stripe / stripe-terminal-ios

Stripe Terminal iOS SDK
https://stripe.com/docs/terminal/sdk/ios
Other
104 stars 64 forks source link

Terminal.shared.disconnectReader doesn't work when app is about to go in the background or terminate #330

Open harsh7703 opened 2 weeks ago

harsh7703 commented 2 weeks ago
## Summary I want to disconnect the reader when the app is supposed to go in the background state or let's say it is about to terminate. This same code works when the app is foreground but does not work when the app is about to switch its state. ## Code to reproduce ``` NotificationCenter.default.addObserver(self, selector: #selector(appWillEnterBackground), name: UIApplication.willResignActiveNotification, object: nil) func appWillEnterBackground() { Terminal.shared.disconnectReader { error in if let error = error { print("Disconnect failed: \(error)") } else { print("--------------- Disconnected --------------") } } } ``` ## iOS version 18.0.1 ## Installation method Cocoapods ## SDK version 3.9.1 ## Other information
bric-stripe commented 2 weeks ago

@harsh7703 some questions to help us:

  1. what reader type are you seeing this with?
  2. can you clarify the "does not work" state?
    • Are you seeing an error returned from disconnectReader? if so, what error?
    • or is it not calling your completion block? if so, does it call it when the app becomes active again?
harsh7703 commented 2 weeks ago

@bric-stripe - Hi Ans 1: DeviceType: Stripe S700 Ans 2: I have already clarified in my question does not work state in as again under:- ~ I want to disconnect the reader when the app is supposed to go in the background state or let's say it is about to terminate state. This same code works when the app is foreground but does not work when the app is about to switch its background and terminated state. DisconnectFrom reader does not work not called completionblock. It is supposed to call before when applicationDidEnterBackground State. Terminal.shared.disconnectReader { error in if let error = error { print("Disconnect failed: (error)") } else { print("--------------- Disconnected --------------") } }

harsh7703 commented 5 days ago

@bric-stripe - any update on this it would be fruitful for us to communicate with our clients using this device type?

harsh7703 commented 3 days ago

@bric-stripe -I have updated the SDK to version 4.0.0, but I am still encountering the same issue. Below is the error code that might help identify the root cause. This issue is blocking the release of the new app version, so I would appreciate your assistance in resolving it as soon as possible.

collectPaymentMethod failed: Error Domain=com.stripe-terminal Code=2020 "The command was canceled." UserInfo={NSLocalizedDescription=The command was canceled., com.stripe-terminal:Message=The command was canceled.} errorCode::2020

bric-stripe commented 1 day ago

Hi, I'm investigating the disconnect issue as reported but can you clarify when you're seeing a collectPaymentMethod cancel error? Is it related to the original issue?

Canceled collectPaymentMethod is expected if cancel is requested on the cancelable or the user cancels on the reader. Could you provide a serial number for a reader where you're hitting this? And for the collectPaymentMethod issue can you provide a PaymentIntent ID so I can try to find some additional logging/timing to help me investigate / understand the problem.

bric-stripe commented 1 day ago

I've been unable to reproduce any issues disconnecting when going in to the background. Can you reproduce this with our repo's Example app? I added this simple diff to try to repro:

this is added at the end of AppDelegate.swift


+        NotificationCenter.default.addObserver(self, selector: #selector(appWillEnterBackground), name: UIApplication.willResignActiveNotification, object: nil)
+
         return true
     }

+    @objc
+    func appWillEnterBackground() {
+
+        disconnectLogger.error("---------------- Disconnecting -----")
+        Terminal.shared.disconnectReader { error in
+            if let error = error {
+                self.disconnectLogger.error("------------------ Disconnect failed: \(error)")
+            } else {
+                self.disconnectLogger.error("--------------- Disconnected Successfully --------------")
+            }
+        }
+    }

when an sPOS reader is connected I've only seen successful disconnects. Only error I've seen is when backgrounding and no reader is connected, but that's expected.