Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passbook , showing an .pass in an app

Tags:

swift

passkit

All, I have been reading from Apple documentation and I have found info to show bits of a pass and changing a pass in an app. But is there a way the .pass zip can be stored in XCODE and shown in a pop up view controller ?

I have figured this out, but I doesnt work.

Any advice ??

var pkfile : NSData = NSData(contentsOfFile: "Event.pkpass")!
        var pass : PKPass = PKPass(data: pkfile, error: nil)
        let vc = PKAddPassesViewController(pass: pass)
        self.presentViewController(vc, animated: true, completion: nil)
like image 588
Jason Avatar asked Dec 07 '25 03:12

Jason


1 Answers

I have done it like this :

 var filePath = NSBundle.mainBundle().pathForResource("Event", ofType:"pkpass")
        var pkfile : NSData = NSData(contentsOfFile: filePath!)!
        var pass : PKPass = PKPass(data: pkfile, error: nil)
        let vc = PKAddPassesViewController(pass: pass) as PKAddPassesViewController
        self.presentViewController(vc, animated: true, completion: nil)

and made sure that the pkpass file is set in build Settings/Copy Bundle Resources.

Hope this helps someone.

like image 95
Jason Avatar answered Dec 08 '25 18:12

Jason