Zheng Xie
Zheng Xie

Reputation: 415

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

Upvotes: 1

Views: 74

Answers (2)

Joshua Alger
Joshua Alger

Reputation: 2132

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

Upvotes: 1

David R. Cariello
David R. Cariello

Reputation: 505

For Android you must ensure you have the following in your AndroidManifest.xml, within the desired Activity you'd like to start when your app launches after clicking the notification:

<!--Notification Intent -->
<intent-filter>  
   <action android:name="<Your_Android_Package_Name.IBMPushNotification"/>   
   <category  android:name="android.intent.category.DEFAULT"/>
</intent-filter>

Don't forget to use your package name in place of Your_Android_Package_Name

See the helloPush example for more details.

Upvotes: 1

Related Questions