#jayzhuang.

1 messages · Page 1 of 1 (latest)

tender oasisBOT
onyx badge
#

@solar ferry Let's use thread to continue to the discussion

solar ferry
#

hi

#

i have wrapped with dispatchque but has no effect, func terminal(_ terminal: Terminal, didChangeConnectionStatus status: ConnectionStatus) {
print("Connection status changed to:")
DispatchQueue.main.async {
switch status {
case .connected:
print("Debug: connected")

            self.isConnected = true
            self.showReaderView = false


            print(self.isConnected)



        case .connecting:
            print("Debug: connecting")
        case .notConnected:

                self.isConnected = false
                // You might want to set self.showReaderView to true here or handle it according to your logic

            print("Debug: Not connected")
        @unknown default:
            fatalError("")
        }
    }

}
onyx badge
#

my ui change related code won't update , i can print the message on the console Connection status changed to:
Debug: connecting
Connection status changed to:
Debug: connected
true
discoverReaders succeeded but ui didn't updated
What kind of UI update are you referring to?

solar ferry
#

i use published var isConnected : bool make background color changes, if not connected grey color if connected use brighter color

#

func terminal(_ terminal: Terminal, didChangeConnectionStatus status: ConnectionStatus) this func does get called, because i can see messages printed on the console but isConnected isn't updated in my app

onyx badge
#

Since terminal(_ terminal: Terminal, didChangeConnectionStatus status: ConnectionStatus) is called, it means that this function is working. So the problem here seems more like your own variable isn't updated correctly. Am I right?

solar ferry
#

yes,

#

if i place override init() {
super.init()
Terminal.setTokenProvider(self) // Set the token provider
Terminal.shared.delegate = self // Set the terminal delegate
} inside my mvvm class, the UI will get updated everything worked as expected HOWEVER the app will crash after payment is taken

#

import StripeTerminal

class ReaderViewController: UIViewController, TerminalDelegate {
override func viewDidLoad() {
super.viewDidLoad()
Terminal.shared.delegate = self
}

// ...

// MARK: TerminalDelegate

func terminal(_ terminal: Terminal, didReportUnexpectedReaderDisconnect reader: Reader) {
    // Consider displaying a UI to notify the user and start rediscovering readers
}

} , this is from the stripe tutorial it is using uikit as a demostration but i only knows swiftui , i think i didn't follow this part right. please help me

dapper ingot
#

Hi @solar ferry I'm Jack, I'm engineer working in the same team as river

solar ferry
#

hi

dapper ingot
#

So you are trying to bind a state variable in your Swift UI, and you want to update thie variable when didChangeConnectionStatus is called ?

solar ferry
#

yes

#

i used published var variable

dapper ingot
#

OK, can you share with me the relevant swift UI code that you wrote?

solar ferry
#

//
// China_BrasseriesApp.swift
// China Brasseries
//
// Created by Guan Jie Zhuang on 13/06/2021.
//

import SwiftUI
import Firebase
import StripeTerminal
@main
struct China_BrasseriesApp: App {
@UIApplicationDelegateAdaptor(Delegate.self) var delgate
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(OrderViewModel())
.environmentObject(BLEManagerViewModel())
.environmentObject(LoginViewModel())
.environmentObject(ActiveViewModel())
}
}
}

class Delegate: NSObject,UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
// Terminal.setTokenProvider(APIClient.shared)
// Terminal.shared.delegate = APIClient.shared

    // Set the token provider
            Terminal.setTokenProvider(APIClient.shared)
            // Set the terminal delegate
            Terminal.shared.delegate = APIClient.shared
    
    return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    // Needed for phone Auth
}

}

dapper ingot
#

I saw a TakeawayViewModel in StripePaymentView, but I don't see how you use StripeTerminalViewModel in your swiftUI code

solar ferry
#

.background(stripe.isConnected ? createColor(R: 251, G: 255, B: 227) : Color.gray)

solar ferry
dapper ingot
#

@ObservedObject var stripe : APIClient,

stripe is an instance of APIClient, I'm still unable to see any usage of StripeTerminalViewModel

solar ferry
dapper ingot
#

Ok, I don't any code to instantiate the stripe, is it instantiated in another file?

solar ferry
#

class Delegate: NSObject,UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
// Terminal.setTokenProvider(APIClient.shared)
// Terminal.shared.delegate = APIClient.shared

    // Set the token provider
    Terminal.setTokenProvider(APIClient.shared)
    // Set the terminal delegate
    Terminal.shared.delegate = APIClient.shared
    
    return true
}} i have done this when app luanching
dapper ingot
#

I mean this variable
@ObservedObject var stripe : APIClient

stripe is declared, but I don't see where it's instantiated.

solar ferry
#

it is instantiated couple views before , struct HomeView: View {
@StateObject var orderData = OrderViewModel()
@StateObject var tableData = LoginViewModel()
@StateObject var activeData = ActiveViewModel()
@StateObject var blemanager = BLEManagerViewModel()
@StateObject var historyData = HistoryViewModel()
@StateObject var accountdata = AccountingViewModel()
@StateObject var streamTask = MyURLStreamTask()
@StateObject var takeawayData = TakeawayViewModel()
@StateObject var stripeData = APIClient()
@StateObject var udpData = UDPServer()
@StateObject var barcodeData = BarcodeScannerVM()
@StateObject var staffData = StaffViewModel()
@StateObject var pdfviewModel = PDFViewModel()

#

in another file.

#

i created func setupDelegate(){
Terminal.shared.delegate = self
} and on my StripePaymentView.swift and added .onAppear {
stripe.setupDelegate()
} , then my ui can be updated accordingly and the app won't crash after taken the payment. thank you for your advise.