Reason:TypeError
Error name:TypeError
Error message:Cannot read property unregisterForegroundDispatch of undefined
Stacktrace:
Cannot get SourceMap info, dump raw stack:
at unRegister (phone|phone|1.0.0|src/main/ets/utils/NFCUtil.ts:52:1)
at onWebPageAboutToDisappear (phone|phone|1.0.0|src/main/ets/scenes/webview/jshandler/JsMsgNFCHandler.ts:110:1)
at anonymous (phone|phone|1.0.0|src/main/ets/scenes/webview/jshandler/JsManager.ts:130:1)
at webPageDestroyEventDispatch (phone|phone|1.0.0|src/main/ets/scenes/webview/jshandler/JsManager.ts:130:1)
at webPageAboutToDisappear (phone|phone|1.0.0|src/main/ets/scenes/webview/jshandler/JsProxy.ts:34:1)
at aboutToDisappear (phone|phone|1.0.0|src/main/ets/scenes/webview/pages/WebViewPage.ts:211:1) 使用canIUse("SystemCapability.Communication.NFC.Core")判断设备是否支持NFC能力,详情可见NFC标签读写开发指南。
@Entry
@Component
struct CheckNFCAbilityPage {
@State nfcSupport: boolean = false;
aboutToAppear(): void {
this.checkNfcCapability();
}
// 检查设备是否支持NFC能力
checkNfcCapability() {
if (canIUse('SystemCapability.Communication.NFC.Core')) {
this.nfcSupport = true;
console.info('该设备支持NFC功能');
} else {
this.nfcSupport = false;
console.info('该设备不支持NFC功能');
}
}
build() {
Column() {
if (!this.nfcSupport) {
// 设备不支持NFC的情况
Text('当前设备不支持NFC功能')
.fontSize(20)
.fontColor(Color.Red)
} else {
Text('当前设备支持NFC功能')
.fontSize(20)
.fontColor(Color.Red)
}
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Center)
}
}