gpt4 book ai didi

ios - 缺少 NFCTagReaderSession 所需的权利

转载 作者:行者123 更新时间:2023-11-29 05:24:26 26 4
gpt4 key购买 nike

我尝试使用 ISO7816 通过 corenfc 启动通信,但我总是遇到相同的错误,即使我尝试了互联网上发布的多个请求。

代码是

@IBAction func scanPressed(_ sender: Any) {
nfcSession = NFCTagReaderSession.init(pollingOption: .iso14443, delegate: self)
nfcSession?.alertMessage = "Hold your IPhone near the ISO7816 tag to begin transaction.";
nfcSession?.begin()
}

我的 info.plist 是

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
<string>D2760000850101</string>
</array>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>NDEF</string>
<string>TAG</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NFCReaderUsageDescription</key>
<string>Message in a Card</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
<string>nfc</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

出现以下错误

The session was invalidated: Error Domain=NFCError Code=2 "Missing required entitlement" UserInfo={NSLocalizedDescription=Missing required entitlement}

如何解决?

最佳答案

您的权利应位于名为 NFCTagReaders.entitlements 的文件中,并且应包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.nfc.readersession.formats</key>
<array>
<string>NDEF</string>
<string>TAG</string>
</array>
</dict>

我不确定为什么在你的情况下它包含在主 Info.plist 文件中。这可能与您的问题有关,因为您的配置看起来是正确的。

Info.plist 和 NFCTagReaders.entitlements 文件:

screenshot Info.plist and NFCTagReaders.entitlements files

另请检查项目配置中是否已激活 NFC 功能。

您还应该在开始 session 之前通过添加以下行来检查 NFC session 是否可用:

guard NFCTagReaderSession.readingAvailable else {
print("NFC Session not available")
return
}

关于ios - 缺少 NFCTagReaderSession 所需的权利,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58323210/

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