Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从未调用CloudKit推送通知didReceiveRemoteNotification_Ios_Objective C_Macos_Apple Push Notifications_Cloudkit - Fatal编程技术网

Ios 从未调用CloudKit推送通知didReceiveRemoteNotification

Ios 从未调用CloudKit推送通知didReceiveRemoteNotification,ios,objective-c,macos,apple-push-notifications,cloudkit,Ios,Objective C,Macos,Apple Push Notifications,Cloudkit,我正在使用CloudKit存储用户数据,并希望在记录更改或创建新记录时获得推送通知。但它不起作用 我注册订阅,如下所示: - (void) updateCloudSubscriptions { NSPredicate *allPredicate = [NSPredicate predicateWithFormat:@"TRUEPREDICATE"]; CKSubscription *newOrUpdateSubscription = [[CKSubscription alloc

我正在使用CloudKit存储用户数据,并希望在记录更改或创建新记录时获得推送通知。但它不起作用

我注册订阅,如下所示:

- (void) updateCloudSubscriptions {

    NSPredicate *allPredicate = [NSPredicate predicateWithFormat:@"TRUEPREDICATE"];
    CKSubscription *newOrUpdateSubscription = [[CKSubscription alloc]
        initWithRecordType:kMyRecordType predicate:allPredicate options:
        (CKSubscriptionOptionsFiresOnRecordCreation | CKSubscriptionOptionsFiresOnRecordUpdate)];
    CKNotificationInfo *newOrUpdateNotificationInfo = [CKNotificationInfo new];
    newOrUpdateNotificationInfo.shouldBadge = NO;
    newOrUpdateNotificationInfo.shouldSendContentAvailable = YES;
    newOrUpdateSubscription.notificationInfo = newOrUpdateNotificationInfo;

    CKDatabase *publicDatabase = [[CKContainer containerWithIdentifier:kMyContainerID] 
        publicCloudDatabase];
    [publicDatabase saveSubscription:newOrUpdateSubscription 
         completionHandler:^(CKSubscription *theSubscription, NSError *saveError) {
        if (saveError){
            //error handling
        }
        NSLog(@"Subscription created");
    }];
}
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Saving database.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Destroying database.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Closed database.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Reopening database
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Initializing database on thread: <NSThread: 0x7f8f1bf80dd0>{number = 55, name = (null)}
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Enabling auto vacuum.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Enabling WAL journal mode.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Enabling Foreign Key support.
这是成功的。在CloudKit仪表板上,已正确创建订阅

在myAppDelegate中,我现在有以下内容:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:
        (UIUserNotificationTypeNone | UIUserNotificationTypeAlert |
        UIUserNotificationTypeBadge | UIUserNotificationTypeSound) categories:nil];
    [application registerUserNotificationSettings:notificationSettings];
    [application registerForRemoteNotifications];
}
并实现了以下委托方法:

- (void)application:(UIApplication *)application
    didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"%@ with token = %@", NSStringFromSelector(_cmd), deviceToken);
}


- (void)application:(UIApplication *)application
    didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    NSLog(@"%@ with error = %@", NSStringFromSelector(_cmd), error);
}


- (void)application:(UIApplication *)application 
    didReceiveRemoteNotification:(NSDictionary *)userInfo {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}
使用令牌成功调用了didRegisterForRemoteNotificationsWithDeviceToken
。但从未调用过“DidReceiveMotonification”。

我通过在Mac版和iPhone版上更改值来测试这一点。两者都上载更改,但都不会触发通知。我还尝试直接在仪表板上更改值,但也没有引起通知

我错过了什么

如果相关:我使用的是OS X 10.10和XCode 6.4

我激活了
apsd
日志记录,但只收到如下消息:

