CoreNFC debug not working

给你一囗甜甜゛ 提交于 2019-12-07 09:11:58

问题


How programmatically work CoreNFC on xcode-9

func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
    //What I need to do here
}

func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
    //What I need to do here
}

override func viewDidLoad() {
    super.viewDidLoad()

    let sessionReader = NFCNDEFReaderSession.init(delegate: self, queue: nil, invalidateAfterFirstRead: true)
    let nfcSession = NFCReaderSession.self

    let nfcTag = NFCTagCommandConfiguration.init()
    let tagType = NFCTagType(rawValue: 0)

    sessionReader.begin()

}

I want to know what I need to do for read some NFC tag.


回答1:


There are four steps to get it working:

  1. Add the NFC Tag permission to your App Identifier in the Apple developer portal

  1. Add a Code Signing Entitlement file to your project and build settings and add the following raw key and value:

  1. Add the usage description to your Info.plist:

  1. Implement the delegate and pass it to the NFCNDEFReaderSession init like this:

    import UIKit
    import CoreNFC
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate, NFCNDEFReaderSessionDelegate {
    
        var window: UIWindow?
        var session: NFCNDEFReaderSession?
    
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            session = NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: false)
            self.session?.begin()
            return true
        }
    
        func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
            print(error)
        }
    
        func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
            print(messages)
        }
    
    }
    


来源:https://stackoverflow.com/questions/44390251/corenfc-debug-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!