I am attempting to get PKAddPasses to work on SwiftUI. With my code provided, I am able to get the add pass screen to show up. When pressing "Add", the pass gets added to the Wallet. However, neither the "Add" nor the "Cancel" button make the view disappear.
struct PassKit: UIViewControllerRepresentable {
var pass: PKPass
func makeUIViewController(context: Context) -> PKAddPassesViewController {
let passvc = PKAddPassesViewController(pass: self.pass)
return passvc!
}
func updateUIViewController(_ uiViewController: PKAddPassesViewController, context: Context) {
}
}
Passing a PKPass to the pass variable successfully gets the screen to appear. However, I can not make it disappear and I have tried this as a last ditch resort.
struct PassKit: UIViewControllerRepresentable {
@Binding var done: Bool
var pass: PKPass
class Coordinator: NSObject, PKAddPassesViewControllerDelegate {
var parent: PassKit
init(_ parent: PassKit) {
self.parent = parent
}
func addPassesViewControllerDidFinish(_ controller: PKAddPassesViewController) {
parent.done = false
}
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
func makeUIViewController(context: Context) -> PKAddPassesViewController {
let passvc = PKAddPassesViewController(pass: self.pass)
passvc?.delegate = context.coordinator
return passvc!
}
func updateUIViewController(_ uiViewController: PKAddPassesViewController, context: Context) {
}
}
The idea would be to bind the done boolean and when the its true, it would trigger a disappearing action.
NavigationLink(
destination:
PassKit(done: self.$PassKitDone.onChange({ done in
self.PassKitPresent = false
}))
.ignoresSafeArea()
.navigationBarHidden(true),
isActive: $PassKitPresent,
label: {})
This is the SwiftUI code to to go back to the navigation link.