5

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 Fetching User Record ID」) は実行されません。

クラッシュすると、ログに情報が表示されません。Xcode のスレッド キューは次のとおりです。

ここに画像の説明を入力

デバッグナビゲーターで実際に吐き出すものは次のとおりです。

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

4

2 に答える 2

3

メソッドの順序が正しくない/不完全です。これがあなたがすべきことです: 最初に 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-イントロ-DontLinkElementID_2

于 2014-08-31T09:31:08.990 に答える