- (void) updateCloudSubscriptions {

    NSPredicate *allPredicate = [NSPredicate predicateWithFormat:@"TRUEPREDICATE"];
    CKSubscription *newOrUpdateSubscription = [[CKSubscription alloc]
        initWithRecordType:kMyRecordType predicate:allPredicate options:
        (CKSubscriptionOptionsFiresOnRecordCreation | CKSubscriptionOptionsFiresOnRecordUpdate)];
    CKNotificationInfo *newOrUpdateNotificationInfo = [CKNotificationInfo new];
    newOrUpdateNotificationInfo.shouldBadge = NO;
    newOrUpdateNotificationInfo.shouldSendContentAvailable = YES;
    newOrUpdateSubscription.notificationInfo = newOrUpdateNotificationInfo;

    CKDatabase *publicDatabase = [[CKContainer containerWithIdentifier:kMyContainerID] 
        publicCloudDatabase];
    [publicDatabase saveSubscription:newOrUpdateSubscription 
         completionHandler:^(CKSubscription *theSubscription, NSError *saveError) {
        if (saveError){
            //error handling
        }
        NSLog(@"Subscription created");
    }];
}
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Saving database.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Destroying database.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Closed database.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Reopening database
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Initializing database on thread: <NSThread: 0x7f8f1bf80dd0>{number = 55, name = (null)}
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Enabling auto vacuum.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Enabling WAL journal mode.
Jul 12 18:25:29 Mac.local apsd[44748]: APSMessageStore - Enabling Foreign Key support.
Jul 12 18:25:29 Mac.local apsd[44748]:APSMessageStore-保存数据库。
7月12日18:25:29 Mac.local apsd[44748]:APSMessageStore-正在销毁数据库。
7月12日18:25:29 Mac.local apsd[44748]:APSMessageStore-关闭数据库。
7月12日18:25:29 Mac.local apsd[44748]:APSMessageStore-重新打开数据库
七月12日18:25:29 Mac.local apsd[44748]:APSMessageStore-正在初始化线程上的数据库:{number=55,name=(null)}
7月12日18:25:29 Mac.local apsd[44748]:APSMessageStore-启用自动真空。
7月12日18:25:29 Mac.local apsd[44748]:APSMessageStore-启用WAL日志模式。
7月12日18:25:29 Mac.local apsd[44748]:APSMessageStore-启用外键支持。
指出,如果要发送静默推送通知,需要在notificationInfo字典中将
shouldSendContentAvailable
设置为true,如下所示:

let notificationInfo = CKNotificationInfo()
notificationInfo.shouldSendContentAvailable = true
subscription.notificationInfo = notificationInfo

对于iOS 8,您的通知注册是正确的,但在OS X上,您必须使用
registerforremotentificationtypes:
方法
NSApplication
,而在iOS 7上,您必须使用
registerforremotentificationtypes:
方法
UIApplication

应用程序必须向Apple推送通知服务(APNs)注册才能 接收应用程序推送提供商发送的远程通知。在iOS 8中 之后,注册分为四个阶段:

  • 使用注册应用程序支持的通知类型 registerUserNotificationSettings:
  • 注册以接收推送 通过APNs通过调用应用程序的 RegisterForRemotonifications方法
  • 存储返回的设备令牌 由服务器发送到应用程序代理以成功注册,或 优雅地处理注册失败
  • 将设备令牌转发到 应用程序的推送提供商 (在iOS 7中,不是前两步, 您可以通过调用registerForRemoteNotificationTypes:方法进行注册 在操作系统X中,通过调用 registerForRemoteNotificationTypes:非应用程序的方法。)

    还应实施而不是执行DidReceiveRemoteNotonification:

    使用此方法处理应用程序的传入远程通知。 与application:didReceiveMotonification:method不同,它是 仅当应用程序在前台运行时调用,系统 当应用程序在前台或后台运行时调用此方法 背景。此外,如果启用了远程通知 后台模式下,系统启动应用程序(或从 挂起状态),并在远程 通知来了。但是,该系统不会自动运行 如果用户已强制退出,则启动应用程序。在这种情况下 用户必须重新启动应用程序或重新启动设备,然后才能启动系统 尝试再次自动启动应用程序

    如果希望通知唤醒应用程序,请确保编辑
    Info.plist
    ,并选中“启用后台模式”和“远程通知”复选框:


    因为您需要一个静默通知,根据文档,您应该只将“contentavailable”标志发送到1,所以这是正确的。但是也有其他用户在静默通知方面有问题,显然,将“sound”属性作为空字符串发送确实有帮助(),因此您可以尝试将
    CKNotificationInfo.soundName
    设置为空字符串。

    目前,有一个CloudKit错误与更新通知有关。您是否尝试了添加新记录的应用程序?有关更新错误的更多信息,请参阅@EdwinVermeer,这很有趣。但是,我也没有收到关于创建记录的通知。在目标应用程序功能中,是否打开远程通知的后台模式?发送通知时,您的应用程序是否在后台?应用程序始终在前台,但我添加了后台功能,但没有成功。感谢您的详细回答,巴里斯。我确实在OSX上正确注册了;我的问题中没有列出代码。我总是在iOS 8上测试,所以那里的注册应该是正确的。当我测试时,这些应用程序已经出现在前台,但我也添加了后台通知和
    didReceiveEmotentification:fetchCompletionHandler:
    ,但它仍然没有被调用。对我来说这是非常神秘的…@codingFriend1查看我的更新答案:尝试将
    CKNotificationInfo.soundName
    设置为空字符串。也许它有帮助,它似乎已经为…是的!那是丢失的拼图<必须设置代码>声音名称,才能接收通知。很抱歉,我花了这么长时间来核实,而你只收到了一半的赏金。无论如何:非常感谢你的帮助!为此非常感谢!!当应用程序在backgro中时,我一直在努力寻找不被调用的方法