Reputation: 41
I've been trying several links to download pkpass from server but whenever i download it it shows me the size of file "0 kb", due to this i cannot convert it to pkpass data. is there any other way for dynamic pkpass ? or some other way to download and load it to wallet ?
is it doing because pkpass contain certificates and private information thats why it's not downloading ?
I cannot find any way to integrate dynamic pkpass in app using swift 4.2 or above.
the links I've been using but none of it works
-> Downloading PKPass in an iOS custom app from my server
-> Unable to add Pass to Apple Wallet
-> open .pkpass file from Wallet using share extension iOS
Upvotes: 2
Views: 1268
Reputation: 41
Finally got a solution to get pkpass from server by: -> simply get base64 string from api response -> convert that base64 to to Data like this below
private func convertBase64ToData (base64Str:String) -> Void {
let data = Data(base64Encoded: base64Str, options: .ignoreUnknownCharacters)
openPkPassDataFile(passData: data!)
}
-> then convert Data to PKPass like this below
private func openPkPassDataFile(passData:Data) -> Void{
let pass = try? PKPass(data: passData)
let passLibrary = PKPassLibrary()
if passLibrary.containsPass(pass!) {
print("This pass already added in wallet. Thanks!")
} else {
let pkvc = PKAddPassesViewController(pass: pass!)
pkvc!.delegate = self
self.present(pkvc!, animated: true, completion: {() -> Void in
})
}
}
Note: add import PassKit and PKAddPassesViewControllerDelegate in your controller.
Upvotes: 2