CKDiscoverAllContactsOperation not fetching contacts

泄露秘密 提交于 2019-12-10 17:08:09

问题


I am using CKDiscoverAllContactsOperation but its not working fine for me.

-(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];
}

The container which I'm using is publicCloudDatabase.


回答1:


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.




回答2:


You should use the discoverAllContactUserInfosWithCompletionHandler on the container like this:

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

this function will only return the contacts that can be linked to an iCloud account and the person has also started up your app.



来源:https://stackoverflow.com/questions/25847340/ckdiscoverallcontactsoperation-not-fetching-contacts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!