iOS Question NFC Tag Reading in Background

walterf25

Expert
Licensed User
Longtime User
Hi all, according to the NFC Core documentation for xcode 13, it is possible to enable NFC Tag reading in the Background.
https://developer.apple.com/documen...port_for_background_tag_reading?language=objc
Would it be possible to implement this with B4i and native objective C?

Does anyone have any idea, I followed @Erel 's latests NFC Example with complies with xcode 13 and it works fine, but I would like to see if the background tag reading can be implemented as well?

Thanks,
Walter
 

walterf25

Expert
Licensed User
Longtime User
Note that most devices do not support this feature. It is only supported by iPhone XS+ devices.

If you have such device I can help you implement this feature.
Hi Erel, yes I do have an iPhone XS, how would I implement this feature?

Thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Start with these instructions:
1. Add the associated domains capability and download and update provision profile:

firefox_N4fEcyoU7i.png


2. Based on the NFCExtra example. Add this line:
B4X:
#Entitlement: <key>com.apple.developer.associated-domains</key><array><string>applinks:b4x.com</string></array>
3. Create an NFC tag with URL data (you can use this: https://www.b4x.com/android/forum/threads/nfcex-class-write-ndef-tags.110726/#post-692860). Set the link to https://www.b4x.com

4. Add this at the end of the main module:
B4X:
#if OBJC
@end
@implementation B4IAppDelegate (nfc)
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
   restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *restorableObjects))restorationHandler {
   NSLog(@"continueUserActivity");
   if (userActivity.activityType != NSUserActivityTypeBrowsingWeb)
       return false;
   B4I* bi = [b4i_main new].bi;
   [bi raiseEvent:nil event:@"application_nfc:" params:@[userActivity.ndefMessagePayload]];
   return true;
}
#End If

5. Run your app in debug mode, move it to the background and try to scan. Do you see the 'continueUserActivity' message in the logs?
 
Last edited by a moderator:
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Start with these instructions:
1. Add the associated domains capability and download and update provision profile:

firefox_N4fEcyoU7i.png


2. Based on the NFCExtra example. Add this line:
B4X:
#Entitlement: <key>com.apple.developer.associated-domains</key><array><string>applinks:b4x.com</string></array>
3. Create an NFC tag with URL data (you can use this: https://www.b4x.com/android/forum/threads/nfcex-class-write-ndef-tags.110726/#post-692860). Set the link to https://www.b4x.com

4. Add this at the end of the main module:
B4X:
#if OBJC
@end
@implementation B4IAppDelegate (nfc)
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
   restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *restorableObjects))restorationHandler {
   NSLog(@"continueUserActivity");
   if (userActivity.activityType != NSUserActivityTypeBrowsingWeb)
       return false;
   B4I* bi = [b4i_main new].bi;
   [bi raiseEvent:nil event:@"application_nfc:" params:@[userActivity.ndefMessagePayload]];
   return true;
}
#End If

5. Run your app in debug mode, move it to the background and try to scan. Do you see the 'continueUserActivity' message in the logs?
Great, I will give it a try today and will let you know, you're the man Erel.

Walter
 
Upvote 0
Top