gpt4 book ai didi

iphone - dyld : Library not loaded: @rpath/CoreNFC. 框架/CoreNFC、iOS11 和 Xcode 9 测试版

转载 作者:搜寻专家 更新时间:2023-10-31 08:22:08 26 4
gpt4 key购买 nike

我在 Xcode 9.0 beta 2 中运行 CoreNFC 示例 代码时遇到此错误并且应用程序崩溃

dyld: Library not loaded: @rpath/CoreNFC.framework/CoreNFC
Referenced from: /var/containers/Bundle/Application/2837709C-C852-4811-B696-38F2725554D4/iOS-11-by-Examples.app/iOS-11-by-Examples
Reason: image not found

有人知道如何解决这个问题吗?

最佳答案

感谢@Chinchan Zu 的评论,我结合了一些答案来解决这个问题

here is how to mark Core NFC as Optional stackoverflow question

首先,您在“链接的框架和库”中将导入 NFCCore 作为可选,如此屏幕截图所示 linking nfcCore as optional

然后在您的代码中用这个#if 检查包装您的代码。这是我使用的类

#if canImport(CoreNFC)

import Foundation
import CoreNFC

#endif

class NFCManagar: NSObject {
#if canImport(CoreNFC)
var session: NFCNDEFReaderSession?
#endif

var items = [Item]()
var completion: ((_ success: Bool, _ error: Error?)-> Void)?

func beginScanning(items: [Item], completion: @escaping (_ success: Bool, _ error: Error?)-> Void) {
self.completion = completion
self.items.removeAll()
self.items.append(contentsOf: items)

#if canImport(CoreNFC)
session = NFCNDEFReaderSession(delegate: self, queue: nil, invalidateAfterFirstRead: true)
session?.alertMessage = "Hold your iPhone near check in/out device."
session?.begin()
#endif
}

}

#if canImport(CoreNFC)
extension NFCManagar: NFCNDEFReaderSessionDelegate {

// MARK: - NFCNDEFReaderSessionDelegate

/// - Tag: processingTagData
func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
debugPrint("Nfc is detected")
}

/// - Tag: endScanning
func readerSession(_ session: NFCNDEFReaderSession, didInvalidateWithError error: Error) {
// Check the invalidation reason from the returned error.
if let readerError = error as? NFCReaderError {
// Show an alert when the invalidation reason is not because of a success read
// during a single tag read mode, or user canceled a multi-tag read mode session
// from the UI or programmatically using the invalidate method call.
if (readerError.code != .readerSessionInvalidationErrorFirstNDEFTagRead)
&& (readerError.code != .readerSessionInvalidationErrorUserCanceled) {

debugPrint("Nfc didInvalidateWithError \(error)")
}
}

// A new session instance is required to read new tags.
self.session = nil
}
}
#endif

关于iphone - dyld : Library not loaded: @rpath/CoreNFC. 框架/CoreNFC、iOS11 和 Xcode 9 测试版,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44946057/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com