如何在我的应用程序中使用NFC模块打开门?

时间:2018-11-14 15:02:01

标签: ios xcode nfc

我必须使用手机通过NFC模块解锁门。我拿出了要打开的特殊钥匙号,但是如何通过我的应用程序使用此特殊代码来解锁门呢?

我的代码:

- (IBAction)scna:(id)sender {
    self.session = [[NFCNDEFReaderSession alloc] initWithDelegate:self queue:dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT) invalidateAfterFirstRead:NO];
    [self.session beginSession];
}

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

    for (NFCNDEFMessage *message in messages) {
        for (NFCNDEFPayload *payload in message.records) {
            NSLog(@"Payload: %@", payload);
            const NSDate *date = [NSDate date];
            dispatch_async(dispatch_get_main_queue(), ^{
                NSString *string = [NSString stringWithFormat:
                                 @"[%@] Identifier: %@ (%@)\n"
                                 @"[%@] Type: %@ (%@)\n"
                                 @"[%@] Format: %d\n"
                                 @"[%@] Payload: %@ (%@)",
                                 date,
                                 payload.identifier,
                                 [[NSString alloc] initWithData:payload.identifier
                                                       encoding:NSASCIIStringEncoding],
                                 date,
                                 payload.type,
                                 [[NSString alloc] initWithData:payload.type
                                                       encoding:NSASCIIStringEncoding],
                                 date,
                                 payload.typeNameFormat,
                                 date,
                                 payload.payload,
                                 [[NSString alloc] initWithData:payload.payload
                                                       encoding:NSASCIIStringEncoding]];

                [UIAlertController alertControllerWithTitle:@"Title" message:[NSString stringWithFormat:@"%@",string] preferredStyle:UIAlertControllerStyleAlert];

            });
        }
    }
}

此代码非常适合读取数据,但我需要编写。例如,如果我选择可以通过电话付款的信用卡,则我需要使用同一张卡但需要自定义。

0 个答案:

没有答案