1:打开Mail
[csharp] view plain copy
- NSString *recipients = @"mailto:ysy@flyrise?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]];
2:打电话
[csharp] view plain copy
- NSString *num = @"110"; //number为号码字符串
- NSString *mobileNumber = [NSString stringWithFormat:@"telprompt://%@", num];
- NSLog(@"call phone %@;", mobileNumber);
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mobileNumber]];
如果将telprompt修改为:tel 后,点击可直接拨打电话, 但电话结束后,不会返回至应用程序
[csharp] view plain copy
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.baidu"]];
3:打开Messages
[csharp] view plain copy
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];
4:打开App Store 某个应用的评价系统
[csharp] view plain copy
- NSLog(@"%@",[[[SystemGlobalInfo defaultInstance] deviceInfo] applicationId]);
- NSString *str = [NSString stringWithFormat: @"itms-apps://ax.itunes.apple/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@",[[[SystemGlobalInfo defaultInstance] deviceInfo] applicationId]];
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
5:打开App Store 中的某个应用 途中经过Safari
[csharp] view plain copy
- NSString *appID = @"291586600";
- NSString *appUrl = [NSString stringWithFormat:@"http://phobos.apple/WebObjects/MZStore.woa/wa/viewSoftware?id=%@&mt=8",appID];
- NSURL *appStoreUrl = [NSURL URLWithString:appUrl];
- [[UIApplication sharedApplication] openURL:appStoreUrl];
6:打开App Store 中的某个应用 直接跳转
[csharp] view plain copy
- NSString *urlString = @"http://itunes.apple/us/app/ye-wu-xie-zuo-ping-tai/id507704613?mt=8&uo=4";
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]] ;
7:打开谷歌Maps进行搜索
[csharp] view plain copy
- NSString* searchQuery = @"珠海";
- searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
- NSString* urlString = [NSString stringWithFormat:@"http://maps.google/maps?q=%@", searchQuery];
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
本文释权了打开的方式,很详细.. 地址如下:
http://blograinbird/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中.
[csharp] view plain copy
- NSURL *url = [NSURL URLWithString:@"AppMessageDemo:11"];
- if ([[UIApplication sharedApplication] canOpenURL:url]) {
- [[UIApplication sharedApplication] openURL:url];
- }else {
- [ShareCode Msg:@"没安装"];
- }
3: B工程被打开时,请使用如下委托处理打开的消息
[csharp] view plain copy
- -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
- {
- NSLog(@"%@",[url path]);
- NSLog(@"%@",sourceApplication);
- NSLog(@"%@",annotation);
- return NO;
- }
下面这个委托,也就是微文中提到的委托,已经被苹果弃用
[csharp] view plain copy
- -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
- {
- NSLog(@"123");
- return [WXApi handleOpenURL:url delegate:self];
- }
注: sourceApplication 表示 App plist文件中标明的 Bundle identifier
至于返回YES,还是返回NO,似乎没有发生任何事情,待继续考证.
9:为应用设置首选项功能
创建:
1:打开Mail
[csharp] view plain copy
- NSString *recipients = @"mailto:ysy@flyrise?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]];
2:打电话
[csharp] view plain copy
- NSString *num = @"110"; //number为号码字符串
- NSString *mobileNumber = [NSString stringWithFormat:@"telprompt://%@", num];
- NSLog(@"call phone %@;", mobileNumber);
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mobileNumber]];
如果将telprompt修改为:tel 后,点击可直接拨打电话, 但电话结束后,不会返回至应用程序
[csharp] view plain copy
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.baidu"]];
3:打开Messages
[csharp] view plain copy
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];
4:打开App Store 某个应用的评价系统
[csharp] view plain copy
- NSLog(@"%@",[[[SystemGlobalInfo defaultInstance] deviceInfo] applicationId]);
- NSString *str = [NSString stringWithFormat: @"itms-apps://ax.itunes.apple/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@",[[[SystemGlobalInfo defaultInstance] deviceInfo] applicationId]];
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
5:打开App Store 中的某个应用 途中经过Safari
[csharp] view plain copy
- NSString *appID = @"291586600";
- NSString *appUrl = [NSString stringWithFormat:@"http://phobos.apple/WebObjects/MZStore.woa/wa/viewSoftware?id=%@&mt=8",appID];
- NSURL *appStoreUrl = [NSURL URLWithString:appUrl];
- [[UIApplication sharedApplication] openURL:appStoreUrl];
6:打开App Store 中的某个应用 直接跳转
[csharp] view plain copy
- NSString *urlString = @"http://itunes.apple/us/app/ye-wu-xie-zuo-ping-tai/id507704613?mt=8&uo=4";
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]] ;
7:打开谷歌Maps进行搜索
[csharp] view plain copy
- NSString* searchQuery = @"珠海";
- searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
- NSString* urlString = [NSString stringWithFormat:@"http://maps.google/maps?q=%@", searchQuery];
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
本文释权了打开的方式,很详细.. 地址如下:
http://blograinbird/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中.
[csharp] view plain copy
- NSURL *url = [NSURL URLWithString:@"AppMessageDemo:11"];
- if ([[UIApplication sharedApplication] canOpenURL:url]) {
- [[UIApplication sharedApplication] openURL:url];
- }else {
- [ShareCode Msg:@"没安装"];
- }
3: B工程被打开时,请使用如下委托处理打开的消息
[csharp] view plain copy
- -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
- {
- NSLog(@"%@",[url path]);
- NSLog(@"%@",sourceApplication);
- NSLog(@"%@",annotation);
- return NO;
- }
下面这个委托,也就是微文中提到的委托,已经被苹果弃用
[csharp] view plain copy
- -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
- {
- NSLog(@"123");
- return [WXApi handleOpenURL:url delegate:self];
- }
注: sourceApplication 表示 App plist文件中标明的 Bundle identifier
至于返回YES,还是返回NO,似乎没有发生任何事情,待继续考证.
9:为应用设置首选项功能
创建: