Thursday, October 29, 2026
HomeiOS Developmentios - Apple Pay displaying however don't work on contact. Solely works...

ios – Apple Pay displaying however don’t work on contact. Solely works when lengthy pressed. SwiftUI

[ad_1]

I’ve an analogous challenge to this query Apple iOS Tutorial: Issues getting UIButton addTarget to Work.

Nevertheless, my challenge is completely different in that I’ve two buttons in a vStack, an Apple Pay button on high and add to bag on backside. Once I press Apple Pay it used to work flawlessly. However out of the blue with none modifications to code or iOS, the button stoped engaged on contact. Nevertheless, it nonetheless works on lengthy press solely. The add to bag button works with none points. enter picture description right here

extension ApplePaymentButton {
#if os(iOS)
typealias ViewRepresentable = UIViewRepresentable
#else
typealias ViewRepresentable = NSViewRepresentable
#endif

struct Representable: ViewRepresentable {
    var motion: () -> Void
    
    init(motion: @escaping () -> Void) {
        self.motion = motion
    }
    
    func makeCoordinator() -> Coordinator {
        Coordinator(motion: motion)
    }
    
    #if os(iOS)
    func makeUIView(context: Context) -> UIView {
        context.coordinator.button
    }
    
    func updateUIView(_ rootView: UIView, context: Context) {
        context.coordinator.motion = motion
    }
    #else
    func makeNSView(context: Context) -> NSView {
        context.coordinator.button
    }
    
    func updateNSView(_ rootView: NSView, context: Context) {
        context.coordinator.motion = motion
    }
    #endif
}

class Coordinator: NSObject {
    
    var motion: () -> Void
    var button = PKPaymentButton(paymentButtonType: .purchase, paymentButtonStyle: .automated)
    
    init(motion: @escaping () -> Void) {
        self.motion = motion
        tremendous.init()
        #if os(iOS)
        button.addTarget(self, motion: #selector(callback(_:)), for: .touchUpInside)
        #else
        button.motion = #selector(callback(_:))
        button.goal = self
        #endif
    }
    
    @objc
    func callback(_ sender: Any) {
        motion()
    }
}

after I remark this code: button.addTarget(self, motion: #selector(callback(_:)), for: .touchUpInside), the button stops working even on lengthy press.

I recognize your assist on this challenge Since this app is in manufacturing.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments