问题描述
我在我的 viewWillAppear:
中使用它来请求用户对其地址簿的许可/访问(如苹果要求).当他们允许访问时,他们可以进入邀请"页面,在那里他们可以浏览(他们自己的)已经在我的应用上拥有现有帐户的联系人.基本上,我只是将他们的联系人放入UITableView
.因此,我必须获取所有他们的联系人并将其添加到 NSMutableArray
类型的数组中.在下面的代码中,它说//ADD ALL OF USERS CONTACTS TO ARRAY HERE"我需要一些代码.我在那里放什么?
I'm using this in my viewWillAppear:
to ask the user for permission/access(as apple requires) to their address book. When they have allowed access, they can proceed to an "invites" page, where they can browse through (their own)contacts that already have existing accounts on my app. Basically, I'm just going to take their contacts and put it into a UITableView
. SO, I MUST GET ALL THEIR CONTACTS AND ADD IT TO AN array of type NSMutableArray
. In the following code, where it says "//ADD ALL OF USERS CONTACTS TO ARRAY HERE" I need some code. What do I put there?
- (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
}
}
推荐答案
你想要 ABAddressBookCopyArrayOfAllPeople().
这篇关于授予地址簿访问权限后,将用户联系人存储在 NSMutable 数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!