2016-01-11 33 views
1

我正在使用Bluemix推送通知開發應用程序。當應用程序處於前臺或後臺時,帶有完成處理程序的didReceiveRemoteNotification()被調用並且一切正常。單擊手機操作系統時顯示的Bluemix推送通知將不會啓動應用程序

但是,當應用程序未啓動,並通知由另一個設備發送。當您從頂部向下滑動時,手機會在系統通知中顯示推送通知,但單擊通知將不會啓動應用程序。它只是駁回了通知。這對於Android和IOS來說是一樣的。

如何通過點擊通知啓動應用程序?

感謝和問候,

回答

2

對於iOS,您需要確保您也正在向APNs服務註冊應用程序。完成此操作後,您將可以通過單擊收到的推送通知來打開應用程序。

的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; 
} 

斯威夫特:

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() 
} 

你可以看到關於Push註冊這裏瞭解更多信息:

Enabling iOS applications to receive push notifications

我也建議看我們的Bluemix推送示例:

BMS iOS helloPush Sample

+0

謝謝喬希,它工作。 不知何故,swift代碼不能編譯。抱怨「|」運營商。 所以我用下面的代碼: //註冊通知中心 設設置= UIUserNotificationSettings(forTypes:[.Alert,.Badge,.Sound],類別:無)的應用程序。 UIApplication.sharedApplication()registerUserNotificationSettings(設置) UIApplication.sharedApplication()。registerForRemoteNotifications() –

2

對於Android的你必須確保你已經在你的AndroidManifest.xml下,你想,當你點擊應用程序的通知後,啓動以啓動所需的活動中:

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

不要忘記場所使用Your_Android_Package_Name

硒你的包名請參閱helloPush示例以瞭解更多詳細信息。

+0

謝謝戴夫,這個整理出來。 –

相關問題