wallet的前身為passbook,2015年WWDC大會蘋果正式改名wallet,passbook是蘋果2012年iOS6開放出來的新功能.可以幫助用戶管理五種類型(Boarding passes(登機(jī)牌),Coupons(優(yōu)惠券),Store cards(購物卡),Event tickets(入場券),Generic(通用卡))的票據(jù)
在iOS中一個(gè)Pass其實(shí)就是一個(gè).pkpass文件,事實(shí)上它是一個(gè)Zip壓縮包,只是這個(gè)壓縮包要按照一定的目錄結(jié)構(gòu)來設(shè)計(jì)
如何創(chuàng)建一個(gè)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];
}];
}
});
}
}
個(gè)人博客地址:https://youyou0909.github.io