读书人

在IOS运用中打开另外一个应用的解决方

发布时间: 2012-11-09 10:18:47 作者: rapoo

在IOS应用中打开另外一个应用的解决方案

最近要在IOS中实现一个应用启动另外一个应用的功能,搜了一些资料,使用UIApplication的openURL:的方法就能实现,现在整理和大家分享一下!

注册自定义URL协议

首先被启动的应用需要向iPhone注册一个自定义URL协议。这是在你的项目文件夹的info.plist文件进行的(就是你改变应用程序图标的同一个文件)。
Step1. 右键,选择“Add Row”Step2. Key值选择“URL types”
Step3. 打开“Item 0″,然后为该key增加一个URL identifier。可以是任何值,但建议用“反域名”(例如 “com.fcplayer.testHello”)。
Step4. 在“Item 0”下再加一行。
Step5. 选择“URL Schemes” 作为Key。
Step6. 输入你的URL协议名 (例如“testHello://” 应写做“testHello”)。如果有必要,你可以在这里加入多个协议。
操作截图如下:

在IOS运用中打开另外一个应用的解决方案

访问自定义URL

在主应用程序中通过访问自定义URL启动另外一个应用:

-(IBAction)openMaps {//打开地图    // Where is Apple on the map anyway?    NSString* addressText = @”1 Infinite Loop, Cupertino, CA 95014″;    // URL encode the spaces    addressText =  [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];    NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", addressText];    // lets throw this text on the log so we can view the url in the event we have an issue    NSLog(urlText);    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];    }    -(IBAction)openEmail {//打开mail    // Fire off an email to apple support    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://devprograms@apple.com"]];    }    -(IBAction)openPhone {//拨打电话    // Call Google 411    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]];    }    -(IBAction)openSms {//打开短信    // Text to Google SMS    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://466453"]];    }    -(IBAction)openBrowser {//打开浏览器    // Lanuch any iPhone developers fav site    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunesconnect.apple.com"]];}

附参考链接:http://blog.csdn.net/arthurchenjs/article/details/6920631

读书人网 >操作系统

热点推荐