CloudKit 推送通知,后台运行的应用程序 [英] CloudKit Push Notification, App running on background

查看:27
本文介绍了CloudKit 推送通知,后台运行的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS8.2-app在后台运行时,没有收到任何推送通知,

When iOS8.2-app is running in the background, it does not receive any push notification,

如果它在前台运行,它会很好地接收推送通知.

while if it is running on the foreground, it receives the push notifications fine.

知道发生了什么吗?

运行在CloudKit Development模式下,订阅用于添加、编辑和删除,并使用以下didReceiveRemoteNotification:

Running on CloudKit Development mode, the subscription is for add,edit,and remove, and using the following didReceiveRemoteNotification:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
    NSLog(@"Push received.");

    NSDictionary * apsDict = [userInfo objectForKey:@"aps"];

    NSString * alertText = [apsDict objectForKey:@"alert"];

    //TODO: get the record information from the notification and create the appropriate message string.

    if(application.applicationState == UIApplicationStateActive) {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Notification" message:alertText delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alert show];
    } else {

        if([application currentUserNotificationSettings].types & UIUserNotificationTypeAlert) {
            UILocalNotification * localNotification = [[UILocalNotification alloc] init];
            localNotification.alertBody = NSLocalizedString(@"alert body", nil);;
            localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:2];
            [application presentLocalNotificationNow:localNotification];
        }
    }

    completionHandler(UIBackgroundFetchResultNoData);
}

推荐答案

当您进入应用设置功能时,您是否为后台模式启用了远程通知?

When you go to your app settings capabilities, do you have remote notifications enabled for background modes?

看这个截图:

除此之外,您是否注册了所有通知类型,如下所示:

Besides that, did you register for all notification types like this:

application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert | .Badge | .Sound, categories: nil))
    application.registerForRemoteNotifications()

在您的订阅中,您是否为 CKNotificationInfo 发送了 alertBody 或 alertLocalizationKey?如果您这样做,那么您已经从操作系统收到通知,您无需设置本地通知.

And in your subscription, do you send an alertBody or alertLocalizationKey for the CKNotificationInfo? If you do that, then you will already get a notification from the OS and you don't need to setup a local notification.

更新:正如下面提到的 Porton,这个问题是通过填写 alertBody 解决的.

Update: As Porton mentioned below, this issue was solved by filling in the alertBody.

这篇关于CloudKit 推送通知,后台运行的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