实现两个APP之间的跳转传值

时间:2022-12-03 17:36:57

应用A 跳转到 应用B

1.在B中设置URL Schemes     加入一项item 并赋值,比如kiloMeter

  并在B中实现

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    NSLog(@"%@",url);
    NSString *str = [NSString stringWithFormat:@"%@",url];
    NSArray *array = [str componentsSeparatedByString:@"//"];
    str = [array lastObject];
    array = [str componentsSeparatedByString:@","];
    name.text = [array objectAtIndex:0];
    passWord.text = [array objectAtIndex:1];
    return YES;
}

2.在A中跳转代码,跳转时以kiloMeter开头,比如:@"kiloMeter://1111,2222"

    NSURL *url = [NSURL URLWithString:@"kiloMeter://1111,2222"];
    if ([[UIApplication sharedApplication]canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
    }