#import <PassKit/PassKit.h>
// convert base64 string to pkpass data
NSData *passData = [[NSData alloc] initWithBase64EncodedString:strEncodeData options:0];
NSLog(passData);
// init a pass object with the data
PKPass *pass = [[PKPass alloc] initWithData:passData];
NSLog(pass);
//init a pass library
PKPassLibrary *passLib = [[PKPassLibrary alloc] init];
//check if pass library contains this pass already
if([passLib containsPass:pass]) {
//pass already exists in library, show an error message
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Pass Exists" message:@"The pass you are trying to add to Passbook is already present." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
} else {
//present view controller to add the pass to the library
PKAddPassesViewController *vc = [[PKAddPassesViewController alloc] initWithPass:pass];
[vc setDelegate:(id)self];
[self presentViewController:vc animated:YES completion:nil];
}
我正在尝试将存折保存到 ios 钱包。由于安全问题,我需要使用 base64 数据而不是 uri。我为此假设的流程如下所示
- 从服务器获取 base64 字符串。
- 使用“initWithBase64EncodedString”将 base64 转换为 pkpass 数据
- 使用“PKAddPassesViewController”将 pkpass 保存到钱包
使用上面的代码,进度在第二步停止,出现 nil 错误,即使解码的 base64 字符串是正确的。所以我不能确定第二步之后的代码是否会正常运行。
感谢您提前回答。