在为地址簿授予访问权限后,将用户联系人存储在NSMutablearray中

时间:2014-01-12 23:01:25

标签: ios objective-c nsmutablearray abaddressbook

我在viewWillAppear:中使用此功能向用户询问其地址簿的权限/访问权限(如苹果所要求)。当他们允许访问时,他们可以进入“邀请”页面,在那里他们可以浏览已经拥有我的应用上现有帐户的(他们自己的)联系人。基本上,我只是将他们的联系人放入UITableView。所以,我必须获得所有他们的联系人并将其添加到NSMutableArray类型的数组中。在下面的代码中,它说“//添加所有用户联系人到这里”我需要一些代码。我该放什么?

- (void)viewWillAppear:(BOOL)animated
{
    // Request authorization to Address Book
    ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

    if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
        ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
            if (granted) {
                // First time access has been granted, add user's contacts to array
                // ADD  ALL OF USERS CONTACTS TO ARRAY HERE

            } else {
                // User denied access
                // Display an alert telling user that they must allow access in order to proceed to "invites" page 
            }
        });
    }
    else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
        // The user has previously given access, grab all contacts
        // ADD ALL OF USERS CONTACTS TO ARRAY HERE
    }
    else {
        // The user has previously denied access
        // Display an alert telling user that they must allow access in order to proceed to "invites" page 
    }
}

1 个答案:

答案 0 :(得分:1)