開發(fā)語言:objective-c
問題描述:
使用 wakdev 的 NFC工具-iOS即NFC Tools 讀取標簽中自己寫入的 NDEF 數(shù)據(jù)庵芭,缺少"類型"說明符和語言環(huán)境的使用情況
原代碼:
NSString *type = @"Q";
NSData *typeData = [type dataUsingEncoding:NSUTF8StringEncoding];
NSString *identifier = @"123456789";
NSData *identifierData = [identifier dataUsingEncoding:NSUTF8StringEncoding];
NSString *payload1 = @"Hello World!";
NSData *payloadData1 = [payload1 dataUsingEncoding:NSUTF8StringEncoding];
if (@available(iOS 13.0, *)) {
NFCNDEFPayload *NDEFPayload1=[[NFCNDEFPayload alloc]initWithFormat:NFCTypeNameFormatNFCWellKnown type:typeData identifier:identifierData payload:payloadData1];
NFCNDEFMessage *essage = [[NFCNDEFMessage alloc]initWithNDEFRecords:@[NDEFPayload1]];
}
查資料看到一個答案叛本,不過是用Swift寫的
var payloadData = Data([0x02,0x65,0x6E]) // 0x02 +'en'=區(qū)域說明符知染;0x7a,0x68 = 'zh';0x65,0x6e = 'en'
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)
通過以下網(wǎng)站可查詢十六進制碼對應(yīng)的字符:
ASCII碼表在線查詢
https://www.litefeel.com/tools/ascii.php
修改后的代碼
NSString *type = @"Q";
NSData *typeData = [type dataUsingEncoding:NSUTF8StringEncoding];
NSString *identifier = @"123456789";
NSData *identifierData = [identifier dataUsingEncoding:NSUTF8StringEncoding];
NSString *payload1 = @"Hello World!";
NSData *payloadData1 = [payload1 dataUsingEncoding:NSUTF8StringEncoding];
Byte byte[] = {0x02,0x65,0x6E};
NSData *areaSpecifierData = [NSData dataWithBytes:byte length:3];
NSMutableData *payloadData = [[NSMutableData alloc] initWithData:areaSpecifierData];
[payloadData appendData:payloadData1];
if (@available(iOS 13.0, *)) {
NFCNDEFPayload *NDEFPayload1 = [[NFCNDEFPayload alloc]initWithFormat:NFCTypeNameFormatNFCWellKnown type:typeData identifier:identifierData payload:payloadData];
NFCNDEFMessage *essage = [[NFCNDEFMessage alloc]initWithNDEFRecords:@[NDEFPayload1]];
}
有不對的地方括蝠,還請大家指正