默認(rèn)情況下app在后臺或者未啟動 是拿不到通知信息的;如果app要在后臺(或者前臺不活躍)拿到通知信息 需要在apns的aps中加上content-available = 1 并且在項(xiàng)目的target-capabilities-Background mode中同時開啟background fetch 和remote notifications ;在appdelegate中實(shí)現(xiàn)- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler 方法,其中可以在后臺或者前臺,前臺不活躍可以拿到通知信息。


tips:1、如果app未啟動,無法拿到通知信息。
2、aps-alert 為空的時候手機(jī)app上不會顯示條幅
3、app 未啟動-點(diǎn)擊通知進(jìn)入 會在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中拿到
NSDictionary* remoteNotificationDict = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
4、app未啟動-點(diǎn)擊icon進(jìn)入app 無法拿到通知信息
5、app在后臺 - 點(diǎn)擊通知進(jìn)入(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo會在你的程序進(jìn)入前臺后才會被調(diào)用
6、app在后臺 - ?點(diǎn)擊icon進(jìn)入app?(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 不會再次執(zhí)行(但是在收到通知是會執(zhí)行 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler )
7、有標(biāo)題? aps = {
? ? ? ? alert =? ? ? ? {
? ? ? ? ? ? body = "Your message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message Here";
? ? ? ? ? ? title = "Your message Here";
? ? ? ? };
? ? ? ? "content-available" = 1;
? ? ? ? sound = default;
? ? };
}
8、沒標(biāo)題 aps = {
? ? ? ? alert = "Your message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message Here";
? ? ? ? "content-available" = 1;
? ? ? ? sound = default;
? ? };
}
參考鏈接?http://www.cocoachina.com/bbs/read.php?tid-290239-page-1.html