-1
我只是試圖添加我的存摺而不通過電子郵件分享。如何在點擊按鈕上添加我的存摺?IOS存摺代碼示例如何添加?
我只是試圖添加我的存摺而不通過電子郵件分享。如何在點擊按鈕上添加我的存摺?IOS存摺代碼示例如何添加?
此代碼假定您知道如何創建擺在首位的通...
NSError * passerror;
PKPass * pass = [[PKPass alloc] initWithData:data error:&passerror];
if(!pass) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Pass Failed" message:@"Sorry there was a problem creating your Passbook." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
return;
}
//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:@"Pass is already in Passbook." 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];
}
編輯你需要導入
#import <PassKit/PassKit.h>
我需要進口什麼? – 2014-10-27 13:07:40
更新了導入信息的答案 – Flexicoder 2014-10-27 13:21:54