iOS開發調用手機中的打電話,短信,郵箱,地圖等

1、調用郵件客戶端(Apple Mail)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://admin@hzlzh.com"]];
2、調用電話(Phone Number)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8008808888"]];

iOS應用內撥打電話結束后返回應用
一般在應用中撥打電話的方式是:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://123456789"]];

使用這種方式撥打電話時,當用戶結束通話后,iphone界面會停留在電話界面。
用如下方式,可以使得用戶結束通話后自動返回到應用:

UIWebView*callWebview =[[UIWebView alloc] init];
NSURL *telURL =[NSURL URLWithString:@"tel:10086"];// 貌似tel:// 或者 tel: 都行
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];

//記得添加到view上
[self.view addSubview:callWebview];

 還有一種私有方法:(可能不能通過審核)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://10086"]];
3、調用短信(SMS)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];
4、調用自帶 瀏覽器 safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.hzlzh.com"]];

調用phone可以傳遞號碼,調用SMS 只能設定號碼,不能初始化SMS內容。

若需要傳遞內容可以做如下操作:

加入:MessageUI.framework

#import <MessageUI/MFMessageComposeViewController.h>

實現代理:MFMessageComposeViewControllerDelegate

調用sendSMS函數
//內容,收件人列表
- (void)sendSMS:(NSString *)bodyOfMessage recipientList:(NSArray *)recipients
{

MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];

if([MFMessageComposeViewController canSendText])

{

controller.body = bodyOfMessage;

controller.recipients = recipients;

controller.messageComposeDelegate = self;

[self presentModalViewController:controller animated:YES];

}

}

// 處理發送完的響應結果
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissModalViewControllerAnimated:YES];

if (result == MessageComposeResultCancelled)
NSLog(@"Message cancelled")
else if (result == MessageComposeResultSent)
NSLog(@"Message sent") 
else 
NSLog(@"Message failed") 
}

默認發送短信的界面為英文的,解決辦法為:
在.xib 中的Localization添加一組chinese就ok了

5、調用谷歌地圖(Google Maps)
URL模式:http://maps.google.com/maps?q=<strong>${QUERY_STRING}</strong>
代碼示例:
NSString* searchQuery =@"1 Infinite Loop, Cupertino, CA 95014";
searchQuery =[addressText stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSString* urlString =[NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", searchQuery];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
6、調用應用商店(AppStore)
URL模式:http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&amp;mt=8
代碼示例:
NSURL*appStoreUrl =[NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&amp;amp;mt=8"];
[[UIApplication sharedApplication] openURL:appStoreUrl];
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容