4
設置>聯繫人>默認帳戶被選爲iCloud並保存了一個新聯繫人。然後將默認帳戶更改爲gmail。 CNContactStore不獲取新保存的聯繫人。CNContact框架工作不提取所有聯繫人(iCloud,Gmail)
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted == YES)
{
NSArray *keys = @[CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPhoneNumbersKey, CNContactImageDataKey,CNContactEmailAddressesKey];
NSArray * contactContainerArray = [store containersMatchingPredicate:nil error:nil];
for(CNContainer * container in contactContainerArray) {
NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:container.identifier];
NSError *error;
NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];
}
偉大的解決方案Vaisakh。也請你讓我知道如何識別聯繫人屬於哪個「賬戶」?意味着如何識別來自iCloud或Gmail或本地通訊錄的特定聯繫人? –
我已經在這裏問我的問題https://stackoverflow.com/questions/44133669/how-to-get-account-name-from-contact-framework –
@MitBhatt實際問題會給你所有聯繫人的容器(用戶可能在其設備的本地帳戶或服務器帳戶中有聯繫人,這些帳戶或服務器帳戶被配置爲同步聯繫人。每個帳戶至少有一個聯繫人容器。聯繫人只能位於一個容器中。) – Vaisakh