iOS 中的 Ionic、phonegap nfc 异常

Ionic, phonegap nfc Exception in iOS

我正在开发一个读取 nfc 标签的 Ionic 应用程序。但是当我 运行 它在 iOS 时,我从 nfc 标签得到结果,但在那之后我得到 NSExcetion。

这是我尝试读取 NFC 标签的代码部分:

if(this.platform.is("ios")) {
      this.nfc.beginSession().subscribe(() => {
        this.nfc.addNdefListener((data) => {
          console.log("IOS: ",data) // You will not see this, at this point the app will crash
        })
      });  
  }

我从来没有得到 console.log !!!!!

这些是我在 Xcode(版本 9.2)中遇到的错误:

2018-02-01 09:06:57.987510-0500 androidSDK[1819:852595]   readerSessionDidBecomeActive
2018-02-01 09:07:03.035369-0500 androidSDK[1819:852705] NFCNDEFReaderSession didDetectNDEFs
2018-02-01 09:07:03.035641-0500 androidSDK[1819:852705] {"ndefMessage":[{"tnf":1,"id":[],"payload":[2,101,110,72,101,108,108,111,46,33],"type":[84]},{"tnf":1,"id":[],"payload":[2,101,110,72,101,108,108,111,32,119,111,114,108,100,33,32],"type":[84]}]}
2018-02-01 09:07:03.035975-0500 androidSDK[1819:852430] -[WKWebView stringByEvaluatingJavaScriptFromString:]: unrecognized selector sent to instance 0x15e046200
2018-02-01 09:07:03.036619-0500 androidSDK[1819:852430] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WKWebView stringByEvaluatingJavaScriptFromString:]: unrecognized selector sent to instance 0x15e046200'
*** First throw call stack:
(0x18121b164 0x180464528 0x181228628 0x18ab933c8 0x181220b10 0x181105ccc 0x104b74880 0x105cfd2cc 0x105cfd28c 0x105d01ea0 0x1811c3344 0x1811c0f20 0x1810e0c58 0x182f8af84 0x18a836804 0x104b2b1cc 0x180c0056c)
libc++abi.dylib: terminating with uncaught exception of type NSException
2018-02-01 09:07:03.036798-0500 androidSDK[1819:852705] didInvalidateWithError Single tag read (null)

问题出在插件上,它只适用于 UIWebView,但您使用的是 WKWebView,所以this line 失败

[(UIWebView*)[self webView] stringByEvaluatingJavaScriptFromString: function];

有一个 pull request 可用于解决此问题,因此请点击“赞”按钮,这样它可能会被考虑并合并,或者改用叉子。