Search code examples
push-notificationibm-cloudibm-mobile-services

Bluemix push notification displayed in phone OS, when clicked, won't launch the app


I'm developing an App using Bluemix push notification. When the app is at foreground or background, didReceiveRemoteNotification() with completion handler is called and all is fine.

But when the app is not launched, and notification is sent by another device. the phone does display the push notification in the system notifications when you swipe down from the top, but clicking the notification won’t launch the app. It just dismisses the notification. This is the same for Android and IOS.

How can I launch the app by clicking the notification?

Thanks and Best Regards,

Jen


Solution

  • For iOS you need to make sure you are also registering the application to the APNs service successfully. Once this is completed you will be able to open the application by clicking on the push notification that is received.

    Objective-c:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
         [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:categories]];
         [[UIApplication sharedApplication] registerForRemoteNotifications];
         }
         else{
         [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
         }
    
         return YES;
    }
    

    Swift:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    let notificationTypes: UIUserNotificationType = UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound
    let notificationSettings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: categories)
    
    application.registerUserNotificationSettings(notificationSettings)
    application.registerForRemoteNotifications()
    }
    

    You can see more information regarding Push registration here:

    Enabling iOS applications to receive push notifications

    I would also recommend looking at our Bluemix Push Sample:

    BMS iOS helloPush Sample