2016-04-26 15 views
0

Ich bin neu bei iOS und ich habe Kontakte in meiner App geholt, aber wie man die Kontakt-ID holt ... angenommen, wenn es zwei Nummern mit dem gleichen Namen gespeichert hat, also, wie die ID des bestimmten Kontaktnamens holt?Wie kann ich die Kontakt-ID in Ihrer iOS App abrufen?

+0

sind Sie ABAddressbook oder Kontakt Rahmen, viele Verfahren von ABAddressbook veraltet sind im iOS 9 verwendet? – HardikDG

+0

können Sie mir den Prozess zum Abrufen von Kontakten und Kontakt-ID mit Kontakte-Framework ... Ich habe ABaddressbook Framework verwendet, aber seine veraltete –

+0

verwenden Sie Swift oder objective-c? – HardikDG

Antwort

0

Sie können wie diese versuchen: Import Rahmen

#import <Contacts/Contacts.h> 

-Code

- (void) getContacts { 
    CNContactStore *store = [[CNContactStore alloc] init]; 
    [store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) { 
     if (granted == YES) { 
      //keys with fetching properties 
      NSArray *keys = @[CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPhoneNumbersKey, CNContactImageDataKey]; 
      NSString *containerId = store.defaultContainerIdentifier; 
      NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId]; 
      NSError *error; 
      NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error]; 
      if (error) { 
       NSLog(@"error fetching contacts %@", error); 
      } else { 
       for (CNContact *contact in cnContacts) { 
        //store all the contacts as per your requirement 
        NSLog(@"Id %@",contact.identifier);//the contact id which you want 
        NSLog(@"Name %@",contact.givenName); 
       } 
      } 
     }   
    }]; 
} 
+0

@AmrutGaikwad Froh, dass es hilft, wenn diese Antwort Ihnen hilft, Ihre Frage zu lösen bitte wählen Sie die Antwort als richtig. Danke – HardikDG

+0

ok..können Sie mir auch sagen, wie Sie das abgerufene Kontakt-Array zu einer Tabellenansicht hinzufügen? –

+0

liefert den Array-Index an den cellForRowAtIndexPath-Methodenindex und ruft Daten von bestimmten Objekten über den Schlüssel – HardikDG