【问题标题】:How to Get the Tag Identifier in Core NFC如何在核心 NFC 中获取标签标识符
【发布时间】:2017-08-29 18:55:06
【问题描述】:

如何使用 Core NFC 获取 NFC 标签的 ID(而不是消息负载的 ID)?

我正在寻找与 Android 中存在的此功能类似的东西:https://developer.android.com/reference/android/nfc/Tag.html#getId()

【问题讨论】:

标签: ios swift core-nfc


【解决方案1】:

使用_foundTags 导致拒绝:

1.2 二进制拒绝

指南 2.5.1 - 性能 - 软件要求

您的应用使用或引用以下非公共 API:

_foundTags

App Store 不允许使用非公共 API,因为 如果这些 API 发生变化,可能会导致糟糕的用户体验。

在未来提交的 此应用程序可能会导致您的 Apple Developer 终止 帐户,以及从 App Store 中删除所有相关应用。

接下来的步骤

如果您使用的是第三方库,请更新到最 这些库的最新版本。如果您无权访问 库的源代码,您可以使用 “字符串”或“otool”命令行工具。 “字符串”工具可以 输出库调用的方法列表和“otool -ov” 将输出 Objective-C 类结构及其定义 方法。这些工具可以帮助您缩小问题所在 代码驻留。您还可以使用“nm”工具来验证是否有 第三方库正在调用这些 API。

资源

有关“nm”工具的信息,请查看“nm tool”Xcode 手册页。

如果没有其他方法可以为您的应用提供功能 需要,您可以提交增强请求。

【讨论】:

    【解决方案2】:

    以下是实现它的方法。 但请记住,它使用私有函数,Apple 可以随时删除/更改该函数,并可能导致 AppStore 拒绝。

    在我的应用中测试,它现在适用于 iOs 11.1

    来源:

    https://github.com/hansemannn/iOS11-NFC-Example/issues/16

    https://github.com/chariotsolutions/phonegap-nfc/pull/287/files#diff-84fad93feff6a327c30a08cac8f546dfR171

            func readerSession(_ session: NFCNDEFReaderSession, didDetectNDEFs messages: [NFCNDEFMessage]) {
                let uid : String = getTagIdFromSession(session: session)
                //Do what you want with the UID
    
            }
    
    
            func getTagIdFromSession(session : NFCNDEFReaderSession) -> String{
                var uid: String = ""
                if(session.value(forKey: "_foundTags") != nil) {
                    let foundTags : NSArray = session.value(forKey: "_foundTags") as! NSArray
                    if(foundTags.count > 0) {
                        let tag : NSObject = foundTags.firstObject  as! NSObject;
                        if(tag.value(forKey: "_tagID") != nil) {
                            var uuidPadded : Data = tag.value(forKey: "_tagID") as! Data
                            //We reverse the order
                            for (i,_) in uuidPadded.enumerated() {
                                uuidPadded.insert(uuidPadded.remove(at:i),at:0)
                            }
                            for (_, element) in uuidPadded.enumerated() {
                                let tag : String = String(element, radix:16)
                                //We add the missing 0 in case the number is < 10. It can be done with bitwise operations too.  
                                if(tag.length < 2) {
                                    uid.append("0"+tag)
                                }
                                else {
                                    uid.append(tag)
                                }
    
    
                            }
                        }
                    }
                }
                return uid;
            }
    

    【讨论】:

    • 正如最近的回答中提到的,这将称为应用拒绝。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多