2016-11-29 58 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); 
        } 
        } 
    

调用此方法鉴于没有负载或没有视图出现。

相关问题