iOS7 iOS8 调用系统通讯录界面
来源:互联网 发布:淘宝上买炉石卡包 编辑:程序博客网 时间:2024/05/16 03:42
#pragma mark--选取手机联系人
-(void)selectPeople{
//这个变量用于记录授权是否成功,即用户是否允许我们访问通讯录
int__block tip=0;
//声明一个通讯簿的引用
ABAddressBookRef addBook =nil;
//创建通讯簿的引用
addBook=ABAddressBookCreateWithOptions(NULL,NULL);
//创建一个出事信号量为0的信号
dispatch_semaphore_t sema=dispatch_semaphore_create(0);
//申请访问权限
ABAddressBookRequestAccessWithCompletion(addBook, ^(bool greanted,CFErrorRef error) {
//greanted为YES是表示用户允许,否则为不允许
if (!greanted) {
tip=1;
}
//发送一次信号
dispatch_semaphore_signal(sema);
});
//等待信号触发
dispatch_semaphore_wait(sema,DISPATCH_TIME_FOREVER);
if (tip) {
//做一个友好的提示
UIAlertView * alart = [[UIAlertViewalloc]initWithTitle:@""message:@"此应用程序没有权限访问您的联系人。您可以在'设置'->'隐私'->'通讯录'->'健一网'中启用访问权限"delegate:selfcancelButtonTitle:@"知道了"otherButtonTitles:nil,nil];
[alart show];
}else{
_peoplePicker= [[ABPeoplePickerNavigationControlleralloc] init];
_peoplePicker.peoplePickerDelegate =self;
NSArray *displayItems = [NSArrayarrayWithObjects:[NSNumbernumberWithInt:kABPersonPhoneProperty],nil];
_peoplePicker.displayedProperties=displayItems;
// if(IOS8){
// _peoplePicker.predicateForSelectionOfPerson = [NSPredicate predicateWithValue:false];
// }
[selfpresentViewController:_peoplePickeranimated:YEScompletion:nil];
}
}
#pragma mark -- ABPeoplePickerNavigationControllerDelegate
//ios8执行
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
ABMultiValueRef valuesRef =ABRecordCopyValue(person, kABPersonPhoneProperty);
//查找这条记录中的名字
NSString *firstName =CFBridgingRelease(ABRecordCopyValue(person,kABPersonFirstNameProperty));
firstName = firstName != nil? firstName:@"";
//查找这条记录中的姓氏
NSString *lastName =CFBridgingRelease(ABRecordCopyValue(person,kABPersonLastNameProperty));
lastName = lastName != nil? lastName:@"";
NSLog(@"%@",[NSStringstringWithFormat:@"%@%@",firstName,lastName]);
// CFRelease(person);
CFIndex index =ABMultiValueGetIndexForIdentifier(valuesRef,identifier);
if(property !=kABPersonPhoneProperty) {
return;
}else{
CFStringRef value =ABMultiValueCopyValueAtIndex(valuesRef,index);
[selfdismissViewControllerAnimated:YEScompletion:^{
selectPeople=[NSStringstringWithFormat:@"%@%@",lastName,firstName];
selectNumber=[NSStringstringWithFormat:@"%@",(__bridgeNSString*)value];
if ([selectNumberisEqualToString:@"(null)"]) {
selectNumber=@"";
}else{
selectNumber=[selectNumberstringByReplacingOccurrencesOfString:@"-"withString:@""];
selectNumber=[HYShareObjectformatPhoneNum:selectNumber];
}
[self.tablereloadData];
}];
}
}
//ios7执行
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierNS_DEPRECATED_IOS(2_0,8_0){
if(property !=kABPersonPhoneProperty) {
returnNO;
}else{
ABMultiValueRef valuesRef =ABRecordCopyValue(person, kABPersonPhoneProperty);
//查找这条记录中的名字
NSString *firstName =CFBridgingRelease(ABRecordCopyValue(person,kABPersonFirstNameProperty));
firstName = firstName != nil? firstName:@"";
//查找这条记录中的姓氏
NSString *lastName =CFBridgingRelease(ABRecordCopyValue(person,kABPersonLastNameProperty));
lastName = lastName != nil? lastName:@"";
NSLog(@"%@",[NSStringstringWithFormat:@"%@%@",firstName,lastName]);
// CFRelease(person);
CFIndex index =ABMultiValueGetIndexForIdentifier(valuesRef,identifier);
CFStringRef value =ABMultiValueCopyValueAtIndex(valuesRef,index);
[selfdismissViewControllerAnimated:YEScompletion:^{
selectPeople=[NSStringstringWithFormat:@"%@%@",lastName,firstName];
selectNumber=[NSStringstringWithFormat:@"%@",(__bridgeNSString*)value];
if ([selectNumberisEqualToString:@"(null)"]) {
selectNumber=@"";
}else{
selectNumber=[selectNumberstringByReplacingOccurrencesOfString:@"-"withString:@""];
selectNumber=[HYShareObjectformatPhoneNum:selectNumber];
}
[self.tablereloadData];
}];
}
returnYES;
}
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
[selfdismissViewControllerAnimated:YEScompletion:nil];
}
- iOS7 iOS8 调用系统通讯录界面
- iOS7 调用系统通讯录, 点击取消crash
- iOS7,iOS8和iOS9获取通讯录联系人
- iOS开发--调用系统通讯录界面
- iOS调用系统的通讯录界面获取用户信息
- Xcode6 上面关于ios8系统通讯录调用的代理方法变更;
- android调用系统通讯录
- 调用系统通讯录
- 调用系统通讯录
- ios调用系统通讯录
- ios 调用系统通讯录
- 调用系统通讯录
- Android 调用系统通讯录
- 系统通讯录界面的使用
- ios8之后调用系统定位
- 调用系统通讯录,返回结果
- 调用系统通讯录 获得手机号
- AddressBook 调用系统通讯录数据
- PHP里session有效时间和回收机制
- Java编程中“为了性能”需做的26件事
- ASP.NET车辆管理系统100%源码
- EasyUi细节
- 全区开展国家网络安全宣传周活动
- iOS7 iOS8 调用系统通讯录界面
- [转]JQuery.Ajax之错误调试帮助信息
- kinect2.0开发-简介(1)
- 为大数据打造可信的安全运行环境
- cocos2dx AudioEngine(声音播放)音效播放结束判断测试和背景音乐播放
- MySQL 常用命令
- mac系统安装Ionic
- 电脑经常卡是怎么回事?
- 数据库Sharding的思想和切分策略