Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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
Inapp购买成功,但iPhone应用程序中的内容未解锁。。为什么?_Iphone_Objective C_App Store - Fatal编程技术网

Inapp购买成功,但iPhone应用程序中的内容未解锁。。为什么?

Inapp购买成功,但iPhone应用程序中的内容未解锁。。为什么?,iphone,objective-c,app-store,Iphone,Objective C,App Store,在我的iphone应用程序中,我使用了应用程序内购买。所有的东西都在工作,内容都在资源文件夹中。成功完成事务后,我使用Sql查询在Sqlite数据库中插入数据。我在app Store中上传了这个应用程序,发现在成功交易后,从用户那里获得了付款,但内容没有插入数据库,也没有显示在应用程序中。请帮帮我。我在这一点上感到压力很大。因此,我已删除我的应用程序表单应用程序商店 在此代码中,在成功查找我正在使用的应用程序内购买列表后 为了更好地理解,我将我的一些代码放在这里: - (void)insertN

在我的iphone应用程序中,我使用了应用程序内购买。所有的东西都在工作,内容都在资源文件夹中。成功完成事务后,我使用Sql查询在Sqlite数据库中插入数据。我在app Store中上传了这个应用程序,发现在成功交易后,从用户那里获得了付款,但内容没有插入数据库,也没有显示在应用程序中。请帮帮我。我在这一点上感到压力很大。因此,我已删除我的应用程序表单应用程序商店

在此代码中,在成功查找我正在使用的应用程序内购买列表后

为了更好地理解,我将我的一些代码放在这里:

- (void)insertNewObject {

    // Create a new instance of the entity managed by the fetched results controller.
    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];

    // Save the context.
    NSError *error = nil;
    if (![context save:&error]) {
        /*
         Replace this implementation with code to handle the error appropriately.

         abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
         */
        // NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }
}


-(void)updateObject {
    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];

    // Save the context.
    NSError *error = nil;
    if (![context save:&error]) {

        abort();
    }
}


#pragma mark -
#pragma mark Store request

- (void) requestProductData {
    request= [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:[arrayProductID objectAtIndex:b-2]]];//@"Scaringmirror11"
    request.delegate = self;
    [request start];
}

- (void) startPurchase {
    //int newB=b-2;
    SKPayment *payment = [SKPayment paymentWithProductIdentifier:[arrayProductID objectAtIndex:b-2]];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}



#pragma mark Store delegate
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
    NSArray *myProduct = response.products;
    if (myProduct == nil || [myProduct count] == 0) 
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:ALERT_TITLE message:@"Missing product from App store.\n"
                                                       delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
        [alert show];
        [alert release];
        return;
    }
    SKProduct *product;
    BOOL    existProduct = NO;
    for (int i=0; i<[myProduct count]; i++) {
        product = (SKProduct*)[myProduct objectAtIndex:0];
        if ([product.productIdentifier isEqualToString:[arrayProductID objectAtIndex:b-2]]) {
            existProduct = YES;

            //[[NSUserDefaults standardUserDefaults] setValue:transaction.transactionReceipt forKey:@"proUpgradeTransactionReceipt" ];
            //[[NSUserDefaults standardUserDefaults] synchronize];
            break;
        }
    }
    if (existProduct == NO) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:ALERT_TITLE message:@"Missing product from App store.No match Identifier found.\n"
                                                       delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
        [alert show];
        [alert release];
        return;
    }

    [request autorelease];
    [self startPurchase];
}



#pragma mark Store delegate

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
    NSArray *myProduct = response.products;
    if (myProduct == nil || [myProduct count] == 0) 
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:ALERT_TITLE message:@"Missing product from App store.\n"
                                                       delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
        [alert show];
        [alert release];
        return;
    }
    SKProduct *product;
    BOOL    existProduct = NO;
    for (int i=0; i<[myProduct count]; i++) {
        product = (SKProduct*)[myProduct objectAtIndex:0];
        if ([product.productIdentifier isEqualToString:[arrayProductID objectAtIndex:b-2]]) {
            existProduct = YES;

            //[[NSUserDefaults standardUserDefaults] setValue:transaction.transactionReceipt forKey:@"proUpgradeTransactionReceipt" ];
            //[[NSUserDefaults standardUserDefaults] synchronize];
            break;
        }
    }
    if (existProduct == NO) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:ALERT_TITLE message:@"Missing product from App store.No match Identifier found.\n"
                                                       delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
        [alert show];
        [alert release];
        return;
    }

    [request autorelease];
    [self startPurchase];
}


