应用之间调用 UIApplication类的OpenURL方法
2014-10-05 14:27
197 查看
from: http://blog.163.com/wzi_xiang/blog/static/659829612012910103458775/
一、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:navigationControlleranimated: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
一、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:navigationControlleranimated: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
相关文章推荐
- 应用之间调用 UIApplication类的OpenURL方法
- 应用之间调用 UIApplication类的OpenURL方法
- 应用之间调用 UIApplication类的OpenURL方法
- 应用之间调用 UIApplication类的OpenURL方法
- this的神奇应用,用于构造方法之间调用
- go语言使用go-sciter创建桌面应用(三) 事件处理,函数与方法定义,go与tiscript之间相互调用
- Java应用技巧:SE6调用编译器的两种方法(1)
- 在Biztalk应用中调用程序集的方法
- C#多线程-不同线程之间通过事件委托封送调用方法
- 不同编码网站内容之间的JS调用方法
- js与C#之间相互调用的一些方法
- 关于ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用/传值 一点点经验
- ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用
- 应用框架的设计与实现——.NET平台(8.3 调用非托管代码的方法)
- 关于ASP.NET同页面内【用户控件与父页面】以及【用户控件与用户控件】之间方法调用/传值 一点点经验
- 如何应用Java的链式方法调用 推荐
- 再flex 通过 调用自身的url,重载整个应用的方法
- Java动态调用类方法的应用
- ASP.Net Ajax应用初步:使用AJAX直接调用后台方法
- C#多线程-不同线程之间通过事件委托封送调用方法