我正在使用 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,但它没有附加任何电子邮件。