CoreNFC debug not working

蹲街弑〆低调 提交于 2019-12-05 17:39:07
Jens Meder

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