0
votes

I have a custom notification service that is successful in sending notifications but the didReceiveRemoteNotification is never called when the user clicks on the notification. The app will open to the last state and I'm trying to deep link to a specific scene in the app.

In my didFinishLaunchingWithOptions I am registering the notification types by calling into this function"

func registerForPushNotifications(application: UIApplication) { let notificationSettings = UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil) UIApplication.shared.registerUserNotificationSettings(notificationSettings) }

I'm registering my device with the backend service with the called to the didRegisterForRemoteNotificationsWithDeviceToken function

Next I have my didregister function

func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) { UIApplication.shared.registerForRemoteNotifications() }

Finally, I have the didReceiveRemoteNotification which I expect to be called when I tap on the notification.

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) { }

The xml that is being posted to my backend service is fairly straight forward and seems to be working as expected: { "audience":{ "ios_channel":"e06b9r8r-ffce-4fa6-92ec-123456789" }, "notification":{ "ios":{ "alert":"Testing sounds send", "title":"Test Alert", "sound":"default" } }, "device_types":[ "ios" ] }

If anyone has input as to why the didReceiveRemoteNotification func isn't called would be greatly appreciated.

2
I resolved this issue shortly after I posted it. I'm using Urban Airship v1.0 and the UA library will automatically integrates into the app which intercepts any calls back into the App. To remedy this, add "automaticSetupEnabled" to NO in either your AirshipConfig.plist file or on a UAConfig. UA explains this change here: docs.urbanairship.com/platform/ios.html#automatic-integrationLiedl

2 Answers

0
votes

didReceiveRemoteNotification only fires when your app is open. To respond to a user tapping the notification, you'll need to check for the UIApplicationLaunchOptionsRemoteNotificationKey value in the launchOptions parameter of didFinishLaunching.

0
votes
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  if let userInfo = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] {
            NSLog("[RemoteNotification] applicationState: \(applicationStateString) didFinishLaunchingWithOptions for iOS9: \(userInfo)")
            //TODO: Handle background notification


        }
        return true
    }