Search code examples
iosobjective-cnfccore-nfc

Read and Redirect webpage by NFC tag response in objective c


Im struggled with redirect to webpage after read NFC scan by objective C.

Here is my code

- (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);
        }
    }        
}

Solution

  • I got solution by using VYNFC kit,

    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];
    
           }