获取联系--(不需要弹出控制器)

#pragma mark 获取通讯录

- (NSMutableArray *)accessAddressBookAddress{

NSMutableArray * addressBookTemp=[[NSMutableArray alloc]initWithCapacity:0];

//新建一个通讯录类

ABAddressBookRef addressBooks = nil;

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0){

addressBooks =ABAddressBookCreateWithOptions(NULL, NULL);

//获取通讯录权限

dispatch_semaphore_t sema = dispatch_semaphore_create(0);

ABAddressBookRequestAccessWithCompletion(addressBooks, ^(bool granted, CFErrorRef error){

dispatch_semaphore_signal(sema);

});

dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);

}else{

addressBooks = ABAddressBookCreate();

}

//获取通讯录中的所有人

CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBooks);

//通讯录中人数

CFIndex nPeople = ABAddressBookGetPersonCount(addressBooks);

//循环,获取每个人的个人信息

for (NSInteger i = 0; i < nPeople; i++){

//新建一个addressBook model类

Model *addressBook = [[Model alloc] init];

//获取个人

ABRecordRef person = CFArrayGetValueAtIndex(allPeople, i);

//获取个人名字

CFTypeRef abName = ABRecordCopyValue(person, kABPersonFirstNameProperty);

CFTypeRef abLastName = ABRecordCopyValue(person, kABPersonLastNameProperty);

CFStringRef abFullName = ABRecordCopyCompositeName(person);

NSString *nameString = (__bridge NSString *)abName;

NSString *lastNameString = (__bridge NSString *)abLastName;

if ((__bridge id)abFullName != nil) {

nameString = (__bridge NSString *)abFullName;

} else if ((__bridge id)abLastName != nil){

nameString = [NSString stringWithFormat:@"%@ %@", nameString, lastNameString];

}

addressBook.name = nameString;

addressBook.recordID = (int)ABRecordGetRecordID(person);

ABPropertyID multiProperties[] = {kABPersonPhoneProperty,kABPersonEmailProperty};

NSInteger multiPropertiesTotal = sizeof(multiProperties) / sizeof(ABPropertyID);

for (NSInteger j = 0; j < multiPropertiesTotal; j++) {

ABPropertyID property = multiProperties[j];

ABMultiValueRef valuesRef = ABRecordCopyValue(person, property);

NSInteger valuesCount = 0;

if (valuesRef != nil) valuesCount = ABMultiValueGetCount(valuesRef);

if (valuesCount == 0) {

CFRelease(valuesRef);

continue;

}

//获取电话号码和email

for (NSInteger k = 0; k < valuesCount; k++) {

CFTypeRef value = ABMultiValueCopyValueAtIndex(valuesRef, k);

switch (j) {

case 0: {// Phone number

addressBook.tel = (__bridge NSString*)value;

NSMutableString * tel=[NSMutableString stringWithString:addressBook.tel];

[tel replaceOccurrencesOfString:@"-" withString:@"" options:NSCaseInsensitiveSearch  range: NSMakeRange(0, addressBook.tel.length)];

addressBook.tel=[tel copy];

break;

}

case 1: {// Email

addressBook.email = (__bridge NSString*)value;

break;

}

}

CFRelease(value);

}

CFRelease(valuesRef);

}

//将个人信息添加到数组中,循环完成后addressBookTemp中包含所有联系人的信息

[addressBookTemp addObject:addressBook];

if (abName) CFRelease(abName);

if (abLastName) CFRelease(abLastName);

if (abFullName) CFRelease(abFullName);

}

return addressBookTemp;

}

时间: 2024-12-25 14:00:40

获取联系--(不需要弹出控制器)的相关文章

自设table表格,获取内容,并经弹出框的url传参,获取结果显示在弹出框,并加载合计

table表格,选择框 form id="editForm1"> <table class="table_form"> <td >经济性质:</td> <td > <input width="150" type="text" id="nature_id" readonly onclick="show_nature()">

Python Selenium 获取不到弹出框的另外一种思路

大家都知道弹出框大致可以分为三种:1.警告消息框(alert).2.确认消息框(confirm).3.提示消息对话(prompt) 而selenium 提供switch_to_alert()方法来定位: switch_to_alert() #定位弹出对话 text()               #获取对话框文本值 accept()                   #相当于点击"确认" dismiss()                  #相当于点击"取消"

仿手机卫士打电话弹出归属地

所要实现的功能如下图 no tu no bb 实现此功能需要解决一下问题 1,来电号码所在地址怎么解决?答:从数据库里面获取,数据库从哪来?从百度,google.soga! 2,怎么知道什么时候来电or去电?答:监听系统广播 3,怎么知道来电or去电人的姓名和号码归属地答:通过内容提供者来获取! 4,弹出的窗口怎么来做?答:用popupwindow ? 否 我们经常在service 或者 BroadcastReceiver里面弹出Toast, 我们这里就用Toast做,通过WindowManag

获取鼠标坐标并且根据鼠标位置不同弹出不同内容

获取鼠标坐标,并且根据鼠标所在div弹出不同内容: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <head

layer 打开关闭弹出窗口与获取父窗口值

一.首先引用js文件 <script src="../../js/common/layer/layer.js"></script> 二.全屏调用以下代码 var index = layer.open({                       type: 2,                       content: url,                       area: ['300px', '195px'],                 

获取弹出键盘时间,,,与高度

弹出键盘操作 //1.定制通知 //在初始化时定制通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(KeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; //2.对应的方法. -(void)KeyboardWillShow:(NSNotification *)notification { NSDictionary

百度地图 layer弹出地图 获取坐标

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>layer弹出百度地图</title> <script src="jquery.min.js"></script> <script src="layer/layer.js"><

C#让TopMost窗体弹出并置顶层但不获取当前输入焦点的终极办法

为了使程序在弹出窗口时置顶层且不获取系统输入焦点,避免影响用户当前的操作,来电通来电弹屏软件尝试过N多种办法,例如:弹出前保存当前焦点窗口句柄,弹出时因为使用TopMost系统默认将焦点交给了弹出窗口,弹出后再将焦点还给弹出前的焦点窗口句柄(C#让窗体置顶弹出但不获取焦点).这种方法貌似解决了问题,但是在弹出的时候还是会打断用户的部分操作.经过我们的不断探索和尝试,终于在Form底层取得了突破,效果很好,和qq的弹窗一样不会打扰用户操作. //声明常量:(释义可参见windows API) co

获取弹出框的句柄,关闭弹出框

大家可能有过这样的需求,有的弹出框可能需要手动关闭,这样非常麻烦,我参考相关资料,用C# 程序自动关闭弹出框的例子,供大家参考 1 //获取弹出框的句柄,并隐藏函数. 2 using System.Runtime.InteropServices;//这个是必须的命名空间. 3 class SearchWindow 4 { 5 6 private const int WM_Close = 0x0010; 7 [DllImport("User32.dll ", EntryPoint = &