4

我正在使用CKDiscoverAllContactsOperation,但它不适合我。

-(void)queryForAllUsers: (void (^)(NSArray *records))completionHandler {

    CKDiscoverAllContactsOperation *op = [[CKDiscoverAllContactsOperation alloc] init];

    [op setUsesBackgroundSession:YES];
    op.queuePriority = NSOperationQueuePriorityNormal;

    [op setDiscoverAllContactsCompletionBlock:^(NSArray *userInfos, NSError *error) {

        if (error) {
            NSLog(@"An error occured in %@: %@", NSStringFromSelector(_cmd), error);
            //abort();
        } else {

            NSLog(@"Number of records in userInfos is: %ld", (unsigned long)[userInfos count]);
            dispatch_async(dispatch_get_main_queue(), ^(void){
                completionHandler(userInfos);
            });
        }
    }];
    [self.container addOperation:op];
}

我正在使用的容器是publicCloudDatabase.

4

2 回答 2

4

The search only works if different users activate the app, approved to be Discoverable and have the other person's iCloud email address in their Contacts.

于 2015-02-12T06:35:58.153 回答
0

您应该像这样在容器上使用 discoverAllContactUserInfosWithCompletionHandler :

[self.container discoverAllContactUserInfosWithCompletionHandler:^(NSArray *userInfos, NSError *error) {
.. 
}

此函数将仅返回可以链接到 iCloud 帐户的联系人,并且此人还启动了您的应用程序。

于 2014-09-17T08:31:12.703 回答