【发布时间】:2018-07-11 22:03:11
【问题描述】:
我正在开发一个读取 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)
- 离子版本:3.19.1
- iOS平台版本:4.5.4
- 科尔多瓦版本:8.0.0
- Phonegap-nfc 插件:phonegap-nfc 0.7.1 "NFC"
【问题讨论】:
-
您是否尝试为failure argument of addNdefListender 添加回调函数?我还建议在您的 beginSession 订阅中放置一个错误处理程序,以确保会话正在启动(检查 this 以了解 RxJS 的错误处理)。
-
将 besinSession 更改为 this.nfc.beginSession( (succuss) => { console.log("Success"); }, (fail) => { console.log("Fail"); } ) 我没有得到控制台日志!!!!
-
你是如何运行应用程序的?
-
让 Ionic cordova 准备 iOS,然后我从 XCode 运行项目。
-
尝试在您的离子项目根目录下的终端中使用
ionic cordova run -c ios。-c将在终端打印出控制台语句
标签: ios cordova ionic-framework nfc phonegap