#pragma mark observer delegate
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
    for (SKPaymentTransaction *transaction in transactions)
    {
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:

                [self completeTransaction:transaction];
                NSLog(@"Success");
                break;
            case SKPaymentTransactionStateFailed:
                [self failedTransaction:transaction];
                NSLog(@"Failed");
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
            default:
                break;
        }
    }
}

- (void) completeTransaction: (SKPaymentTransaction *)transaction {
    //[[NSUserDefaults standardUserDefaults] setBool:YES forKey:REGISTRATION_KEY];
    registered = YES;

    //NSData *receiptData = [transaction transactionReceipt];

    //NSString *str =[NSString string 
    //[[NSUserDefaults standardUserDefaults] setValue:transaction.transactionReceipt forKey:@"proUpgradeTransactionReceipt" ];
    //[self registeredEnable];
    // Remove the transaction from the payment queue.
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
    [sqlite insertIntoScaryImage:[arrayGetMoreScaryImage objectAtIndex:b] add:[arrayGetMoreScarySound objectAtIndex:b]];
}

- (void) restoreTransaction: (SKPaymentTransaction *)transaction {
    //[[NSUserDefaults standardUserDefaults] setBool:YES forKey:REGISTRATION_KEY];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:ALERT_TITLE message:@"Purchase success."
                                                   delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
    [alert show];
    [alert release];
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];

    //[sq];
}

