register for remote notifications swift

// Import the UserNotifications framework and add the UNUserNotificationCenterDelegate in AppDelegate.swift
import UserNotifications 

// Request user permission

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {


        let center = UNUserNotificationCenter.current()
        center.requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in
            // Enable or disable features based on authorization.
        }
        application.registerForRemoteNotifications()
        return true
}

// Getting device token

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

    let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
    print(deviceTokenString)
}

// In case of error

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {

        print("i am not available in simulator \(error)")
}

// In case if you need to know the permissions granted

UNUserNotificationCenter.current().getNotificationSettings(){ (settings) in

	switch settings.soundSetting{
      	case .enabled:
	      	print("enabled sound setting")
		case .disabled:
      		print("setting has been disabled")
      	case .notSupported:
      		print("something vital went wrong here")
    }
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
remote notification swift swiftui remote push notifications local notification immediate in swift how to set local notification in swift custom notification ios swift handle notification ios swift handel notification ios swift register apple device developer remote What is remote Notification in swift push notification ios recieved notification push notification ios device token push notification delegate methods in swift push notification using APN ios send ios notifications notifications swift xcode push notification ios swift in app notification swift how to implement push notifications on iphone push notification in swift ios enable push notification swift 5 push notification API swift push benachrichtigung swift ios xcode push notifications push notification from server ios example swift 5 ios push notifcations swift pushnotification swift push notification ios send notification from app swift ios send notifications through code ios push notification received event for kalyer what you in swift to do a push notifications swift remote notifications ios push notifications example swift push notifications sample ios push notification tutorial swift handle push notification ios swift push notifications ios push notifications swift 5 xcode swift how to send notifications push notification tutorial push notofications in swift complete example sending to server push notofications in swift complete example. add push notifications to ios app xcode add push notifications to ios app go ios push notificaiton push notification swift swift push notifications push notifications iphone swift push notifications swift register for remote notifications swift
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source