通过目标c中的NFC标记响应来读取和重定向网页

时间:2018-03-14 12:17:12

标签: ios objective-c nfc core-nfc

在目标C阅读NFC扫描后,我很难重定向到网页。

这是我的代码

- (void) readerSession:(nonnull NFCNDEFReaderSession *)session didDetectNDEFs:(nonnull NSArray<NFCNDEFMessage *> *)messages {

    for (NFCNDEFMessage *message in messages) {
        for (NFCNDEFPayload *payload in message.records) {
            NSLog(@"Payload data:%@",payload.payload);
        }
    }        
}

1 个答案:

答案 0 :(得分:1)

我使用VYNFC套件获得了解决方案,

https://github.com/vinceyuan/VYNFCKit

if ([parsedPayload isKindOfClass:[VYNFCNDEFURIPayload class]]) {
         text = @"[URI payload]\n";
         text = [NSString stringWithFormat:@"%@%@", text, ((VYNFCNDEFURIPayload *)parsedPayload).URIString];
         urlString = ((VYNFCNDEFURIPayload *)parsedPayload).URIString;
          NSURL *url = [NSURL URLWithString:urlString];
          NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
          [_webview loadRequest:requestObj];

       }