0
#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ウォレットに保存しようとしています。安全な問題のため、uri の代わりに base64 データを使用する必要があります。このために私が想定した流れは以下のようなものです

  1. サーバーから base64 文字列を取得します。
  2. 「initWithBase64EncodedString」で base64 を pkpass データに変換します
  3. 「PKAddPassesViewController」で pkpass をウォレットに保存する

上記のコードでは、デコードされたbase64文字列が正しい場合でも、2番目のステップでnilエラーで進行が停止します。したがって、2番目のステップの後のコードがエラーなしで機能するかどうかはわかりません。

事前に答えてくれてありがとう。

4

1 に答える 1