应用之间调用 UIApplication类的OpenURL方法
2016-02-18 13:12
323 查看
一、UIApplication类的OpenURL方法
1、调用app store界面方法
在实际开发中,往往要推荐自己其他应用和推荐自己的收费软件,那么我们就需要在程序中直接连接到app store的相应页面。
实际上的做法很简单,使用的还是UIApplication类的OpenURL方法:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"程序的相应连接"]];
2、调用其它应用的方法
// 调用 自带mail
[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"mailto://admin@hzlzh.com"]];
// 调用 电话phone
[[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"tel://8008808888"]];
// 调用 SMS
[[UIApplicationsharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];
// 调用自带 浏览器 safari
[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"http://www.hzlzh.com"]];
// 调用 Remote
[[UIApplicationsharedApplication] openURL:[NSURL URLWithString:@"remote://fff"]];
调用phone可以传递号码,调用SMS只能设定号码,不能初始化SMS内容。
二、应用程序间通信
1、调在plist文件中,注册对外接口
找到appname-info.plist文件,点击打开它,在列表中找到URL types(如果没有,可添加一个URL types )里面的内容设置看下图:
关键Key和Value是 URL identifier => com.zilanxing.andpush;URL Schemes => andpush
到此对外接口已注册好
2、调用上面的接口通信
注册url地址:andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv
// 通过iOS浏览器打开应用程序注册应用
// andpush用户注册,当用户邮箱收到邀请链接,直接点击下面链接就可以打开andpush应用程序的注册页面
<a href="andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv">andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv</a>
// 通过其它App应用打开andpush应用程序的注册页面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv"]];
3、 andpush 响就注册页面的请求
在AndPush应用的AppDelegate.m文件中添加如下代码:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
if (!url) {
return NO;
}
NSLog(@"handleOpenURL: %@",
[url absoluteString]);
// 在host等于cn.andpush.com时,说明是注册请求
if ([[url host] isEqualToString:@"cn.andpush.com"])
{
// 请求的url地址: andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv
// 获取注册邀请码 code
NSString *code = [[url query] substringFromIndex:[[url query] rangeOfString:@"code="].location+5];
NSLog(@"code: %@", code);
// 使用本地 ViewController 来注册
UserRegisterViewController *viewController = [[[UserRegisterViewControlleralloc] init] autorelease];
viewController.title = @"注册";
viewController.code = code;
//从底部显示视图
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
navigationController.title = @"注册";
[self.tabBarController presentModalViewController:navigationController animated:TRUE];
[navigationController release];
// [self.navigationController pushViewController:controller animated:YES];
// [controller release];
return YES;
} else {
return NO;
}
}
到此搞定,以后再完善。
其它参考:
http://www.cocoachina.com/newbie/tutorial/2012/0529/4302.html http://www.byywee.com/page/M0/S753/753470.html http://www.cocoachina.com/bbs/simple/?t58388.html
1、调用app store界面方法
在实际开发中,往往要推荐自己其他应用和推荐自己的收费软件,那么我们就需要在程序中直接连接到app store的相应页面。
实际上的做法很简单,使用的还是UIApplication类的OpenURL方法:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"程序的相应连接"]];
2、调用其它应用的方法
// 调用 自带mail
[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"mailto://admin@hzlzh.com"]];
// 调用 电话phone
[[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"tel://8008808888"]];
// 调用 SMS
[[UIApplicationsharedApplication] openURL:[NSURL URLWithString:@"sms://800888"]];
// 调用自带 浏览器 safari
[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"http://www.hzlzh.com"]];
// 调用 Remote
[[UIApplicationsharedApplication] openURL:[NSURL URLWithString:@"remote://fff"]];
调用phone可以传递号码,调用SMS只能设定号码,不能初始化SMS内容。
二、应用程序间通信
1、调在plist文件中,注册对外接口
找到appname-info.plist文件,点击打开它,在列表中找到URL types(如果没有,可添加一个URL types )里面的内容设置看下图:
关键Key和Value是 URL identifier => com.zilanxing.andpush;URL Schemes => andpush
到此对外接口已注册好
2、调用上面的接口通信
注册url地址:andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv
// 通过iOS浏览器打开应用程序注册应用
// andpush用户注册,当用户邮箱收到邀请链接,直接点击下面链接就可以打开andpush应用程序的注册页面
<a href="andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv">andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv</a>
// 通过其它App应用打开andpush应用程序的注册页面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv"]];
3、 andpush 响就注册页面的请求
在AndPush应用的AppDelegate.m文件中添加如下代码:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
if (!url) {
return NO;
}
NSLog(@"handleOpenURL: %@",
[url absoluteString]);
// 在host等于cn.andpush.com时,说明是注册请求
if ([[url host] isEqualToString:@"cn.andpush.com"])
{
// 请求的url地址: andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv
// 获取注册邀请码 code
NSString *code = [[url query] substringFromIndex:[[url query] rangeOfString:@"code="].location+5];
NSLog(@"code: %@", code);
// 使用本地 ViewController 来注册
UserRegisterViewController *viewController = [[[UserRegisterViewControlleralloc] init] autorelease];
viewController.title = @"注册";
viewController.code = code;
//从底部显示视图
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
navigationController.title = @"注册";
[self.tabBarController presentModalViewController:navigationController animated:TRUE];
[navigationController release];
// [self.navigationController pushViewController:controller animated:YES];
// [controller release];
return YES;
} else {
return NO;
}
}
到此搞定,以后再完善。
其它参考:
http://www.cocoachina.com/newbie/tutorial/2012/0529/4302.html http://www.byywee.com/page/M0/S753/753470.html http://www.cocoachina.com/bbs/simple/?t58388.html
相关文章推荐
- AppDelegate中几个常用的回调调用时机
- LocalBroadcastManager 使用小结
- Memory Analysis for Android Applications
- iOS 开发设置空间旋转中心点的代码
- iOS 纯代码适配iPhone6,6p
- Android app 运行时按了Home键,进入到另一程序,再调用原来程序
- Android安卓开发中终止线程方法
- Android学习必备--java工具15个
- Android 源码编译经验分享, 以及如何使用Android studio 阅读整个源码
- Android 抖动效果
- 用Pull解析将xml转换成List<Object>对象
- iOS NSPredicate 模糊、精确、查询
- iOS应用程序发布AppStore及更新流程
- Android Canvas绘图详解(图文)
- iOS 图片扫描(Moodstocks)
- #android#android studio 使用cardview
- Android获取view在屏幕中的位置
- [iOS]The app icon set named "AppIcon" did not have any applicable content
- 安卓 ImageView ACTION_UP&DOWN监听
- Android编程之LayoutInflater的inflate方法详解