iOS CloudKit在-fetchUserRecordIDWithCompletionHandler的完成块上崩溃:

时间:2014-08-29 22:43:47

标签: ios objective-c multithreading objective-c-blocks cloudkit

我正在为CloudKit编写初始化方法。我在获取用户ID /帐户状态时遇到的问题。

我正在呼叫[[CKContainer defaultContainer] fetchUserRecordIDWithCompletionHandler:]

稍后崩溃了,调试器将我指向“Queue:com.apple.cloudkit.operation.callback(serial)queue”线程。

此方法是唯一具有应该执行的回调的CloudKit相关方法。

这是方法本身:

[[CKContainer defaultContainer] fetchUserRecordIDWithCompletionHandler:^(CKRecordID *recordID, NSError *error) {
    NSLog(@"CLOUDKIT Fetching User Record ID");

    if (error) {
        NSLog(@"[%@] Error loading CloudKit user: %@", self.class, error);
    }

    if (recordID) {
        NSLog(@"CLOUDKIT Found User Record ID: %@", recordID.recordName);

        // If there is a record ID we check for account status
        [[CKContainer defaultContainer] accountStatusWithCompletionHandler:^(CKAccountStatus accountStatus, NSError *error) {
            NSLog(@"CLOUDKIT Finding Account Status");

            if (error) {
                NSLog(@"[%@] Error checking CloudKit availability: %@", self.class, error);
            }

            if (accountStatus == CKAccountStatusAvailable) {
                NSLog(@"CLOUDKIT Account Available, beginning initial sync");
                // We have an available account. If we have a new user do a complete sync
                NSString *userRecordID = [[NSUserDefaults standardUserDefaults] stringForKey:CLOUD_KIT_CURRENT_USER_ID_USER_DEFAULT];
                if (userRecordID == nil || ![recordID.recordName isEqualToString:userRecordID]){
                    [self syncAllData];
                } else {
                    // If there haven't been any updates, just sync as usual
                    [self syncChanges];
                }

                // Subscribe to zone updates
                [self subscribeToDefaultZoneUpdates];
            } else {
                NSLog(@"[%@] Cloudkit account is either unavailable or restricted", self.class);
            }
        }];
    } else {
        NSLog(@"[%@] CloudKit user Record ID not found", self.class);
    }
}];

正在执行之前和之后的NSLog,但最顶层的NSLog(“CLOUDKIT获取用户记录ID”)永远不会被执行。

当它崩溃时,日志不会给我任何信息。这是来自Xcode的线程队列:

enter image description here

这是它在调试导航器中实际吐出的内容。

libsystem_kernel.dylib`__pthread_kill:
0x332f7df4:  mov    r12, #0x148
0x332f7df8:  svc    #0x80
0x332f7dfc:  blo    0x332f7e14                ; __pthread_kill + 32
0x332f7e00:  ldr    r12, [pc, #4]             ; __pthread_kill + 24
0x332f7e04:  ldr    r12, [pc, r12]
0x332f7e08:  b      0x332f7e10                ; __pthread_kill + 28
0x332f7e0c:  rsbeq  lr, r6, #0x80000001
0x332f7e10:  bx     r12
0x332f7e14:  bx     lr

具体来说,它在0x332f7dfc: blo 0x332f7e14 ; __pthread_kill + 32

时突破

2 个答案:

答案 0 :(得分:2)

您的方法顺序不正确/不完整。这是你应该做的:首先你必须调用accountStatusWithCompletionHandler来查看你是否已经进入iCloud。然后,如果是这种情况,则必须调用requestApplicationPermission以查看是否允许您查询iCloud。如果确实如此,那么您可以执行fetchUserRecordIDWithCompletionHandler来获取您的ID,然后执行discoverUserInfoWithUserRecordID以获取详细信息。如果您想查看示例,请查看Apple的CloudKitAtlas演示:https://developer.apple.com/library/prerelease/ios/samplecode/CloudAtlas/Introduction/Intro.html#//apple_ref/doc/uid/TP40014599-Intro-DontLinkElementID_2

答案 1 :(得分:0)

好的,所以我确实想到了这个。

我回滚到最后一个工作并改变了除FastPDFKit生成的一些二进制文件之外的所有内容。我这样做后它开始工作正常。不知道有什么东西弄乱它但它现在有效。