iOS手机端手动复制文字、打电话、获取通讯录信息

1、复制文字

NSString *str=@"你要复制的文字";

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];

pasteboard.string = str;

这样就复制成功了

2、打电话

NSString *data=@"电话号码";

NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",data];

3、获取通讯录信息

-(void)getAddressBook

{

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类

BSAddressBookModel *addressBook = [[BSAddressBookModel 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) {

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;

break;

}

case 1: {// Email

addressBook.email = (__bridge NSString*)value;

break;

}

}

}

}

[self.dataSource addObject:addressBook];//将个人信息添加到数组中,循环完成后addressBookTemp中包含所有联系人的信息

}

}

4、调起Safari,并打开某网页

NSString *str=@"你要打开的网址";

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@""]];

你可能感兴趣的:(iOS手机端手动复制文字、打电话、获取通讯录信息)