要先在info加入NFC的權限後,判斷機行是否可以使用NFC
static let shared = CoreNFCManager()
private var session: NFCNDEFReaderSession?
func isSupportNFC () {
if NFCNDEFReaderSession.readingAvailable {
// 支援 NFC,iPhone 7 以後機型
CoreNFCManager.shared.session = NFCNDEFReaderSession(delegate: self,
queue: nil,
invalidateAfterFirstRead: false)
CoreNFCManager.shared.session?.alertMessage = "將您的 iPhone 靠近該商品以了解有關它的更多信息"
CoreNFCManager.shared.session?.begin()
}
}
func scanNFC() {
guard NFCNDEFReaderSession.readingAvailable else {
print("NFC 掃描不可用")
return
}
session = NFCNDEFReaderSession(delegate: self, queue: .main, invalidateAfterFirstRead: false)
session?.begin()
}
```
接下來就可以掃描,我們明天再把值接出來