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

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

问题描述

在iOS8.2应用在后台运行,它不接受任何推送通知,

它是在前台运行而如果,它会收到推送通知的罚款。

任何想法是怎么回事?

运行在 CloudKit发展模式下,订阅是用于添加,编辑和删除,并使用以下 didReceiveRemoteNotification

   - (无效)应用:(*的UIApplication)的应用didReceiveRemoteNotification:(NSDictionary的*)USERINFO fetchCompletionHandler:(无效(^)(UIBackgroundFetchResult))completionHandler
{
    的NSLog(@收到推送。);    *的NSDictionary = apsDict [USERINFO objectForKey:@APS];    * NSString的alertText = [apsDict objectForKey:@警报];    // TODO:得到通知的记录信息,并建立相应的消息字符串。    如果(application.applicationState == UIApplicationStateActive){
        UIAlertView中*警报= [[UIAlertView中页头] initWithTitle:@通知消息:alertText代表:无cancelButtonTitle:@确定otherButtonTitles:无];
        [警报显示]
    }其他{        如果([应用currentUserNotificationSettings] .types&安培; UIUserNotificationTypeAlert){
            UILocalNotification * localNotification = [[UILocalNotification的alloc]初始化];
            localNotification.alertBody = NSLocalizedString(@警报体,无);;
            localNotification.fireDate = [的NSDate dateWithTimeIntervalSinceNow:2];
            [应用presentLocalNotificationNow:localNotification];
        }
    }    completionHandler(UIBackgroundFetchResultNoData);
}


解决方案

当你去你的应用程序设置的功能,你有背景模式启用远程通知?

请参阅此屏幕截图:

除此之外,你注册的所有通知类型是这样的:

  application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes:.Alert | .Badge | .Sound,类别:无))
    application.registerForRemoteNotifications()

而在你的订阅,你发了一个CKNotificationInfo或alertBody alertLocalizationKey?如果你这样做,那么你会得到已经从操作系统的通知,你不需要设置一个本地通知。

更新:由于波顿下面提到的,这个问题是由alertBody灌装解决

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.

Any idea what is going on ?

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?

See this screenshot:

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

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

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.

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

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

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