虽然我收到了通知,但是接收到的被拒绝通知

时间:2014-05-05 10:38:06

标签: ios push-notification

(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];
}

1 个答案:

答案 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];
}

但是当您点击通知

时会发出此呼叫