1:打开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]];
2:打电话
NSString *num = @"110"; //number为号码字符串 NSString *mobileNumber = [NSString stringWithFormat:@"telprompt://%@", num]; NSLog(@"call phone %@;", mobileNumber); [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mobileNumber]];
注:上面代码触发后,系统会提示用户是否真的要打电话, 电话结束后,会返回至应用程序,
如果将telprompt修改为:tel 后,点击可直接拨打电话, 但电话结束后,不会返回至应用程序
2:打开Safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.baidu.com"]];
3:打开Messages
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];
4:打开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]];
5:打开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];
6:打开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]] ;
7:打开谷歌Maps进行搜索
NSString* searchQuery = @"珠海"; searchQuery = [searchQuery stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]; NSString* urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", searchQuery]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
8:利用OpenUrl打开第三方应用程序
本文释权了打开的方式,很详细.. 地址如下:
这里简单描述一下注意点,
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,似乎没有发生任何事情,待继续考证.
9:为应用设置首选项功能
创建:
时间: 2024-10-04 00:33:12