如何为PKPaymentButton创建包装器

问题描述 投票:0回答:1

我正在尝试在SwiftUI中实现PKPaymentButton,但是我不知道如何为PKPaymentButton创建包装器。我的代码如下:

struct ApplePayButton: UIViewRepresentable {

    func makeUIViewController(context: Context) -> PKPaymentButton {
        return PKPaymentButton.init()
    }

    func updateUIView(_ uiView: ApplePayButton.UIViewType, context: UIViewRepresentableContext<ApplePayButton>) {
        //
    }
}

我遇到以下错误:

  • 参考类型为'ApplePayButton'的无效关联类型'UIViewType']
  • 类型'ApplePayButton'不符合协议'UIViewRepresentable'

有人能做到这一点,还是有人能更好地在SwiftUI中实现Apple Pay?

swift wrapper swiftui applepay uiviewrepresentable
1个回答
0
投票

声明应类似于以下内容:

import SwiftUI
import UIKit
import PassKit

struct ApplePayButton: UIViewRepresentable {


    func makeUIView(context: Context) -> PKPaymentButton {
        return PKPaymentButton()
    }

    func updateUIView(_ uiView: PKPaymentButton, 
                 context: UIViewRepresentableContext<ApplePayButton>) {
        //
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.