(void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo ;
和
- (void)application:(UIApplication *)application didReceiveRemoteNotification:
(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult
result))completionHandler{};
永远不会被叫,虽然我在iphone上收到通知,是否还需要添加其他功能?谢谢。
更新 当应用程序不在后台或活动但我没有收到消息时我尝试了这个。 - (BOOL)应用程序:(UIApplication *)应用程序 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //为| GPPSignIn |设置应用的客户端ID和| GPPShare |。
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
// Clear application badge when app launches
application.applicationIconBadgeNumber = 0;
if ([[launchOptions allKeys] containsObject:UIApplicationLaunchOptionsRemoteNotificationKey]) {
id userInfo=[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"MESSAGE" message:userInfo delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil];
[alert show];
}
答案 0 :(得分:2)
如果您的申请关闭并获得通知.....
在didFinishLaunchingWithOptions
if ([[launchOptions allKeys] containsObject:UIApplicationLaunchOptionsRemoteNotificationKey])
{
id userInfo=[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
NSLog(@"%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]);
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"MESSAGE" message:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil];
[alert show];
}
但是当您点击通知
时会发出此呼叫