1

我正在使用 PassSlot,它可以即时创建一个可以添加到存折的通行证。我正在尝试将其下载到设备以允许附加到电子邮件。这是我到目前为止所拥有的:

[PassSlot passFromTemplateWithName:@"LoveCouponCards" withValues:values pass:^(PSPass *pass) {
    [PassSlot downloadPass:pass pass:^(PSPass *pass) {
        PKPass *pkpass = [pass performSelector:@selector(pass)];
        NSLog(@"Pass: %@", pkpass);


        MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;


        NSArray *toRecipients = [NSArray arrayWithObject:@"friend@example.com"];


        [picker setToRecipients:toRecipients];


        [picker addAttachmentData:pkpass mimeType:@"application/vnd.apple.pkpass" fileName:@"HI"];

        // Fill out the email body text
        NSString *emailBody = \\
        [picker setMessageBody:emailBody isHTML:NO];

        [self presentViewController:picker animated:YES completion:nil];


    }];
}];

问题是在电子邮件的 addAttachment 部分中,它引发了一个错误,即 NSData 基本上与 PKPass 无关。如何将通行证转换为 NSData 以便我可以附加它?

更新:

我试着做

 NSURL *url = pkpass.passURL;
 NSData *so = [NSData dataWithContentsOfURL:url];

然后将'so'作为addAttachment,但它没有附加任何电子邮件。

4

2 回答 2

3

首先, 的passURL属性PKPass并不像你想象的那样工作。它不是通行证本身的 URL。这是一个打开 Passbook 应用程序并加载请求的通行证的 URL。

您可以创建一个PKPasswith NSData,但不能逆转该过程。听起来好像您正试图在设备上获得通行证,然后通过电子邮件发送它。这是不允许的 - 如果是这样,人们可以轻松地复制和分发通行证(这不一定是一件好事)。

如果您想通过电子邮件向用户发送通行证,您需要在服务器端而不是客户端进行。恐怕您无法使用PassKit. 对不起!

于 2013-01-27T14:44:08.330 回答
2

Unfortunately the PassKit library does not provide a way to get back the NSData from a PKPass.

We already provide an API call that allows you to get the raw data of a pass. We will extend our PassSlot SDK with a method that allows you to get the NSData without having the manually call this API method.

Update

The new SDK version 0.5 is now released. You can attach the pass with the following code:

[PassSlot passFromTemplateWithName:@"LoveCouponCards" withValues:values pass:^(PSPass *pass) {
    [PassSlot downloadPass:pass pass:^(PSPass *pass) {

        MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;

        [picker setToRecipients:@[@"friend@example.com"]];
        [picker addAttachmentData:pass.data mimeType:@"application/vnd.apple.pkpass" fileName:@"LoveCouponCard.pkpass"];
        [picker setMessageBody:emailBody isHTML:NO];

        [self presentViewController:picker animated:YES completion:nil];
    }];
}];
于 2013-01-27T21:19:11.793 回答