iOS:APP跳转

1: Universal Links
【iOS:APP跳转】后台配置跳转包名 跳转并且可以拿到回调
2: URL Scheme
本地配置好URLScheme 跳转并且可以拿到回调
3: 动态调用未公开API (openApplicationWithBundleID:)
直接通过包名跳转不会回调
1: Universal Links (苹果官方文档) 下面以微信sdk为例
a)Universal Links必须支持https
b)Universal Links配置的paths不能带query参数
c)微信使用Universal Links拉起第三方App时,会在Universal Links末尾拼接路径和参数,因此App配置的paths必须加上通配符/*
1.首先要在苹果开发者网页-Identifiers选择Associated Domains iOS:APP跳转
文章图片
apple develper 2.Xcode版本小于11的前往Capabilities,Xcode11前往Signing&Capabilities,输入applinks://XXX(XXX内容为你的域名:api.test.com,不带https:// !!!!) iOS:APP跳转
文章图片
Xcode11 AppDelegate加上处理的回调

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray> * __nullable restorableObjects))restorationHandler { 处理回调 return [WXApi handleOpenUniversalLink:userActivity delegate:self]; }

3.在桌面新建个apple-app-site-association,不带后缀 touch apple-app-site-association
vim apple-app-site-association
输入
{ "applinks": { "apps": [], "details": [ { "appID": "4ZSH3DDADG.com.test.test1", "paths": [ "*" ] }, { "appID": "4ZSH3DDADG.com.test.test2", "paths": [ "*" ] } ] } }

  • 这里的4ZSH3DDADG.com.test.test1,4ZSH3DDADG是你的TeamID,直接在Xcode的Signing&Capabilities就能看到,后面跟着的是包名,details里面可以有多个,一个Universal Links跳多个包名
4.让后端把apple-app-site-association放到域名的根路径 5.测试,直接请求https://api.test.com->你的域名 下拉就会出现这个就是配置成功了 iOS:APP跳转
文章图片
WechatIMG364.jpeg 注意:APP不会每次打开都去请求服务器的apple-app-site-association, 所以修改apple-app-site-association之后需要卸载才能看到效果 2: URL Scheme
iOS:APP跳转
文章图片
URL Scheme AppDelegate加上处理的回调
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options{ //处理回调 }

这个就写死在本地, 把这个URL Scheme提供给外部调用就好了 测试的话直接浏览器输入 (URL Scheme):// 就可以跳转了
3.根据包名打开app,敏感字符串拆开动态调用
static BOOL OpenProjectBundle(NSString *bundleID){ Class LSApplicationWorkspace_class = NSClassFromString([@"LSApplicati" stringByAppendingString:@"onWorkspace"]); SEL defaultWspc = NSSelectorFromString([@"defaultW" stringByAppendingString:@"orkspace"]); SEL opensdasadkl = NSSelectorFromString([@"openApplicatio" stringByAppendingString:@"nWithBundleID:"]); NSObject * workspace = [LSApplicationWorkspace_class performSelector:defaultWspc]; BOOL isopen = [workspace performSelector:opensdasadkl withObject:bundleID]; return isopen; }

这个是未公开api, 不是私有api,可以通过审核上架,亲测

    推荐阅读