IOS - Passbook
1. 什么是Passbook
// 添加框架
#import <PassKit/PassKit.h>
@interface GViewController ()
// 存放加载的pkpass文件
@property (strong,nonatomic) NSArray *dataList;
@end
@implementation GViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// 获得加载到得数据
_dataList = [self loadPasses];
// IOS6 和 IOS7 适配
if ([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0 ) {
[self.tableView setContentInset:UIEdgeInsetsMake(20, self.tableView.contentInset.left, self.tableView.contentInset.bottom, self.tableView.contentInset.right)];
}
}
/**
* 加载数据
*
* @return 返回文件后缀名为pkpass 的文件
*/
- (NSArray *)loadPasses
{
// 1.获得mainBundle 的路径
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
// 2.取出mainBundle中的文件,存放在数组中
NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resourcePath error:nil];
// 3.遍历数组,取出pkpass 文件
NSMutableArray *arrayM = [NSMutableArray array];
for (NSString *fileName in array) {
// 获取文件后缀名为.pkpass 的文件
if ([fileName hasSuffix:@".pkpass"]) {
[arrayM addObject:fileName];
}
}
// 4.返回获得的数据
return arrayM;
}
-(void)openWithName:(NSString *)name
{
// 1.根据文件名获取文件完整路径
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:name];
// 2.将文件加载到NSData中
NSData *data = [NSData dataWithContentsOfFile:path];
// 3.实例化pkpass (根据NSData 数据)
PKPass *pass = [[PKPass alloc] initWithData:data error:nil];
// 4.将pass实例添加到pass视图中
PKAddPassesViewController *controller = [[PKAddPassesViewController alloc] initWithPass:pass];
// 5.显示pass视图控制器
[self presentViewController:controller animated:YES completion:nil];
}
#pragma mark - tableView 的数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _dataList.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 1.设置cell的唯一标示符
static NSString *ID = @"cell";
// 2.cell重用
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath];
// 3.设置cell的内容
cell.textLabel.text = _dataList[indexPath.row];
return cell;
}
#pragma mark - tableView 的代理方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self openWithName:_dataList[indexPath.row]];
}
@end
IOS - Passbook的更多相关文章
- PHP资源列表
一个PHP资源列表,内容包括:库.框架.模板.安全.代码分析.日志.第三方库.配置工具.Web 工具.书籍.电子书.经典博文等等. 初始翻译信息来自:<推荐!国外程序员整理的 PHP 资源大全& ...
- 【PHP资源】PHP 资源大全
看到这篇文章不错,转来收藏 依赖管理 依赖和包管理库 Composer/Packagist:一个包和依赖管理器 Composer Installers:一个多框架Composer库安装器 Pickle ...
- 【PHP开发】国外程序员收集整理的 PHP 资源大全
依赖管理 依赖和包管理库 Composer/Packagist:一个包和依赖管理器 Composer Installers:一个多框架Composer库安装器 Pickle:一个PHP扩展安装器 其他 ...
- 优秀的PHP开源项目集合
包管理Package Management Package Management Related 框架 框架组件 微框架Micro Frameworks 内容管理系统Content Managemen ...
- 推荐!国外程序员整理的 PHP 资源大全
推荐!国外程序员整理的 PHP 资源大全 2014/08/02 · PHP, 工具与资源 · 8.5K 阅读 · 1 评论· php 分享到:0 与<YII框架>不得不说的故事—安全篇 R ...
- PHP框架、库和软件资源大全(整理篇)
php的资料 https://github.com/ziadoz/awesome-php Awesome PHP A curated list of amazingly awesome PHP lib ...
- 国外程序员收集整理的PHP资源大全
依赖管理 依赖和包管理库 Composer/ Packagist:一个包和依赖管理器 Composer Installers:一个多框架Composer库安装器 Pickle:一个PHP扩展安装器 其 ...
- [ Alcatraz ]管理Xcode插件
[ Alcatraz 配置 ] 1.包管理器在线安装 Terminal终端 $ curl -fsSL https://raw.githubusercontent.com/supermarin/Alca ...
- 【转】国外程序员收集整理的PHP资源大全
ziadoz在 Github发起维护的一个PHP资源列表,内容包括:库.框架.模板.安全.代码分析.日志.第三方库.配置工具.Web 工具.书籍.电子书.经典博文等等.伯乐在线对该资源列表进行了翻译, ...
随机推荐
- 清除浮动(clearfix hack)
eg:
- 71 mac boook pro 无 gpu 下caffe 安装
71 mac boook pro 无 gpu 下caffe 安装 1.首先安装homebrew工具,相当于Mac下的yum或apt ruby -e "$(curl -fsSL https:/ ...
- boss设计参考的脑图
- sass兼容IE8透明度方法
你可以轻松的利用 {Sass::Script::Functions#ie_hex_str ie_hex_str} 函数对其做转换.$translucent-red: rgba(, , , 0.5); ...
- PowerDesigner的使用(一)
一. PowerDesigner 功能 1. 需求管理:记录需求,分析设计模型 2. 生成文档:生成HTML格式文档,方便沟通. 3. 影响度分析:模型之间连接起来,同步修改功能. 4. 数据映射:提 ...
- 使用IzPack打包JAVA Web应用程序
使用IzPack打包JAVA Web应用程序步骤如下: 这里使用IzPack-4.3.5 + launch4j-3.1.0-beta1-win32.zip(绿色版)对Web应用程序打包,打包后即可对我 ...
- 下一代GNU/Linux显示服务Wayland 1.12正式发布
导读 最近,Bryce Harrington很高兴地宣布了“面向GNU/Linux操作系统的Wayland 1.12.0显示服务已正式发布”的消息.与它一同到来的,还有Weston 1.12.0合成器 ...
- oracle with as 用法
http://blog.itpub.net/28371090/viewspace-1190141/
- 3.3---集合栈(CC150)
思路:注意一下别写错add还是remove public class SetOfStacks { public static ArrayList<ArrayList<Integer> ...
- svn update错误
可以再checkout下来一份项目,重新命名,然后将该项目下的隐藏文件夹.svn替换掉原项目 注意备份