flutter_nfc_kit icon indicating copy to clipboard operation
flutter_nfc_kit copied to clipboard

iOS Background Reading

Open thomasklaush opened this issue 2 years ago • 10 comments

Is it possible to do iOS Background reading?

Meaning reading a tag without the annoying pop-up of the iPhone.

thomasklaush avatar Jan 18 '22 16:01 thomasklaush

I was about to ask this question myself.

Would be a really nice feature and should be possible with the CORENFC library having added this feature lately. Please refer to the following link -> Adding Support for Background Tag Reading

mekjolle avatar Jan 19 '22 07:01 mekjolle

Based on the code

func application(_ application: UIApplication,
                 continue userActivity: NSUserActivity,
                 restorationHandler: @escaping ([Any]?) -> Void) -> Bool {

    guard userActivity.activityType == NSUserActivityTypeBrowsingWeb else {
        return false
    }

    // Confirm that the NSUserActivity object contains a valid NDEF message.
    let ndefMessage = userActivity.ndefMessagePayload
    guard ndefMessage.records.count > 0,
        ndefMessage.records[0].typeNameFormat != .empty else {
            return false
    }

    // Send the message to `MessagesTableViewController` for processing.
    guard let navigationController = window?.rootViewController as? UINavigationController else {
        return false
    }

    navigationController.popToRootViewController(animated: true)
    let messageTableViewController = navigationController.topViewController as? MessagesTableViewController
    messageTableViewController?.addMessage(fromUserActivity: ndefMessage)

    return true
}

I think it can't be fully handled by a FlutterPlugin. Instead you might need to go to the Runner app to read the tag info and do the deep linking yourself as any other universal/deeplinking related scenarios

timnew avatar Jan 20 '22 02:01 timnew

It's something similar to Android's foreground dispatching (#17). In these modes, you do not have to actively call some API to poll a tag. The OS will call your handler instead.

However as a Flutter plugin, it is difficult to act as a handler. You have to add some rather complex native code to your project. So we might not be able to support this easily.

Harry-Chen avatar May 11 '22 04:05 Harry-Chen

I was wondering if anyone has successfully implemented iOS background reading in Flutter. Doing this requires some native code, and it's challenging for me to find any useful resources.

Has anyone progressed on this issue? If so, could you possibly share some directions or even link to a GitHub repository with a Flutter example?

Your insights would be incredibly helpful for those of us looking to implement this feature.

Thank you!

spehj avatar Sep 04 '23 13:09 spehj

I was wondering if anyone has successfully implemented iOS background reading in Flutter. Doing this requires some native code, and it's challenging for me to find any useful resources.

Has anyone progressed on this issue? If so, could you possibly share some directions or even link to a GitHub repository with a Flutter example?

Your insights would be incredibly helpful for those of us looking to implement this feature.

Thank you!

I'd be interested in this as well as we're trying to achieve background NFC scanning on iOS for a customer-specific feature.

plut9 avatar Sep 05 '23 06:09 plut9

Need this too! I'm very surprised this doesn't exist yet.

zigapovhe avatar Sep 07 '23 07:09 zigapovhe

Hi everyone. Any development on this item?

HenriqueMatias avatar Apr 01 '24 23:04 HenriqueMatias

Hi everyone. Any development on this item?

I had to implement it on my own. I wrote some iOS native code and used method channels.

spehj avatar Apr 02 '24 06:04 spehj

Hey @spehj thank you for the hint. So did you fork the project or you wrote the code from scratch?

HenriqueMatias avatar Apr 07 '24 18:04 HenriqueMatias

@HenriqueMatias I wrote it from scratch in AppDelegate.swift

spehj avatar Apr 07 '24 18:04 spehj