wallet的前身为passbook,2015年WWDC大会苹果正式改名wallet,passbook是苹果2012年iOS6开放出来的新功能.可以帮助用户管理五种类型(Boarding passes(登机牌),Coupons(优惠券),Store cards(购物卡),Event tickets(入场券),Generic(通用卡))的票据
在iOS中一个Pass其实就是一个.pkpass文件,事实上它是一个Zip压缩包,只是这个压缩包要按照一定的目录结构来设计
如何创建一个Pass可以参考Apple的文档
https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/PassKit_PG/YourFirst.html#//apple_ref/doc/uid/TP40012195-CH2-SW1
-(void)addPassbookView:(NSData *)date{
NSError *error = nil;
BOOL passEnbale = [PKPassLibrary isPassLibraryAvailable];//检查pass是否可用
if (![PKPassLibrary isPassLibraryAvailable]) {//
dispatch_async(dispatch_get_main_queue(), ^{
//[[WaitDialogFullS sharedWaitDialog] endLoading];
[[[UIAlertView alloc] initWithTitle:@"Error"
message:@"PassKit not available"
delegate:nil
cancelButtonTitle:GDLocalizedString(@"jpyd_ok")
otherButtonTitles: nil] show];
});
return;
}
if (passEnbale) {
PKPass *onePass = [[PKPass alloc] initWithData:date error:&error];
if (error) {
dispatch_async(dispatch_get_main_queue(), ^{
// [[WaitDialogFullS sharedWaitDialog] endLoading];
ZNLog(@"!!!!!ERROR:%@",[error description]);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:GDLocalizedString(@"jpyd_Friendlyreminder") message:GDLocalizedString(@"sy_onePass") delegate:nil cancelButtonTitle:GDLocalizedString(@"jpyd_ok") otherButtonTitles:nil, nil];
[alert show];
[alert release];
});
return ;
}
dispatch_async(dispatch_get_main_queue(), ^{
PKAddPassesViewController *passAddViewController = [[[PKAddPassesViewController alloc] initWithPass:onePass]autorelease];
passAddViewController.delegate = self;
ChinaEastViewController *app = [ChinaEastViewController sharedBankcommViewController];
//Application tried to present a nil modal view controller on target .修改听云,李良
if (passAddViewController) {
[app presentViewController:passAddViewController animated:YES completion:^{
// [[WaitDialogFullS sharedWaitDialog] endLoading];
}];
}
});
}
}
个人博客地址:https://youyou0909.github.io