uni-app SDK升级后 isExistsApp 方法崩溃
uni-app SDK升级后 isExistsApp 方法崩溃
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| Mac | 10.15.7 | HBuilderX |
示例代码:
// 运行目录中是否已经存在 App
// @param appid appid
- (BOOL)isExistsApp:(NSString *)appid {
return [DCUniMPSDKEngine isExistsApp:appid];
}
操作步骤:
直接调用方法
预期结果:
正常运行
实际结果:
崩溃
bug描述:
把SDK封成Flutter插件,升级SDK后,用9月份的版本还是可以的,在Flutter插件里调用 isExistsApp 时报错并崩溃,崩溃信息如下:
2021-10-26 10:24:02.148637+0800 Runner[52946:440226] -[__NSDictionaryM length]: unrecognized selector sent to instance 0x600001abc0a0
2021-10-26 10:24:02.171834+0800 Runner[52946:440226] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM length]: unrecognized selector sent to instance 0x600001abc0a0'
First throw call stack:
(
0 CoreFoundation 0x00007fff2041daf2 exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff20177e78 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2042c6f7 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3 CoreFoundation 0x00007fff20422032 __forwarding + 1489
4 CoreFoundation 0x00007fff20424068 _CF_forwarding_prep_0 + 120
5 Foundation 0x00007fff207f99ec -[NSPathStore2 stringByAppendingPathComponent:] + 121
6 Runner 0x000000010f9c512e +[PTPathUtil appRootPathWithAppidL:] + 89
7 Runner 0x000000010f9e55a2 +[DCUniMPSDKEngine isExistsApp:] + 86
8 Runner 0x000000010fc45ab2 -[YingziFlutterAppletPlugin isExistsApp:] + 66
9 Runner 0x000000010fc448ba -[YingziFlutterAppletPlugin handleMethodCall:result:] + 2346
10 Flutter 0x0000000110ed5fca 45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 104
11 Flutter 0x000000011068e1fa _ZNK7flutter21PlatformMessageRouter21HandlePlatformMessageEN3fml6RefPtrINS_15PlatformMessageEEE + 166
12 Flutter 0x000000011069340a _ZN7flutter15PlatformViewIOS21HandlePlatformMessageEN3fml6RefPtrINS_15PlatformMessageEEE + 38
13 Flutter 0x0000000110a20ab9 _ZNSt3110function6__funcIZN7flutter5Shell29OnEngineHandlePlatformMessageEN3fml6RefPtrINS2_15PlatformMessageEEEE4$_36NS_9allocatorIS8_EEFvvEEclEv + 83
14 Flutter 0x00000001109a469a _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 160
15 Flutter 0x00000001109a90e6 _ZN3fml17MessageLoopDarwin11OnTimerFireEP16CFRunLoopTimerPS0_ + 26
16 CoreFoundation 0x00007fff2038cc47 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 20
17 CoreFoundation 0x00007fff2038c71a CFRunLoopDoTimer + 926
18 CoreFoundation 0x00007fff2038bccd CFRunLoopDoTimers + 265
19 CoreFoundation 0x00007fff2038634e __CFRunLoopRun + 1949
20 CoreFoundation 0x00007fff203856c6 CFRunLoopRunSpecific + 567
21 GraphicsServices 0x00007fff2b76adb3 GSEventRunModal + 139
22 UIKitCore 0x00007fff24675187 -[UIApplication _run] + 912
23 UIKitCore 0x00007fff2467a038 UIApplicationMain + 101
24 Runner 0x000000010f862580 main + 112
25 libdyld.dylib 0x00007fff20256409 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM length]: unrecognized selector sent to instance 0x600001abc0a0'
terminating with uncaught exception of type NSException
CoreSimulator 732.18.0.2 - Device: iPhone 12 (3DF07B45-73D7-4880-BEBD-4EC582929534) - Runtime: iOS 14.2 (18B79) - DeviceType: iPhone 12
(Recorded stack frame)

更多关于uni-app SDK升级后 isExistsApp 方法崩溃的实战教程也可以访问 https://www.itying.com/category-93-b0.html
1 回复
更多关于uni-app SDK升级后 isExistsApp 方法崩溃的实战教程也可以访问 https://www.itying.com/category-93-b0.html
根据崩溃信息 -[__NSDictionaryM length]: unrecognized selector sent to instance,问题出在 isExistsApp: 方法内部调用 stringByAppendingPathComponent: 时,参数类型错误。从堆栈看,PTPathUtil appRootPathWithAppidL: 期望传入一个 NSString 类型的 appid,但实际传入了一个 NSDictionary 对象。
原因分析:
- 参数类型不匹配:Flutter 插件调用原生方法时,传入的
appid参数可能被错误地包装成了字典(NSDictionary),而不是字符串(NSString)。 - SDK 升级兼容性问题:升级 uni-app SDK 后,
DCUniMPSDKEngine内部对参数类型的校验或处理可能发生变化,导致传入错误类型时崩溃。
解决方案:
- 检查 Flutter 插件传参:确保调用
isExistsApp:时,appid参数是字符串类型,而非 Map/Dictionary。检查 Flutter 侧代码,确认MethodChannel调用时参数类型正确。 - 验证参数类型:在原生 iOS 代码中,对传入的
appid进行类型校验,例如:- (BOOL)isExistsApp:(id)appid { if (![appid isKindOfClass:[NSString class]]) { // 处理类型错误,如返回 NO 或抛出异常 return NO; } return [DCUniMPSDKEngine isExistsApp:appid]; }

