应用程序跳转

1. 应用场景:

  • 使用第三方登录 : 需要用户授权, 授权完成后, 返回应用
  • 应用推广, 积分墙
  • 支付宝, 第三方支付, 淘宝, 电话费充值

2. 应用程序跳转   -----   实际上是调用其他应用的URL

  •  target  --- info   ---  URL Type  +

3.应用跳转 代码

    //

    UIApplication *app = [UIApplication sharedApplication];

// 只需要 设置协议头就可以跳转了    

    NSURL *url = [NSURL URLWithString:@"sina://"];

    if ([app canOpenURL:url]) {

        [app openURL:url];

    }else{

        LogRed(@"到AppStore --- 下载");

    }

------------------------------------------------------------------------------------------------------------------------

4. 跳转到指定界面

/**

 *  当被其他应用程序通过URL打开时, 就会调用

 *

 *  @param application 当前应用程序

 *  @param url         打开当前应用程序的URL

 */

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

{

    LogGreen(@"%@",url);

    

    // 1. 获取 授权控制器

    UINavigationController *nav = (UINavigationController *)self.window.rootViewController;

    

    // 栈顶Viewcon

    ViewController *homeVC = (ViewController *)nav.topViewController;

    

    

    NSString *urlStr = url.absoluteString;

    if ([urlStr hasPrefix:@"sina://author"]) {

        LogYellow(@"跳转到 --  授权");

        

        // 截取1Con scheme

        NSRange range = [urlStr rangeOfString:@"sina://author?myscheme="];

        NSString *subStr = [urlStr substringFromIndex:range.length];

        

        LogMagenta(@"%@",subStr);

        

        [homeVC performSegueWithIdentifier:@"home2author" sender:nil];

        

    }else if ([urlStr hasPrefix:@"sina://view?id="]){

        LogYellow(@"跳转到  --- 详情");

        

        [homeVC performSegueWithIdentifier:@"home2detail" sender:nil];

    }

    

    return YES;

}

 

/**

 *  当被其他应用程序通过URL打开时, 就会调用 --- 新的方法

 *

 *  @param application       当前应用程序

 *  @param url               打开当前应用程序的url

 *  @param sourceApplication 打开当前应用程序的 bundle identifier

 *  @param annotation

 *

 *  @return

 */

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

{

    /**

     *  sourceApplication

     

     标记 - 唯一App(积分墙)

     */

    

    return YES;

}

 

posted @ 2015-09-23 00:52  guangleijia  阅读(238)  评论(0编辑  收藏  举报