应用程序间跳转 (友盟SSO 授权 与系统自带的分享)

应用程序间跳转的应用场景

  1. 使用第三方用户登录,如微信登录,返回用户名和密码
  2. 需要用户授权,返回到调用程序,同时返回授权的用户名
  3. 应用程序推广,跳转到itunes并显示指定app下载页
  4. 第三方支付,跳转到支付APP,如支付宝,微信钱包
  5. 显示位置及导航功能时,跳转到第三方地图应用。
  6. 打电话、发邮件、发短信、打开网页等,跳转到内置APP程序

应用间的跳转:

 

1.//url :统一资源占位符 http://baidu.com tel://110 file:///apple/storebock

//由    协议头:http:// tel:// file://

 //     资源路径:baidu.com

 

2.如何配置应用程序的URL的协议头: target (项目)- > info > URL Type >URL Schemes 

3.APP —A

//跳转到微信APP

- (IBAction)jump {

 

    [self openXiaodiWeiXin:@"xiaodi://"];

    

}

 

//跳转到微信好友界面,带上另一个要跳转到的控制器的indentify和自己的Schemes(协议头)

- (IBAction)secttion {

    [self openXiaodiWeiXin:@"xiaodi://secttion?Schemes=news"];

}

//跳转到朋友圈界面

- (IBAction)timeLine {

    [self openXiaodiWeiXin:@"xiaodi://timeLine"];

    

}

 

-(void)openXiaodiWeiXin:(NSString *)URLStr

{

    //2.如何配置应用程序的URL的协议头: target (项目)- > info > URL Type >URL Schemes

    //1.创建要跳转的应用程序的URL

    NSURL *weixinURL = [NSURL URLWithString:URLStr];

    //2.判断URL是否可以跳转

    if ([[UIApplication sharedApplication]canOpenURL:weixinURL]) {

        //跳转到另一个应用程序

        [[UIApplication sharedApplication]openURL:weixinURL];

    }

}

****************

APP — B

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

{

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

    //消除动画,会先把当前的控制器压栈,返回会先返回原来的控制器,再返回主页

    [nav popToRootViewControllerAnimated:NO];

    ViewController *mainVC = [nav.childViewControllers firstObject];

    NSString *urlStr = url.absoluteString;

    if ([urlStr rangeOfString:@"secttion" ].length) {

        //把传过来的Schemes 传到相应控制器(方便跳回原来的APP)

        mainVC.appURLStr = urlStr;

          //跳转到相应的控制器

        [mainVC performSegueWithIdentifier:@"Secction" sender:nil];

         NSLog(@"这是通过微信好友打开:%@",url);

    }else if ([urlStr rangeOfString:@"timeLine"].length)

    {  

//跳转到相应的控制器

        [mainVC performSegueWithIdentifier:@"TimeLine" sender:nil];

         NSLog(@"这是通过微信朋友圈打开的%@",url);

    }

    return YES;

}

****ViewController.m

//使用UIStoryboardSegue 话,可以利用该方法传值

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{

    if ([segue.identifier isEqualToString:@"Secction"]) {

        SecttionViewController *secttionVC =  segue.destinationViewController;

        secttionVC.appURLStr = self.appURLStr;

    }

   

 

}

 

****相应要跳转的页面实现跳回原来的APP

/回到原来的APP

- (IBAction)BackToApp {

    

    NSString *urlStr = self.appURLStr;

    NSRange rangstring =[urlStr rangeOfString:@"xiaodi://secttion?Schemes="];//NSRangeFromString()

    NSString *schemesStr =  [urlStr substringFromIndex: rangstring.length];

    NSLog(@"%@",schemesStr);

    NSString *schemesString = [NSString stringWithFormat:@"%@://",schemesStr];

    NSURL *schemesUrl =[NSURL URLWithString:schemesString];

    if ([[UIApplication sharedApplication]canOpenURL:schemesUrl]) {

        [[UIApplication sharedApplication]openURL:schemesUrl];

    }

 

}

//****************************************************

1.利用系统自带做分享 (看工程 友盟分享)

 

    //1.测试平台是否可用

    if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {

        NSLog(@"新浪微博分享是否成功,如果没有 设置界面 》新浪微博 设置新浪微博ID ");

    }

    

    //2.创建SLComposeViewController

    SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];

    

    //设置发送的文字

    [composeViewController setInitialText:@"千年等一回,不要错过"];

    

    //设置发送的图片

    [composeViewController  addImage:[UIImage imageNamed:@"SSO"]];

    

    //弹出发送界面

    [self presentViewController:composeViewController animated:YES completion:nil];

    //设置分享成功与取消的提醒

    composeViewController.completionHandler = ^(SLComposeViewControllerResult result)

    {

        if (result == SLComposeViewControllerResultCancelled) {

            

            NSLog(@"用户取消了分享");

            

        }else

        {

            NSLog(@"用户点击了发送");

        }

 

    };

 

友盟SSO授权分享:

 

什么是SSO的授权方式呢?

大家常说的SSO的授权方式,其实全称是Single Sign-On,就是利用新浪微博、QQ空间、手机QQFacebook客户端来完成授权。对于用户来说可以省去输入账号密码,更方便安全,因此各大平台均建议开发者优先使用这一种授权方式。ShareSDK目前支持以下平台的SSO:新浪微博、腾讯微博、QQ空间、facebook、Pocket.

网址:http://dev.umeng.com/social/android/operation

 

当要用很自己手机的已经安装的软件进行分享某篇文章图片小视屏等等都可以使用

 

原文地址:https://www.cnblogs.com/meixian/p/5370929.html