app之间的跳转和传参问题

app 之间跳转和传参;

首先 创建2个app   formApp (需要跳转到另外app的项目)     toApp(被跳转的项目)

 

一:在toApp 项目中的操作:

 

1:创建URLSchemes ,

(1).打开info.plist文件,

2. 在appdelegate.m 中 

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
    /**
     如果使用URL 传参数
     */
    NSLog(@"----formApp_URL:%@",url);
    
    /**
     如果使用的是剪切板传参的话,
     */
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    NSString *content = pasteboard.string;
    NSLog(@"剪切板获取参数:%@",content);
    
    /**
     其他操作
     */
    
    return YES;
}

 

二:在formApp中的操作

 

1.检测 设备 是否安装了toApp 了,并跳转

/**
 跳转操作
 */
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    /**
     toApp Schemes://
     */
    NSString *toAppSchemes = @"willToAppURLSchemes://";
    
    /**
    检测设备 是否安装toApp
     */
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:toAppSchemes]]) {
        
        NSLog(@"alearly install");
        
        /**
         跳转app
         */
        
        /**
         1:使用URL 传递参数
         */
        if ([self IOS10]) {
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?usrid=110",toAppSchemes]] options:@{} completionHandler:^(BOOL success) {
                /**
                  成功跳转后的操作
                 */
            }];
        }else{
        
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?usrid=110",toAppSchemes]]];
        }
        
        
//        /**
//         2:使用剪切板传递参数
//         */
//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:toAppSchemes]];
//        /**
//         系统剪切板 (在topApp中 接受到参数后,清空)
//         */
//        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
//    pasteboard.string = @"user=120&orderid=123456";
        
    }else{
        
        NSLog(@"not install");
    }
}

/**
 判断 系统是否 大于10
 */
- (BOOL)IOS10
{
    return  ([[[UIDevice currentDevice] systemVersion] floatValue]) >= 10 ? YES : NO;
}

 

 

2:注意 在检测是否安装时,在xcode7 和iOS9 之后 需要设置白名单,

打开formApp info.plist文件,添加 LSApplicationQueriesSchemes

 

 

这样就可以成功检测到 是否安装toApp了,

 

3. 在传参数的方式 除了 URL,剪切板,还有钥匙串等,想知道更多的方式或详细的,可以搜索--> app之间的通信

 

posted @ 2017-05-20 19:12  新司机上路  阅读(782)  评论(0编辑  收藏  举报
本人qq1365102044,有问题欢迎沟通!