【发布时间】:2015-10-30 06:55:18
【问题描述】:
#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 字符串是正确的。所以我不能确定第二步之后的代码是否会正常运行。
感谢您提前回答。
【问题讨论】:
-
您是否确认base64字符串中包含的pass是有效的,并且可以通过pkpass文件或url添加到Passbook?
-
我只是把使用在线工具手动生成的base64字符串(UTF-8格式)。我可以检查 xcode(object-c) 上的字符串是否正确吗?