NFC NDEF关于IOS编码的写作 [英] NFC NDEF writing on IOS Encoding

查看:554
本文介绍了NFC NDEF关于IOS编码的写作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款可读写NFC标签的Flutter应用程序.在Android上运行正常.现在,我正在努力在IOS上实现NFC编写.

I am working on a flutter app which reads and writes to NFC-tags. On Android it works just fine. Now I am working on implementing NFC-writing on IOS since it is now available.

我确实获得了将文本记录写入标签的应用程序.但是不知何故,它是以UTF16编写的,这使事情分崩离析.

I do get the app to write a text-record to the tag. But somehow it is written in UTF16 which makes things break apart.

如何使用UTF-8编码的字符串创建NFCNDEFPayload.wellKnownTypeTextPayload?

How do I create NFCNDEFPayload.wellKnownTypeTextPayload with a string that is UTF-8 encoded??

推荐答案

您已掌握了大部分方法.这是一个完整的工作示例,它修复了几处问题(特别是缺少类型"说明符和语言环境的使用):

You got most of the way there. Here's a full working example which fixes a couple things (specifically missing 'type' specifier and locale usage):

var payloadData = Data([0x02,0x65,0x6E]) // 0x02 + 'en' = Locale Specifier
payloadData.append("Text To Write".data(using: .utf8)!)

let payload = NFCNDEFPayload.init(
    format: NFCTypeNameFormat.nfcWellKnown,
    type: "T".data(using: .utf8)!,
    identifier: Data.init(count: 0),
    payload: payloadData,
    chunkSize: 0)

请注意,这会将语言环境设置为'en'.

Note that this sets the locale to 'en'.

我已经在iPhone和Android上测试了使用此代码创建的标签,并且看起来工作正常.

I've tested tags created with this code on both iPhone and Android, and it seems to be working fine.

这篇关于NFC NDEF关于IOS编码的写作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