Reputation: 1327
Is there a way to get Push notification token when user enabled it manually from settings while the application was in the background. Is there a function available in Swift which will get push notification token when user will come back to the app.
Upvotes: 1
Views: 818
Reputation: 11
When user turing push notification allowed in the general setting of ios, the app can call the
UIApplication.shared.registerForRemoteNotifications()
and device token is able to be obtained from
public func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
as I understand there is no any direct method to determine the user setting push notification manually, so I came up two alternative ways
to call bellow function (for example)
func registerRemoteNotification() {
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.getNotificationSettings { (settings) in
if settings.authorizationStatus == .authorized {
//"authorized"
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
} else {
//"not authorized")
}
}
}
Upvotes: 1
Reputation: 568
You can use observer for system wise settings change. See more info on this thread
Upvotes: 0