Here is my write NDEF message code:
let readerWriter = NFCReaderWriter.sharedInstance()
let payloadData = NFCNDEFPayload(format: .nfcWellKnown, type: "U".data(using: .utf8)!, identifier: Data(), payload: "google.com".data(using: .utf8)!)
let message = NFCNDEFMessage(records: [payloadData])
readerWriter.write(message, to: tags.first!) { (error) in
if let err = error {
print("ERR:\(err)")
} else {
print("write success")
}
self.readerWriter.end()
}
First Issue:
When I want to read the NFC chip in the background without opening the app, I find the detection speed is not ideal. For example, this code writes "google.com" this time. When performing background reading, it does not successfully read every time the chip is near, and there seems to be a one-minute interval.
Second Issue:
When I implemented this method in the AppDelegate:
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
if (![userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
return NO;
}
NSLog(@"userActivity: %@", userActivity.ndefMessagePayload);
if (userActivity.ndefMessagePayload) {
return YES;
}
return NO;
}
I found that userActivity.ndefMessagePayload outputs null. At the same time, looking at its private variables, it seems to have values:
Printing description of userActivity->_internal->_payloadDataCache:
{
"com.apple.corenfc.useractivity.ndefmessagepayload" = {length = 546, bytes = 0x62706c69 73743030 d4010203 04050607 ... 00000000 0000019c };
}
If ndefMessagePayload is null, how can I determine that it is an NSUserActivity from an NFC scan?