ios – Dealing with push notifications when person allows them in Settings after initially denying entry

Spread the love

I’ve a query about distant push notifications and the way different builders deal with a selected situation. (I take advantage of Fireabase Messaging for distant push notificaiton simply FYI.)

I must deal with a scenario the place a person initially denies push notification authorization utilizing the requestAuthorization(choices:completionHandler:) technique. The person then goes to the Settings app, activates notifications for my app utilizing the “Enable Notifications” toggle, and returns to my app.

If the person kills and relaunches the app, they’ll obtain distant push notifications since all code within the app delegate runs once more when relaunched. Nevertheless, if the person would not relaunch my app after altering the Settings, they will not obtain distant notifications in my app.

Particularly, right here is the circulation:

  1. Consumer installs my app
  2. Consumer goes to the notifications tab in my app and is requested for push
    notification permission
  3. Consumer faucets “Do not Enable”
  4. Consumer goes to the Settings app and activates the “Enable Notifications”
    toggle for my app
  5. Consumer returns to my app (if they’ve relaunched my app, they’ll obtain notificaiton)

Ideally, I would love the person to have the ability to obtain distant notifications after altering the Settings, with out having to kill and relaunch the app.

Is it attainable to make push notifications work on this situation with out relaunching the app? For instance, may calling UIApplication.shared.registerForRemoteNotifications() when the app enters the foreground deal with this case?

Any insights on easy methods to greatest deal with this person circulation could be appreciated. Thanks!

remaining class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    func utility(_ utility: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
        Messaging.messaging().delegate = self

        UNUserNotificationCenter.present().getNotificationSettings { settings in
            guard settings.authorizationStatus == .licensed else { return }
            DispatchQueue.predominant.async {
        return true
    func utility(_ utility: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Knowledge) {
    // save system token
    func utility(_ utility: UIApplication, didFailToContinueUserActivityWithType userActivityType: String, error: Error) {
        print("didFailToContinueUserActivityWithType: (error)")

// MARK: - MessagingDelegate

extension AppDelegate: MessagingDelegate {
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
    // save fcm token

Leave a Reply

Your email address will not be published. Required fields are marked *