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 工具.书籍.电子书.经典博文等等.伯乐在线对该资源列表进行了翻译, ...
随机推荐
- 【C语言入门教程】4.6 指针 和 数组
数组在内存中以顺序的形式存放,数组的第一个存储单元的地址即数组的首地址.对一维数组来说,直接引用数组名就能获得该数组的首地址.指针变量可以存放于其内容相同的数组首地址,也可以指向某一具体的数组元素.通 ...
- 如何查看 Linux是32位还是64位?
方法一:执行命令 file /sbin/init [root@localhost jianbao]# file /sbin/init /sbin/init: ELF 32-bit LSB shared ...
- BZOJ4519——[cqoi2016]不同的最小割
0.题意:求两点之间的最小割的不同的总量 1.分析:裸的分治+最小割,也叫最小割树或GH树,最后用set搞一下就好 #include <set> #include <queue> ...
- php写入txt换行符
1.问题 写入txt文件想换行,老是直接输出了\r\n. 2.解决 要用双引号对\r\n进行解释,否则php会直接当字符输出. 3.例子 要求:往test.txt文本每一行后面加abc $a=file ...
- linux下使用rdp
简单的说就是在linux下如何远程终端连接一台windows的服务器. 在windwos下我们直接可以mstsc开启远程终端的连接.而linux下呢.就需要安装一款工具了. 命令:sudo apt-g ...
- 剑指Offer 数值的整数次方
题目描述 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. 思路: 要考虑边界,0,负数 AC代码: class Solution ...
- Opencv SkinOtsu皮肤检测
void SkinRGB(IplImage* rgb, IplImage* _dst) { assert(rgb->nChannels == && _dst->nChann ...
- 怎样在myEclipse中使用debug调试程序?
怎样在myEclipse中使用debug调试程序? 最基本的操作是: 1.首先在一个java文件中设断点,然后debug as-->open debug Dialog,然后在对话框中选类 ...
- 1. dex和Jar反编译对比
Java源码 public class Hello { public int foo(int a,int b) { return (a + b) * (a - b); } public static ...
- Border Tree笔记
最近在学这个东西(当然不是行道树了QAQ..),感觉挺鬼畜的,整个人都不太好了..(特别是鬼畜的sone爷代码与讲稿),感觉他写的并不是普及向算法...?