- (void) failedTransaction: (SKPaymentTransaction *)transaction {
    if (transaction.error.code != SKErrorPaymentCancelled)
    {
        // Optionally, display an error here.
        NSString *stringError = [NSString stringWithFormat:@"Payment Cancelled\n\n%@", [transaction.error localizedDescription]];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:ALERT_TITLE message:stringError
                                                       delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
        [alert show];
        [alert release];

    }
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
-(void)insertNewObject{
//创建由“获取结果”控制器管理的实体的新实例。
NSManagedObjectContext*上下文=[self.fetchedResultsController managedObjectContext];
//保存上下文。
n错误*错误=nil;
如果(![上下文保存:&错误]){
/*
将此实现替换为适当处理错误的代码。
abort()导致应用程序生成崩溃日志并终止。您不应在装运应用程序中使用此函数,尽管它在开发过程中可能很有用。如果无法从错误中恢复,请显示一个警告面板,指示用户通过按“主页”按钮退出应用程序。
*/
//NSLog(@“未解决的错误%@,%@”,错误,[error userInfo]);
中止();
}
}
-(void)updateObject{
NSManagedObjectContext*上下文=[self.fetchedResultsController managedObjectContext];
//保存上下文。
n错误*错误=nil;
如果(![上下文保存:&错误]){
中止();
}
}
#布拉格标记-
#pragma标记存储请求
-(void)请求产品数据{
请求=[[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObject:[arrayProductID objectAtIndex:b-2]];/@“Scaringmirror11”
request.delegate=self;
[请求启动];
}
-(无效)开始采购{
//int-newB=b-2;
SKPayment*payment=[SKPayment paymentWithProductIdentifier:[arrayProductID objectAtIndex:b-2]];
[[SKPaymentQueue defaultQueue]addPayment:payment];
}
#pragma标记存储委托
-(无效)产品请求:(SKProductsRequest*)请求DID接收方响应:(SKProductsResponse*)响应{
NSArray*myProduct=response.products;
如果(myProduct==nil | |[myProduct count]==0)
{
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:alert\u TITLE消息:@“应用商店中缺少产品。\n”
代理:自取消按钮:@“关闭”其他按钮:无];
[警报显示];
[警报发布];
返回;
}
SKProduct*产品;
BOOL existProduct=否;

对于(int i=0;i您应该在收到付款确认后立即在payment observer中实现解锁功能。 您对observer的实现有点奇怪,我猜它不起作用

编辑:

你的观察员班

#import Foundation/Foundation.h #import StoreKit/StoreKit.h @interface InAppPurchaseObserver : NSObject { } - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions; @end #import "InAppPurchaseObserver.h" @implementation InAppPurchaseObserver // The transaction status of the SKPaymentQueue is sent here. - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { for(SKPaymentTransaction *transaction in transactions) { switch (transaction.transactionState) { case SKPaymentTransactionStatePurchasing: // Item is still in the process of being purchased NSLog(@"Processing!!!"); break; case SKPaymentTransactionStatePurchased: // Item was successfully purchased! // --- UNLOCK FEATURE OR DOWNLOAD CONTENT HERE --- // The purchased item ID is accessible via // transaction.payment.productIdentifier // After customer has successfully received purchased content, // remove the finished transaction from the payment queue. [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; break; case SKPaymentTransactionStateRestored: // Verified that user has already paid for this item. // Ideal for restoring item across all devices of this customer. // --- UNLOCK FEATURE OR DOWNLOAD CONTENT HERE --- // The purchased item ID is accessible via // transaction.payment.productIdentifier // After customer has restored purchased content on this device, // remove the finished transaction from the payment queue. [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; break; case SKPaymentTransactionStateFailed: // Purchase was either cancelled by user or an error occurred. NSLog(@"Failed!!!"); if (transaction.error.code != SKErrorPaymentCancelled) { // A transaction error occurred, so notify user. NSLog(@"Cancelled!!!"); } // Finished transactions should be removed from the payment queue. [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; break; } } } @end #导入Foundation/Foundation.h #导入StoreKit/StoreKit.h @AppPurchaseObserver中的接口:NSObject{ } -(void)paymentQueue:(SKPaymentQueue*)队列更新事务:(NSArray*)事务; @结束 #导入“InAppPurchaseObserver.h” @应用程序中的实现 //SKPaymentQueue的事务状态发送到此处。 -(void)paymentQueue:(SKPaymentQueue*)队列更新事务:(NSArray*)事务{ 用于(SKPaymentTransaction*交易中的交易){ 开关(transaction.transactionState){ 案例SKPaymentTransactionStatePurchasing: //项目仍在采购过程中 NSLog(@“处理!!!”); 打破 案例SKPaymentTransactionStatesPurchased: //物品已成功购买! //---在此处解锁功能或下载内容--- //可通过以下方式访问购买的项目ID: //transaction.payment.productIdentifier //客户成功接收购买的内容后, //从支付队列中删除已完成的事务。 [[SKPaymentQueue defaultQueue]finishTransaction:transaction]; 打破 案例SKPaymentTransactionStateRestored: //已验证用户已为此项目付款。 //非常适合在该客户的所有设备上恢复项目。 //---在此处解锁功能或下载内容--- //可通过以下方式访问购买的项目ID: //transaction.payment.productIdentifier //客户在此设备上恢复购买的内容后, //从支付队列中删除已完成的事务。 [[SKPaymentQueue defaultQueue]finishTransaction:transaction]; 打破 案例SKPaymentTransactionState失败: //用户已取消购买或发生错误。 NSLog(@“失败!!!”); if(transaction.error.code!=SKErrorPaymentCancelled){ //发生事务错误,请通知用户。 NSLog(@“已取消!!!”); } //应将已完成的交易从付款队列中删除。 [[SKPaymentQueue defaultQueue]finishTransaction:transaction]; 打破 } } } @结束 实施

- (void) requestProductData { inappObserver = [[InAppPurchaseObserver alloc] init]; request= [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:[arrayProductID objectAtIndex:b-2]]];//@"Scaringmirror11" request.delegate = self; [request start]; } - (void) startPurchase { //int newB=b-2; SKPayment *payment = [SKPayment paymentWithProductIdentifier:[arrayProductID objectAtIndex:b-2]]; [[SKPaymentQueue defaultQueue] addTransactionObserver:inappObserver]; [[SKPaymentQueue defaultQueue] addPayment:payment]; } -(void)请求产品数据{ inappObserver=[[InAppPurchaseObserver alloc]init]; 请求=[[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObject:[arrayProductID objectAtIndex:b-2]];/@“Scaringmirror11” request.delegate=self; [请求启动]; } -(无效)开始采购{ //int-newB=b-2; 付款*付款