iOS15下canOpenUrl异常问题思考

问题分类:iOS 新特性问题

case现象:
原包app:iOS15.4-正常,iOS14.5-正常
打sdk包:iOS15.4-异常,iOS14.5(越狱/normal)-正常,15.3.1-异常
空sdk-iOS15.4-异常,iOS14.5-正常
Demo-iOS15.4-正常

报错信息:-canOpenURL: failed for URL: "weixin://" - error: "This app is not allowed to query for scheme weixin"

比较差异点:
原包-rs:iOS15.4-正常
空sdk:iOS15.4-异常
Info.plist有差异

原因:原包LSApplicationQueriesSchemes是50个,sdk化后新加了个url,超过50个(cmd+shift+0可查看官方文档canOpenURL:),该scheme url在列表里面位置超过50就会报错。

If your app is linked against an earlier version of iOS but is running in iOS 9.0 or later, you can call this method up to 50 times. After reaching that limit, subsequent calls always return NO. If the user reinstalls or upgrades the app, iOS resets the limit.

分析

1、下断点

rb canOpenURL
5: regex = 'canOpenURL', locations = 7, resolved = 7, hit count = 0
  5.1: where = UIKitCore`-[UIApplication _canOpenURL:publicURLsOnly:], address = 0x0000000183c415f4, resolved, hit count = 0 
  5.2: where = UIKitCore`-[UIApplication canOpenURL:], address = 0x0000000183c42238, resolved, hit count = 0 
  5.3: where = UIKitCore`__28-[UIApplication canOpenURL:]_block_invoke, address = 0x0000000183c422dc, resolved, hit count = 0 
  5.4: where = UIKitCore`-[UISystemShellApplication canOpenURL:], address = 0x0000000183e41a48, resolved, hit count = 0 
  5.5: where = CoreServices`-[_LSCanOpenURLManager canOpenURL:publicSchemes:privateSchemes:XPCConnection:error:], address = 0x0000000180edf1f4, resolved, hit count = 0 
  5.6: where = CoreServices`-[_LSDOpenClient canOpenURL:publicSchemes:privateSchemes:completionHandler:], address = 0x0000000180f0c460, resolved, hit count = 0 
  5.7: where = SearchFoundation`-[SFPunchout(Handwritten) canOpenURL:], address = 0x0000000198029190, resolved, hit count = 0 

2、查找库的位置

image list grep | UIKitCore
[  0] A84E395E-0B00-3162-B1FD-B861CE41349C 0x0000000182daa000 /Users/xx/Library/Developer/Xcode/iOS DeviceSupport/15.5 (19F77)/Symbols/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore
image list grep | CoreServices
[  0] 148CBE3D-FB7E-3611-B855-F460D5DE652F 0x0000000180eaf000 /Users/xx/Library/Developer/Xcode/iOS DeviceSupport/15.5 (19F77)/Symbols/System/Library/Frameworks/CoreServices.framework/CoreServices

3、查看源码
用hopper打开CoreService源码,搜索_LSCanOpenURLManager查看,有如下方法

int -[_LSCanOpenURLManager schemeQueryLimit]() {
    return 0x32;
}

总结

1、有异常先找差异点,逐个对比
2、新特性怎么提前预知,先去看官方文档(cmd+shift+0)
3、借助hopper分析底层源码

相关参考

iOSDeviceSupport列表
iOSDeviceSupport路径:/Applications/Xcode/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
解决Github访问不了
真机源码路径:
~/Library/Developer/Xcode/iOS DeviceSupport/15.5 (19F77)/Symbols/System/Library/Frameworks/CoreServices.framework
LLDB调试利器及高级用法-2个lldb插件

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容