Objective c 在ios中使用系统框架显示iPhone联系人

Objective c 在ios中使用系统框架显示iPhone联系人,objective-c,Objective C,在我的应用程序中,如果我点击一个按钮,我需要显示所有手机联系人,如whatsapp。。。如何使用AddressBook框架实现这一点?或者我们可以使用任何其他框架来显示所有设备联系人…我们可以使用联系人框架获取联系人:按照步骤-> 在应用程序包中添加contact.framework和contactUI.framework 在.h文件中添加两个文件: #导入联系人/Contacts.h #导入ContactsUI/ContactsUI.h 添加流动代码 在视图加载或视图出现时调用此方法。请

在我的应用程序中,如果我点击一个按钮,我需要显示所有手机联系人,如whatsapp。。。如何使用AddressBook框架实现这一点?或者我们可以使用任何其他框架来显示所有设备联系人…

我们可以使用联系人框架获取联系人:按照步骤->

  • 在应用程序包中添加contact.framework和contactUI.framework

  • 在.h文件中添加两个文件:

    #导入联系人/Contacts.h #导入ContactsUI/ContactsUI.h

  • 添加流动代码


  • 在视图加载或视图出现时调用此方法。

    请在发布前搜索。是的,它很有效!!!Thanks@SivagamiSundari如果我的答案对你有帮助,那么请给它正确的分数,这样它将有助于其他用户。
             -(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);
                }
                }