应用之间调用 UIApplication…

来源:互联网 发布:卫龙淘宝辣条直播视频 编辑:程序博客网 时间:2024/06/05 15:43

转自http://blog.163.com/wzi_xiang/blog/static/659829612012910103458775/

一、UIApplication类的OpenURL方法

1、调用app store界面方法

在实际开发中,往往要推荐自己其他应用和推荐自己的收费软件,那么我们就需要在程序中直接连接到app store的相应页面。

 

实际上的做法很简单,使用的还是UIApplication类的OpenURL方法: 

[[UIApplication sharedApplication] openURL:[NSURLURLWithString:@"程序的相应连接"]];


2、调用其它应用的方法

// 调用 自带mail

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"mailto://admin@hzlzh.com"]];

// 调用 电话phone

[[UIApplication sharedApplication]openURL:[NSURLURLWithString:@"tel://8008808888"]];

 

// 调用 SMS

[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"sms://800888"]];

// 调用自带 浏览器 safari

[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"http://www.hzlzh.com"]];

 

// 调用 Remote

[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"remote://fff"]];

调用phone可以传递号码,调用SMS只能设定号码,不能初始化SMS内容。


二、应用程序间通信

 

1、调在plist文件中,注册对外接口

找到appname-info.plist文件,点击打开它,在列表中找到URL types(如果没有,可添加一个URL types)里面的内容设置看下图:

 

应用之间调用 UIApplication类的OpenURL方法 - Awei - 半调子程序员
 

关键Key和Value是 URLidentifier => com.zilanxing.andpush;URL Schemes =>andpush

到此对外接口已注册好

2、调用上面的接口通信

注册url地址:andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv

// 通过iOS浏览器打开应用程序注册应用

 

//andpush用户注册,当用户邮箱收到邀请链接,直接点击下面链接就可以打开andpush应用程序的注册页面

andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv">andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv

//通过其它App应用打开andpush应用程序的注册页面

[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv"]];

3、andpush 响就注册页面的请求

在AndPush应用的AppDelegate.m文件中添加如下代码:

 

 

- (BOOL)application:(UIApplication *)applicationhandleOpenURL:(NSURL *)url

{

    if (!url) {

       return NO;

    }

   NSLog(@"handleOpenURL:%@",[url absoluteString]);

   // host等于cn.andpush.com时,说明是注册请求

    if ([[url hostisEqualToString:@"cn.andpush.com"]){

      // 请求的url地址: andpush://cn.andpush.com/access/register?code=zOdSpC8ZXv

      // 获取注册邀请码 code

      NSString *code =[[url querysubstringFromIndex:[[url queryrangeOfString:@"code="].location+5];

       NSLog(@"code: %@", code);

      // 使用本地 ViewController 来注册

      UserRegisterViewController *viewController= [[[UserRegisterViewController allocinitautorelease];

       viewController.title @"注册";

       viewController.code =code;

      //从底部显示视图

       UINavigationController *navigationController= [[UINavigationController alloc]initWithRootViewController:viewController];

       navigationController.title @"注册";

       [self.tabBarController presentModalViewController:navigationController animated:TRUE];

      [navigationController release];

      //[self.navigationController pushViewController:controlleranimated:YES];

      // [controllerrelease];

       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

0 0
原创粉丝点击