test app call (未添加任何白名单)
未安装app1
时, app2
尝试用com.fozu._001
打开app1
2022-12-14 23:07:36.388166+0800 TestAppCall-02[57515:6224829] [default] Failed to open URL com.fozu._001: Error Domain=NSOSStatusErrorDomain Code=-50 "invalid input parameters" UserInfo={NSDebugDescription=invalid input parameters, _LSLine=230, _LSFunction=-[_LSDOpenClient openURL:options:completionHandler:]}
2022-12-14 23:07:36.388240+0800 TestAppCall-02[57515:6224370] open succeed!
安装app1
后, app2
再次尝试用com.fozu._001
打开app1
结果还是一样
2022-12-14 23:13:46.838713+0800 TestAppCall-02[58108:6232278] [default] Failed to open URL com.fozu._001://: Error Domain=NSOSStatusErrorDomain Code=-50 "invalid input parameters" UserInfo={NSDebugDescription=invalid input parameters, _LSLine=230, _LSFunction=-[_LSDOpenClient openURL:options:completionHandler:]}
2022-12-14 23:13:46.839042+0800 TestAppCall-02[58108:6232104] open succeed!
给app1添加值为”fozuapp01”的urlScheme
, app2
尝试用这个新添加的urlScheme
打开app1
,
-
结果成功调起,可见是urlScheme的值有问题,应该是不能出现某些特殊字符(经验证不能出现下滑线”_“),否则无效
-
能否调起app跟白名单无关
2022-12-14 23:16:43.266567+0800 TestAppCall-02[58357:6235541] open succeed!
test can open(未添加任何白名单)
已安装app1的情况下,app2用app1配置的不同URLScheme查询
2022-12-14 23:39:15.929634+0800 TestAppCall-02[60079:6254340] -canOpenURL: failed for URL: "com.fozu._01://" - error: "Invalid input URL"
2022-12-14 23:39:15.929706+0800 TestAppCall-02[60079:6254340] scheme com.fozu._01:// is not available !
2022-12-14 23:39:15.929791+0800 TestAppCall-02[60079:6254340] -canOpenURL: failed for URL: "com.fozu._001://" - error: "Invalid input URL"
2022-12-14 23:39:15.929836+0800 TestAppCall-02[60079:6254340] scheme com.fozu._001:// is not available !
// 注意这里, error信息不一样,其实表示,支持这个scheme的app已经安装了,但是不允许查询,当然这个信息只是作为提示给开发者看的,而上面两个scheme(被证实无效),因为无效,所以有不同提示
2022-12-14 23:39:15.930262+0800 TestAppCall-02[60079:6254340] -canOpenURL: failed for URL: "fozuapp01://" - error: "This app is not allowed to query for scheme fozuapp01"
2022-12-14 23:39:15.930327+0800 TestAppCall-02[60079:6254340] scheme fozuapp01:// is not available !
test can open(添加白名单)
卸载app1后,app2用app1配置的不同URLScheme查询
结果同上,会想不论支持scheme的app是否有安装,只要scheme有效就是这样的结果?于是去验证
2022-12-14 23:48:59.176336+0800 TestAppCall-02[60820:6262888] -canOpenURL: failed for URL: "com.fozu._01://" - error: "Invalid input URL"
2022-12-14 23:48:59.176424+0800 TestAppCall-02[60820:6262888] scheme com.fozu._01:// is not available !
2022-12-14 23:48:59.176565+0800 TestAppCall-02[60820:6262888] -canOpenURL: failed for URL: "com.fozu._001://" - error: "Invalid input URL"
2022-12-14 23:48:59.176628+0800 TestAppCall-02[60820:6262888] scheme com.fozu._001:// is not available !
2022-12-14 23:48:59.176642+0800 TestAppCall-02[60820:6263085] [default] Failed to open URL fozuapp01://: Error Domain=NSOSStatusErrorDomain Code=-10814 "(null)" UserInfo={_LSLine=225, _LSFunction=-[_LSDOpenClient openURL:options:completionHandler:]}
2022-12-14 23:48:59.177159+0800 TestAppCall-02[60820:6262888] -canOpenURL: failed for URL: "fozuapp01://" - error: "This app is not allowed to query for scheme fozuapp01"
2022-12-14 23:48:59.177231+0800 TestAppCall-02[60820:6262888] scheme fozuapp01:// is not available !
卸载app1后,app2不同的有效的URLScheme(包括app1没有配置的,用于排查系统的缓存起作用?)查询
上面的猜想得到证实,也就是说,能否查只与白名单有关系,跟是否安装支持响应scheme的app无关;也自然猜想:能成功查询的情况下,查询结果自然就是用户是否安装了支持该scheme的app
2022-12-14 23:52:53.870138+0800 TestAppCall-02[61137:6267406] [default] Failed to open URL fozuapp01://: Error Domain=NSOSStatusErrorDomain Code=-10814 "(null)" UserInfo={_LSLine=225, _LSFunction=-[_LSDOpenClient openURL:options:completionHandler:]}
2022-12-14 23:52:53.870210+0800 TestAppCall-02[61137:6267180] -canOpenURL: failed for URL: "fozuapp001://" - error: "This app is not allowed to query for scheme fozuapp001"
2022-12-14 23:52:53.870286+0800 TestAppCall-02[61137:6267180] scheme fozuapp001:// is not available !
2022-12-14 23:52:53.870710+0800 TestAppCall-02[61137:6267180] -canOpenURL: failed for URL: "fozuapp002://" - error: "This app is not allowed to query for scheme fozuapp002"
2022-12-14 23:52:53.870785+0800 TestAppCall-02[61137:6267180] scheme fozuapp002:// is not available !
2022-12-14 23:52:53.871185+0800 TestAppCall-02[61137:6267180] -canOpenURL: failed for URL: "fozuapp003://" - error: "This app is not allowed to query for scheme fozuapp003"
2022-12-14 23:52:53.871249+0800 TestAppCall-02[61137:6267180] scheme fozuapp003:// is not available !
安装app1,给app2配置白名单(com.fozu._01, com.fozu._001, fozuapp01)测试canOpen app1
结果如预期,有效的在白名单上的scheme, 成功测试到, 安装了支持该scheme的app
2022-12-15 00:07:43.366394+0800 TestAppCall-02[62394:6282003] -canOpenURL: failed for URL: "com.fozu._01://" - error: "Invalid input URL"
2022-12-15 00:07:43.366537+0800 TestAppCall-02[62394:6282003] scheme com.fozu._01:// is not available !
2022-12-15 00:07:43.366920+0800 TestAppCall-02[62394:6282003] -canOpenURL: failed for URL: "com.fozu._001://" - error: "Invalid input URL"
2022-12-15 00:07:43.367177+0800 TestAppCall-02[62394:6282003] scheme com.fozu._001:// is not available !
// 这个有效的scheme,测试成功,表示安装了支持该scheme的app
2022-12-15 00:07:43.369847+0800 TestAppCall-02[62394:6282003] scheme fozuapp01:// is available !
卸载app1, 给app2配置白名单(com.fozu._01, com.fozu._001, fozuapp01)测试canOpen app1
结果如预期,有效的在白名单上的scheme, 成功测试到, 未安装支持该scheme的app
2022-12-15 00:11:07.841881+0800 TestAppCall-02[62651:6285615] -canOpenURL: failed for URL: "com.fozu._01://" - error: "Invalid input URL"
2022-12-15 00:11:07.841968+0800 TestAppCall-02[62651:6285615] scheme com.fozu._01:// is not available !
2022-12-15 00:11:07.842069+0800 TestAppCall-02[62651:6285615] -canOpenURL: failed for URL: "com.fozu._001://" - error: "Invalid input URL"
2022-12-15 00:11:07.842127+0800 TestAppCall-02[62651:6285615] scheme com.fozu._001:// is not available !
2022-12-15 00:11:07.844607+0800 TestAppCall-02[62651:6285615] -canOpenURL: failed for URL: "fozuapp01://" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
// 这个有效的scheme,测试成功,表示未安装支持该scheme的app
2022-12-15 00:11:07.844685+0800 TestAppCall-02[62651:6285615] scheme fozuapp01:// is not available !
References
-
https://useyourloaf.com/blog/querying-url-schemes-with-canopenurl/
从这个链接才了解到能不能用如下API调起app跟白名单没有关系,之前对白名单是有误解的,没有探索过
- (void)openURL:(NSURL*)url options:(NSDictionary<UIApplicationOpenExternalURLOptionsKey, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion
白名单的由来
iOS9 之前的 SDK开发的app,可以通过如下API随意查询用户是否安装了支持某个scheme的app
- (BOOL)canOpenURL:(NSURL *)url API_AVAILABLE(ios(3.0));
苹果基于用户隐私保护的考虑,基于iOS9及之后版本的SDK开发的app,要想进行这一查询,必须把要查询的scheme加入自身的白名单,否则因无权限而返回NO