iOS13 URL Schemes 跳转与传值问题

PS:记录自己工作学习中的一些知识;

一、无法打开APP

假设A(APP)通过以下代码尝试打开B(APP)无效果。

NSURL *url = [NSURL URLWithString:@"wide://"];
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
排查

1、B工程中TARTGETS----info---URL Types 是否正确设置,并检查URL Schemes 是否拼写错误。
iOS13 URL Schemes 跳转与传值问题_第1张图片
URLSchemes01.png

2、在A工程中是否将URL Schemes(wide)设置到白名单中info.plist

LSApplicationQueriesSchemes
wide

二、iOS13中B(APP)无法接受A(APP)传来的值

在Xcode11新建项目,工程中除了有AppDelegate,默认同时创建SceneDelegate文件。


iOS13 URL Schemes 跳转与传值问题_第2张图片
02.png

iOS13 后,APP的UI生命周期交由SceneDelegate管理,所以下面方法接受不到A传递的数据。

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options;
解决方法:

通过以下方法拿到A传递的数据

SceneDelegate.m
- (void)scene:(UIScene *)scene openURLContexts:(NSSet *)URLContexts {
    
    NSEnumerator *enumerator = [URLContexts objectEnumerator];
    UIOpenURLContext *context;
    while (context = [enumerator nextObject]) {
        NSLog(@"context.URL =====%@",context.URL);
        NSLog(@"context.options.sourceApplication ===== %@",context.options.sourceApplication);
    }
}

你可能感兴趣的:(iOS13 URL Schemes 跳转与传值问题)