Teja Nandamuri
Teja Nandamuri

Reputation: 11201

fetch cngroup with identifier using Contacts framework

I created a group using CNMutableGroup, by the time of creation , the identifier of the group is :

 A9A00074-CA8F-4EA4-8E76-F26C37CB49B4:ABGroup

I saved this in NSUserDefaults.

The documentation says:

It is recommended that you use the identifier when re-fetching the group. The identifier can be persisted between app launches.

How can I use this identifier to fetch the group ?

If I do:

    CNMutableGroup *group = [CNMutableGroup new];
    group.name=kGroup;

this creates a new identifier even though the group name is same.

I couldn't set the identifier as it is read only.

I tried:

 NSPredicate *predicate = [CNGroup predicateForGroupsInContainerWithIdentifier:[[NSUserDefaults standardUserDefaults]objectForKey:@"groupIDentifier"]];
 NSArray *groups = [store groupsMatchingPredicate:predicate error:&saveError];

The groups is nil.

How can I access the group with the identifier ?

Upvotes: 0

Views: 380

Answers (1)

Teja Nandamuri
Teja Nandamuri

Reputation: 11201

I'm not sure why, but predicateForGroupsWithIdentifiers worked for me:

NSPredicate *predicate = [CNGroup predicateForGroupsWithIdentifiers:@[[[NSUserDefaults standardUserDefaults]objectForKey:@"groupIDentifier"]]];
NSArray *groups = [store groupsMatchingPredicate:predicate error:&saveError];

Upvotes: 1

Related Questions