【问题标题】:Contact Framework is fatching only few contacts联系人框架只增加了几个联系人
【发布时间】:2017-10-08 15:06:14
【问题描述】:

我正在使用 Contacts Framework 将所有联系人从我的 iPhone 抓取到我的应用程序。但它只获取少数联系人。这是我使用此代码的代码:

//ios 9+
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
    if (granted == YES) {

        NSArray *keys = @[CNContactGivenNameKey,CNContactFamilyNameKey,CNContactPhoneNumbersKey,CNLabelPhoneNumberMobile,CNLabelPhoneNumberMain,CNContactImageDataKey,CNContactIdentifierKey];
        NSString *containerId = store.defaultContainerIdentifier;
        NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];
        NSError *error;
        NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];

     }

【问题讨论】:

标签: ios objective-c contact


【解决方案1】:

试试这个:

    [store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {

        if (granted == YES) {

            NSArray *keys = @[CNContactGivenNameKey,CNContactFamilyNameKey,CNContactPhoneNumbersKey,CNLabelPhoneNumberMobile,CNLabelPhoneNumberMain,CNContactImageDataKey,CNContactIdentifierKey];
            NSError *error;
            NSArray *allContainer = [store containersMatchingPredicate:nil error:&error];

            for (CNContainer *container in allContainer) {

                    NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:container.identifier];
                    NSArray *result = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];
                    [aryAllContacts addObject:result];
            }
        }
    }];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多