2016-08-08 4 views

答えて

0

iCloud/yahoo/gmailなどはCNContainerです。 Gmail/iCloudはCNContainerTypeCardDAVタイプです。最初にすべての連絡先を取得し、その連絡先のCNContainerTypeに基づいて配列をフィルタリングする必要があります。しかし残念ながら、私たちはそれがどのCardDav(iCloud/Gmail)であるかを特定できません。

ここで詳細を参照してください:あなたはここにコンタクトFrameworkランタイムヘッダを見て、これを達成することができますHow do we know which CNContainer represents iCloud?

0

https://github.com/JaviSoto/iOS10-Runtime-Headers/tree/master/Frameworks/Contacts.framework

あなたはperformSelectorメッセージでそれらを呼び出すことができます。ちょっと面倒ですが、動作します。それはCNContainersの一般的な使用法についてのすべてだ

CNContactStore* store = [CNContactStore new]; 

// fetch accounts that sync contacts with your device (array of CNAccount) 
// since CNAccount class isn't available by default, we treat it as NSObject for our puproses 

NSArray* accounts = [store performSelector:@selector(accountsMatchingPredicate:error:) withObject:nil withObject:nil]; 

// you can iterate through this array, I just use first one for this example 

NSObject* account = [accounts firstObject]; 

// get identifier of the account for NSPredicate we use next 

NSString* accountId = [account performSelector:@selector(identifier)]; 

// Display name of the account (aka Yahoo, Gmail etc.) 
NSString* accountName = [account performSelector:@selector(_cnui_displayName)]; 

// NSPredicate that help us to get corresponding CNContainer 

NSPredicate* containerPredicate = [[CNContainer class] performSelector:@selector(predicateForContainersInAccountWithIdentifier:) withObject:accountId]; 

// Fetching CNContainer 
CNContainer* container = [[store containersMatchingPredicate:containerPredicate error:nil] firstObject]; 

その後:

は一般的に何をしなければならないことは次のようです。 お待ちしています。

PS。 iOS 10で動作します。将来のバージョンではContacts.frameworkランタイムの変更を確認する必要があります。

PPS。私は迅速にチェックしませんでしたが、いずれかを動作させる必要があります。

私の英語のために残念です。 幸運:)

+1

実行セレクタは私とそのクラッシュのために働いていません。これを行う方法はありますか? –

+0

@Sunil_Vaishnavクラッシュの原因となるコードを教えてください。それとも、私が書いたものを使っているのですか? – NewObjective

関連する問題