分享

iOS 关联外部应用

 爽行天下丶 2015-06-15

1:打开Mail 

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

2:打电话

  1. NSString *num = @"110"; //number为号码字符串  
  2. NSString *mobileNumber = [NSString stringWithFormat:@"telprompt://%@", num];  
  3. NSLog(@"call phone %@;", mobileNumber);  
  4. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mobileNumber]];  
注:上面代码触发后,系统会提示用户是否真的要打电话, 电话结束后,会返回至应用程序,

     如果将telprompt修改为:tel 后,点击可直接拨打电话, 但电话结束后,不会返回至应用程序

2:打开Safari

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

3:打开Messages

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


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

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

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

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

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

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

7:打开谷歌Maps进行搜索

  1. NSString* searchQuery = @"珠海";  
  2. searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];  
  3. NSString* urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", searchQuery];  
  4. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];  
8:利用OpenUrl打开第三方应用程序

本文释权了打开的方式,很详细.. 地址如下:

http://blog./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中.

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


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

  1. -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation  
  2. {  
  3.     NSLog(@"%@",[url path]);  
  4.     NSLog(@"%@",sourceApplication);  
  5.     NSLog(@"%@",annotation);  
  6.     return NO;  
  7. }  

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

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




注: sourceApplication 表示 App plist文件中标明的 Bundle identifier

      至于返回YES,还是返回NO,似乎没有发生任何事情,待继续考证.

9:为应用设置首选项功能

创建: 


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多