Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IOS存折代码示例如何添加?_Ios_Objective C - Fatal编程技术网

IOS存折代码示例如何添加?

IOS存折代码示例如何添加?,ios,objective-c,Ios,Objective C,我只是尝试添加我的存折而不通过电子邮件共享。如何在单击按钮时添加存折?此代码假定您首先知道如何创建存折 NSError * passerror; PKPass * pass = [[PKPass alloc] initWithData:data error:&passerror]; if(!pass) { UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Pass Failed" message:@"S

我只是尝试添加我的存折而不通过电子邮件共享。如何在单击按钮时添加存折?

此代码假定您首先知道如何创建存折

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>
#导入

此代码假定您首先知道如何创建通行证

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>
#导入

此代码假定您首先知道如何创建通行证

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>
#导入

此代码假定您首先知道如何创建通行证

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>
#导入

我需要导入什么?我需要导入什么?我需要导入什么?我需要导入什么?