iOS-打开外部应用、Safari、邮箱等

1:打开Safari

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.baidu.com"]];  

2:打电话

NSString *num = @"110"; //number为号码字符串  
NSString *mobileNumber = [NSString stringWithFormat:@"telprompt://%@", num];  
NSLog(@"call phone %@;", mobileNumber);  
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mobileNumber]];  

提示:上面代码触发后,系统会提示用户是否真的要打电话, 电话结束后,会返回至应用程序,
如果将telprompt修改为:tel 后,点击可直接拨打电话, 但电话结束后,不会返回至应用程序

3:打开Mail

NSString *recipients = @"mailto:ysy@flyrise.cn?subject=Hello from California!";   
NSString *body = @"&body=It is raining in sunny California!";   
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];   
          email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];   
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];   

4:打开Messages

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];  

5:打开App Store 某个应用的评价系统

NSLog(@"%@",[[[SystemGlobalInfo defaultInstance] deviceInfo] applicationId]);  
NSString *str = [NSString stringWithFormat: @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@",[[[SystemGlobalInfo defaultInstance] deviceInfo] applicationId]];  
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];  

6:打开App Store 中的某个应用 途中经过Safari

NSString *appID = @"291586600";  
NSString *appUrl = [NSString stringWithFormat:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@&mt=8",appID];  
NSURL *appStoreUrl = [NSURL URLWithString:appUrl];  
[[UIApplication sharedApplication] openURL:appStoreUrl];  

7:打开App Store 中的某个应用 直接跳转

NSString *urlString = @"http://itunes.apple.com/us/app/ye-wu-xie-zuo-ping-tai/id507704613?mt=8&uo=4";  
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]] ;  

8:打开谷歌Maps进行搜索

NSString* searchQuery = @"珠海";  
searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];  
NSString* urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", searchQuery];  
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];  

9:利用OpenUrl打开第三方应用程序

本文释权了打开的方式,很详细.. 地址如下:
http://blog.cnrainbird.com/index.php/2012/06/04/tong_guo_openurl_qi_dong_di_san_fang_app_bing_chuan_can_shu/
这里简单描述一下注意点,
1: A工程 需要打开 B 工程 那么B工程需要在plist文件中 进行UrlType的注册
2:在启动其他第三方应用程序之前,可以通过如下代码判断,应用程序是否已经安装在iPhone中.

NSURL *url = [NSURL URLWithString:@"AppMessageDemo:11"];    
if ([[UIApplication sharedApplication] canOpenURL:url]) {  
     [[UIApplication sharedApplication] openURL:url];   
}else {  
     [ShareCode Msg:@"没安装"];  
}  

3: B工程被打开时,请使用如下委托处理打开的消息

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation  
{  
    NSLog(@"%@",[url path]);  
    NSLog(@"%@",sourceApplication);  
    NSLog(@"%@",annotation);  
    return NO;  
}  

下面这个委托,也就是微文中提到的委托,已经被苹果弃用

-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url  
{  
    NSLog(@"123");  
    return [WXApi handleOpenURL:url delegate:self];  
}  

注: sourceApplication 表示 App plist文件中标明的 Bundle identifier
至于返回YES,还是返回NO,似乎没有发生任何事情,待继续考证.

10:为应用设置首选项功能
创建:
这里写图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值