首页 文章

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

提问于
浏览
1
(void)application:(UIApplication *)application
     didReceiveRemoteNotification:(NSDictionary *)userInfo ;

- (void)application:(UIApplication *)application didReceiveRemoteNotification:
                    (NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult 
                     result))completionHandler{};

永远不会被叫,虽然我收到了iPhone上的通知,是否还需要添加其他功能才能使用?谢谢 .

Update 当应用程序不在后台或活动但我没有收到消息时我尝试了这个 . - (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {//设置应用程序的客户端ID | GPPSignIn |和| 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 回答

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

    但是当你点击通知时这个电话

相关问题