swift - 存折,在应用程序中显示一个 .pass

标签 swift passkit

全部, 我一直在阅读 Apple 文档,并且找到了显示通行证位和更改应用程序通行证的信息。但是有没有办法将 .pass zip 存储在 XCODE 中并显示在弹出 View Controller 中?

我已经弄明白了,但是我没有用。

有什么建议吗??

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)

最佳答案

我是这样做的:

 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)

并确保在 build Settings/Copy Bundle Resources 中设置了 pkpass 文件。

希望这对某人有帮助。

关于swift - 存折,在应用程序中显示一个 .pass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28744981/

相关文章:

ios - 奇怪的错误,当尝试滚动到底部时,collectionView View 滚动到倒数第二条消息

ios - UIScrollView 可滚动内容大小歧义

ios - 带有 nib 实例的 UIViewController 子类的便捷初始化程序?

php - 生成存折通行证 Web 服务 URL 无法通过 php 运行

ios - 在网络服务中注册一个 iphone 应用程序

ios - NSKeyedUnarchiver.unarchiveTopLevelObjectWithData 在 Swift 4 中被废弃

ios - 为什么在呈现 View Controller 后 UIView 从层次结构中删除?

ios - 如何为 iOS 存折创建 "generic type pass"?

ios - 添加指向 Apple Passbook 首页的超链接