ios手机功能:电话 短信 通讯录 总结
2014-03-12 14:59
423 查看
1打电话功能
NSString *str = [telePhone stringByReplacingOccurrencesOfString:@"-" withString:@""];NSLog(@"telephone:%@",str);//str为电话号码
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",str]]];
2发短信功能引入MessageUI.framework库文件
#import <MessageUI/MessageUI.h>添加这两个协议
MFMessageComposeViewControllerDelegate
#pragma mark ------Send Message------- (void)sendMessage
{
//message
BOOL canSendSMS = [MFMessageComposeViewController
canSendText];
if (canSendSMS) {
MFMessageComposeViewController *picker = [[MFMessageComposeViewController
alloc] init];
picker.messageComposeDelegate =
self;
//picker.navigationBar.tintColor = [UIColor blackColor];
picker.body = [message
objectAtIndex:message_objindex] ;
//picker.recipients = [NSArray arrayWithObject:@"186-0123-0123"];
[self
presentModalViewController:picker animated:YES];
[picker release];
}else {
UIAlertView *alertDialog;
alertDialog = [[UIAlertView
alloc]initWithTitle:@"提醒"
message:@"没有短信功能" delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil,
nil];
[alertDialog show];
}
}
3 获取通讯录
#pragma mark ---------Get Phone List------- (void)getPhoneList
{
ABAddressBookRef addressBook =
nil;
if ([[UIDevice
currentDevice].systemVersion
floatValue] >= 6.0)
{
addressBook = ABAddressBookCreateWithOptions(NULL,
NULL);
//等待同意后向下执行
dispatch_semaphore_t sema =
dispatch_semaphore_create(0);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted,
CFErrorRef error)
{
dispatch_semaphore_signal(sema);
});
dispatch_semaphore_wait(sema,
DISPATCH_TIME_FOREVER);
dispatch_release(sema);
}
else
{
addressBook = ABAddressBookCreate();
}
NSArray *myContactArray = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
for(int i =
0; i < [myContactArray count]; i++){
ABRecordRef people = (ABRecordRef)[myContactArray
objectAtIndex:i];
CFStringRef firstName =
ABRecordCopyValue(people, kABPersonFirstNameProperty);
CFStringRef midName =
ABRecordCopyValue(people, kABPersonMiddleNameProperty);
CFStringRef lastName =
ABRecordCopyValue(people, kABPersonLastNameProperty);
CFStringRef items =
ABRecordCopyValue(people,kABPersonPhoneProperty);
NSMutableString *fullName = [NSMutableString
string];
if([(NSString *)lastName
length] > 0){
[fullName appendString:(NSString *)lastName];
}
if([(NSString *)firstName
length] > 0){
[fullName appendString:(NSString *)firstName];
}
if([(NSString *)midName
length] > 0){
[fullName appendString:(NSString *)midName];
}
CFArrayRef phoneNums =
ABMultiValueCopyArrayOfAllValues(items);
if (phoneNums) {
for (int j=0; j<CFArrayGetCount(phoneNums); j++)
{
NSString *phone = (NSString*)CFArrayGetValueAtIndex(phoneNums, j);
[name addObject:fullName];
[phonenum
addObject:phone];
}
}
}
}
4发邮件
添加这个协议MFMailComposeViewControllerDelegate,#pragma mark ----- Send Email--------
-(void)displayComposerSheet
{ Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass !=
nil)
{ // We must always check whether the current device is configured for sending emails
if ([mailClass
canSendMail])
{
MFMailComposeViewController *picker = [[MFMailComposeViewController
alloc] init];
picker.mailComposeDelegate =
self;
[picker setSubject:@"春节快乐!"];
// Set up recipients
NSArray *toRecipients = [NSArray
arrayWithObject:@" "];
[picker
setToRecipients:toRecipients];
[picker
setMessageBody:[message
objectAtIndex:message_objindex]
isHTML:NO];
// Fill out the email body text
[self
presentModalViewController:picker
animated:YES];
}
else
{
UIAlertView *alertDialog;
alertDialog = [[UIAlertView
alloc]initWithTitle:@"提醒"
message:@"不支持功能" delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil,
nil];
[alertDialog
show];
} }
}
有什么不对的地方望大家指正
相关文章推荐
- iOS 调用系统相关功能(本机信息,手电筒,电话,短信,通讯录,内存,电池,亮度)
- iOS调取通讯录并发送短信功能
- Moto XT800(双卡手机)短信和电话服务的总结
- 仿IOS通讯录效果,实现获取手机通讯录、字母排序显示、搜索联系人、拨打电话
- iOS调用电话短信网页功能
- ios 获得通讯录中联系人的所有属性 亲测,可行 兼容io6 和 ios 7整理:iOS 短信与电话事件的获取
- 获取手机通讯录放入PinnedSectionListView中,按名字首字母排序,并且实现拨打电话功能。
- OC笔记 - iOS适配、block内存泄露、电话短信邮件等小功能(2015.3.27)
- iOS应用调用手机发送短信和拨打电话
- Moto XT800(双卡手机)短信和电话服务的总结
- 实现在手机浏览器上面打 电话发 短信 定位的 功能
- IOS_短信_电话_email_MIMETYPE_通讯录_地图_定位
- iOS软件开发添加电话、短信、邮件常用功能实现
- html5开发手机打电话发短信功能,html5的高级开发,html5开发大全,html手机电话短信功能详解
- iOS 点击按钮实现拨打电话,发送短信功能
- IOS通讯录的隐藏标签(电话)的特殊功能
- iOS短信,邮件,电话功能的开发
- IOS-电话和短信功能
- Android获取手机通讯录调用系统短信功能
- iOS之iPhone手机通讯录和短信搜索界面的实现以及UISearchController和UISearchDisplayController的浅析