1 / 29

iOS6 PassBook

iOS6 PassBook. 透明de面具. PassBook 是啥. PassBook是收集一堆Pass用的容器(废话一句). 那Pass又是啥. Pass是对于可以装入PassBook的一些类似会员卡, 票证等等的泛称(至少我这样理解...). Pass的导入. 如何把pass加入到passbook 三种途径 email web apps. Pass的导入. email 邮件客户端: 直接将pkpass文件作为附件发送 以代码发送邮件, 需要设置MIME的部分, 以python为例

mandek
Download Presentation

iOS6 PassBook

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. iOS6 PassBook • 透明de面具

  2. PassBook 是啥 • PassBook是收集一堆Pass用的容器(废话一句)

  3. 那Pass又是啥 • Pass是对于可以装入PassBook的一些类似会员卡, 票证等等的泛称(至少我这样理解...)

  4. Pass的导入 • 如何把pass加入到passbook • 三种途径 • email • web • apps

  5. Pass的导入 • email • 邮件客户端: 直接将pkpass文件作为附件发送 • 以代码发送邮件, 需要设置MIME的部分, 以python为例 • from email.mime.base import MIMEBasefrom email.mime.multipart import MIMEMultipartmsg = MIMEMultipart() #set msg[‘from’] msg[‘to’] and etc...attachment = 'passes/event.pkpass'pkpass = MIMEBase("application", "vnd.apple.pkpass")fp = open(attachment, 'rb')pkpass.set_payload(fp.read())fp.close()encoders.encode_base64(pkpass)pkpass.add_header('Content-Disposition', 'attachment', filename=attachment)msg.attach(pkpass)

  6. Pass的导入

  7. Pass的导入 • web • 需要设置一些pkpass文件相关的响应头. 以Apache为例, 需要开启mod_headers. • cat .htaccess<FilesMatch "\.(?i:pkpass)$"> ForceType application/vnd.apple.pkpass SetEnvIf Request_URI "^.*/([^/]*)$" FILENAME=$1 Header set Content-Disposition "attachment; filename=%{FILENAME}e" UnsetEnv FILENAME Header set Pragma no-cache Header set Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"</FilesMatch>

  8. Pass的导入 • apps • 根据pass文件创建出PKPass实例(这步会校验pass.json是否合法, 包括json语法是否规范以及相关字段是否符合要求) • NSData *data = [NSData dataWithContentsOfFile:passFilePath];NSError *error = nil;PKPass *pass = [[PKPass alloc] initWithData:data error:&error];NSLog(@”%@”, error.debugDescription);

  9. Pass的导入 • apps • 检查PKPassLibrary内是否已经有同样的pass, 有的话, 进行更新, 没有就要进行增加. • PKPassLibrary *passLibrary = [[PKPassLibrary alloc] init];if([passLibrary containsPass:pass]) {BOOL replaceResult = [passLibrary replacePassWithPass:pass];} else {PKAddPassesViewController *addPassesViewController = [[PKAddPassesViewController alloc] initWithPass:pass];addPassesViewController.delegate = self;[self.navigationController presentViewController:addPassesViewController animated:YES completion:NULL];[addPassesViewController release];}

  10. Pass的导入

  11. Pass的文件结构 • .pkpass文件其实就是一个zip文件 • pkpass内的文件组织结构 • pass.json • manifest.json • signature • icon.png & icon@2x.png • logo.png & logo@2x.png • thumbnail.png • background.png • other multi-language files

  12. Pass的文件结构 • pkpass内的文件组织结构 • pass.json • pass内最基础的文件之一 • json格式 • 内涵pass需要的全部字段, 后续详述

  13. Pass的文件结构 • pkpass内的文件组织结构 • manifest.json • json格式 • 用以校验pass内其他文件是否正确 • 会记录除mainfest.json以及signature之外其他文件的sha1sum

  14. Pass的文件结构 • pkpass内的文件组织结构 • signature • 对manifest.json进行签名后生成的数字签名 • 用以验证manifest.json的合法性 • 签名用的证书是从IDP内获取 • 导入passbook后, 系统内部会进行合法性校验

  15. Pass的文件结构 • pkpass内的文件组织结构 • icon.png & icon@2x.png • 显示在email导入时左侧的icon, 系统会负责添加圆角和高光 • PKPass类会有一个icon的属性, 也是指向该图片

  16. Pass的文件结构 • pkpass内的文件组织结构 • logo.png & logo@2x.png • 在passbook内, 每个pass左上角的icon • 需要是透明底色

  17. Pass的文件结构 • pkpass内的文件组织结构 • thumbnail.png • 部分类型的pass内有效 • 对于Generic类型的而言, 是右侧的头像 • Event也是右侧图像

  18. Pass的文件结构 • pkpass内的文件组织结构 • background.png • 至少对部分类型的Pass起作用(没有详细测试), 但至少表现不同 • StoreCard内是上方横向的贯通图 • EventTicket内则是虚化背景用

  19. pass.json • 基本字段 • formatVersion • 文件格式标识, 目前只有 1 一个取值 • passTypeIdentifier • 在idp内建立的pass标识, 与签名用的证书相关联 • organizationName • 组织名称, 会在email的附件部分以及在PKPass的一个属性中体现 • teamIdentifier • 组织唯一标识, 目前没找到来源, 我这边用appid前系统添加那个串来替代了. • serialNumber • 唯一标识一个pass的码, 两个码一样且组织标识一样的将被认为是同一个pass • description • iOS6 B2开始要求的新字段, 内容随便写

  20. pass.json • 其他可选字段 • locations • relevantDate • foregroundColor • backgroundColor • logoText • webServiceURL • authenticationToken • barCode

  21. pass.json • 其他可选字段 • locations • 到达此位置范围或者附近时会给出提示 • 一组或多组经纬度组合, 也可以包括海拔高度. • 应该是根据经纬度的精度不同来设定范围的大小(并未详细测试)

  22. pass.json • 其他可选字段 • relevantDate • 触发时间 • 到该时间时会给出提示

  23. pass.json • 其他可选字段 • foregroundColor & backgroundColor • 类似 rgb(22, 55, 111) 这样的颜色值 • 分别是背景和前景(字)的颜色

  24. pass.json • 其他可选字段 • webServiceURL & authenticationToken • pass可以和一个webService进行交互, 以获取更新等状态 • 需要以authenticationToken进行认证

  25. pass.json • 其他可选字段 • barCode • 生成二维码或者条码等 • format: 必要字段, 标明要生成哪种码, 有如下可选PKBarcodeFormatQR, //二维码PKBarcodeFormatPDF417, //条码PKBarcodeFormatAztec,PKBarcodeFormatText • message: 必要字段, barcode的原文 • messageEncoding: 原文的编码, 一般来讲是iso-8859-1, 但如果确定扫描的设备可以识别, 其他的也可以, 比如中文等等. • altText: 可选字段, 会显示在barcode附近的一行文字, 一般建议是barcode对应的信息等等, 以便在扫描无能的情况下也能使用.

  26. pass.json • pass核心部分 • boardingPass • coupon • eventTicket • generic • storeCard

  27. Pass打包 • 生成全部文件的sha1写入manifest.json • 用openssl对manifest.json签名, 生成signature • 将全部文件打包成zip文件, 并命名为pkpass后缀

  28. Pass打包 • manifest.json以及zip内最好不要含有.DS_Store这个文件 • zip内应该直接是pass.json等, 而不是再有一层目录.

  29. 官方信息 • https://developer.apple.com/library/prerelease/ios/#documentation/UserExperience/Conceptual/PassKit_PG/Introduction.html#//apple_ref/doc/uid/TP40012195-CH1-SW1 • WWDC 2012 sample codes

More Related