RN ios 错误 Unknown argument type '__attribute__' in method RCTAppState getCurrentAppState:error

React Native 2020-03-08 阅读 142 评论 0

问题描述

React Native 项目的 package.json 如下:"react": "16.8.3", "react-native": "0.59.5"。Xcode 11 下编译成功了,但是在 IPhone 模拟器运行后报错了:

2020-03-08 09:32:21.481 [error][tid:main][RCTModuleMethod.mm:375] Unknown argument type '__attribute__' in method -[RCTAppState getCurrentAppState:error:]. Extend RCTConvert to support this type.
2020-03-08 09:32:21.481540+0800 NativeTest[6056:30774] Unknown argument type '__attribute__' in method -[RCTAppState getCurrentAppState:error:]. Extend RCTConvert to support this type.
2020-03-08 09:32:21.514 [fatal][tid:main] Exception '*** -[__NSArrayM objectAtIndexedSubscript:]: index 1 beyond bounds [0 .. 0]' was thrown while invoking getCurrentAppState on target AppState with params (
    2,
    3
)
callstack: (
    0   CoreFoundation                      0x00007fff23c7127e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff513fbb20 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23d03ab1 _CFThrowFormattedException + 194
    3   CoreFoundation                      0x00007fff23b85749 -[__NSArrayM objectAtIndexedSubscript:] + 169
    4   NativeTest                          0x00000001011d00df -[RCTModuleMethod processMethodSignature] + 13327
    5   NativeTest                          0x00000001011d4e9d -[RCTModuleMethod invokeWithBridge:module:arguments:] + 189
    6   NativeTest                          0x000000010126fd17 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 791
    7   NativeTest                          0x000000010126f823 _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 131
    8   NativeTest                          0x000000010126f799 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25
    9   libdispatch.dylib                   0x00000001020bddd4 _dispatch_call_block_and_release + 12
    10  libdispatch.dylib                   0x00000001020bed48 _dispatch_client_callout + 8
    11  libdispatch.dylib                   0x00000001020ccde6 _dispatch_main_queue_callback_4CF + 1500
    12  CoreFoundation                      0x00007fff23bd4049 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    13  CoreFoundation                      0x00007fff23bceca9 __CFRunLoopRun + 2329
    14  CoreFoundation                      0x00007fff23bce066 CFRunLoopRunSpecific + 438
    15  Foundation                          0x00007fff2576b86f -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 211
    16  Foundation                          0x00007fff2576bae2 -[NSRunLoop(NSRunLoop) runUntilDate:] + 72

解决方案1

升级RN的版本到 0.59.9 或者最新版 0.60.x。

解决方案2

参考官网的修改代码https://github.com/facebook/react-native/pull/25146/files,手动将代码 node_modules/react-native/React/Base/RCTModuleMethod.mmRCTParseUnused 方法,大约在 91 行:

static BOOL RCTParseUnused(const char **input)
{
  return RCTReadString(input, "__unused") ||
         RCTReadString(input, "__attribute__((unused))");
}

修改为:

static BOOL RCTParseUnused(const char **input)
{
  return RCTReadString(input, "__attribute__((unused))") ||
         RCTReadString(input, "__attribute__((__unused__))") ||
         RCTReadString(input, "__unused");
}

重新编译后,运行正常了。

最后更新 2020-03-08
MIP.watch('startSearch', function (newVal, oldVal) { if(newVal) { var keyword = MIP.getData('keyword'); console.log(keyword); // 替换当前历史记录,新增 MIP.viewer.open('/s/' + keyword, {replace: true}); setTimeout(function () { MIP.setData({startSearch: false}) }, 1000); } }); MIP.watch('goHome', function (newVal, oldVal) { MIP.viewer.open('/', {replace: false}); });