2016-11-29 70 views
-1

在我的應用程序中,如果我點擊一個按鈕,我需要顯示所有手機接觸像whatsapp ...如何實現AddressBook框架與此?或者,我們可以使用任何其他框架中顯示所有設備聯繫人...在ios中使用系統框架顯示iPhone聯繫人

+0

[網上有很多例子..](https://www.google.com.kw/sea​​rch?rlz=1C5CHFA_enKW556KW556&espv=2&q=import+contacts+programmatically+ios&oq=import+contacts+programmatically+ios&gs_l= serp.3 ... 8379.16207.0.16443.9.9.0.0.0.0.208.795.0j2j2.4.0 .... 0 ... 1c.1.64.serp..5.3.585 ... 0i22i30k1j0i7i30k1j0i7i5i30k1.1GZZr9YVwOo)請在您之前搜索張貼在這裏.. –

+0

是的,它的作品!謝謝 – Sivagami

+0

@SivagamiSundari如果我的回答對你有幫助,那麼請給它正確的標記,這樣可以幫助其他用戶。 –

回答

0

我們可以獲取使用接觸框架的接觸:步幅>

  1. 添加contact.framework和contactUI.framework以下在您的應用程序包中。
  2. 添加兩個文件在您的.h文件中:

    導入聯繫人/ Contacts.h

    進口ContactsUI/ContactsUI.h

  3. 添加流動代碼

    -(void)loadContactList 
    { 
    

    @try {

    CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; 
    
    
    if(status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted) 
    

    {

      NSLog(@"access denied"); 
    
         } 
         else 
         { 
          //Create repository objects contacts 
          CNContactStore *contactStore = [[CNContactStore alloc] init]; 
    
          //Select the contact you want to import the key attribute (https://developer.apple.com/library/watchos/documentation/Contacts/Reference/CNContact_Class/index.html#//apple_ref/doc/constant_group/Metadata_Keys) 
    
          NSArray *keys = [[NSArray alloc]initWithObjects:CNContactIdentifierKey, CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactImageDataKey, CNContactPhoneNumbersKey,CNContactViewController.descriptorForRequiredKeys,nil]; 
    
          // Create a request object 
          CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:keys]; 
          request.predicate = nil; 
    
          [contactStore enumerateContactsWithFetchRequest:request 
                     error:nil 
                   usingBlock:^(CNContact* __nonnull contact, BOOL* __nonnull stop) 
          { 
           // Contact one each function block is executed whenever you get 
           NSString *phoneNumber = @""; 
           if(contact.phoneNumbers) 
            phoneNumber = [[[contact.phoneNumbers firstObject] value] stringValue]; 
    
           NSLog(@"phoneNumber = %@", phoneNumber); 
           NSLog(@"givenName = %@", contact.givenName); 
           NSLog(@"familyName = %@", contact.familyName); 
           NSLog(@"email = %@", contact.emailAddresses); 
    
    
           [contactList addObject:contact]; 
          }]; 
         } 
    
    
        } @catch (NSException *exception) { 
         NSLog(@"Exception:%@",exception.reason); 
        } 
        } 
    

調用此方法鑑於沒有負載或沒有視圖出現。

相關問題