CoreNFC 调试不工作
CoreNFC debug not working
如何以编程方式在 xcode-9
上运行 CoreNFC
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()
}
我想知道我需要做什么才能读取一些 NFC 标签。
需要四个步骤才能使其正常工作:
- 在 Apple 开发者门户中将 NFC 标签权限添加到您的 App Identifier
- 将代码签名授权文件添加到您的项目和构建设置,并添加以下原始键和值:
- 将使用说明添加到您的 Info.plist:
实现委托并将其传递给 NFCNDEFReaderSession
init,如下所示:
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)
}
}
如何以编程方式在 xcode-9
上运行 CoreNFCfunc 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()
}
我想知道我需要做什么才能读取一些 NFC 标签。
需要四个步骤才能使其正常工作:
- 在 Apple 开发者门户中将 NFC 标签权限添加到您的 App Identifier
- 将代码签名授权文件添加到您的项目和构建设置,并添加以下原始键和值:
- 将使用说明添加到您的 Info.plist:
实现委托并将其传递给
NFCNDEFReaderSession
init,如下所示: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) } }