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
Ios 当事务不可用时,无法恢复事务';不存在应用程序内购买和目标c_Ios_Objective C_Iphone_Uibutton_In App Purchase - Fatal编程技术网

Ios 当事务不可用时,无法恢复事务';不存在应用程序内购买和目标c

Ios 当事务不可用时,无法恢复事务';不存在应用程序内购买和目标c,ios,objective-c,iphone,uibutton,in-app-purchase,Ios,Objective C,Iphone,Uibutton,In App Purchase,我有一个应用程序,正在开发应用程序内购买。整个购买过程都在进行中,如果有使用Apple ID的活动购买,则恢复也在进行中。但是,当用户单击“恢复购买”ui按钮时,如果登录的Apple帐户没有活动购买,则我希望处理这种情况 在myAppDelegate中,我有: - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { for (SKPaymentTransa

我有一个应用程序,正在开发应用程序内购买。整个购买过程都在进行中,如果有使用Apple ID的活动购买,则恢复也在进行中。但是,当用户单击“恢复购买”
ui按钮时,如果登录的Apple帐户没有活动购买,则我希望处理这种情况

在my
AppDelegate
中,我有:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{    
    for (SKPaymentTransaction *transaction in transactions)
    {
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
            {
                // unlock the full version
                [self unlockFullVersion:transaction];
                [[SKPaymentQueue defaultQueue]finishTransaction:transaction];
                [self saveReceipts];
                break;
            }

            case SKPaymentTransactionStatePurchasing:
            {
                // currently purchasing
                break;
            }
            case SKPaymentTransactionStateRestored:
            {
                [self restoreTransaction:transaction]; 
                [[SKPaymentQueue defaultQueue]finishTransaction:transaction];

                break;
            }
            case SKPaymentTransactionStateFailed:
            {
                // it didn't work
                break;
            }
            case SKPaymentTransactionStateDeferred:
            {
                // deferred
                break;
            }
        }
    }

}

- (void)restoreTransaction:(SKPaymentTransaction *)transaction
{
    if (transaction)
    {

        if ([transaction.payment.productIdentifier isEqualToString:@"com.company.Unlimited"])
        {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"CheckProVersion" object:self userInfo:nil];
            [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"IAPSuccessful"];


            [[NSUserDefaults standardUserDefaults]synchronize];
        }

            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Restore Successful" message:@"Your restore was successful." delegate:nil cancelButtonTitle:@"Thanks" otherButtonTitles:nil, nil];
        [alertView show];
    }
    else
    {
        NSLog(@"The transaction does not exist");

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Restore Unsuccessful" message:@"Your Apple ID doesn't have an active purchase for upgrading to Envylope Pro. " delegate:nil cancelButtonTitle:@"Thanks" otherButtonTitles:nil, nil];
        [alertView show];
    }
}
在这种特殊情况下,如果事务不存在,则不会调用
restoreTransaction
方法中的第二个
UIAlertView

我已经设置了一个断点,但它从未被调用。我已经设置了一个
SKPaymentTransactionStateFailed
案例的断点,我发现,当我没有有效购买时,这个断点会被击中。但是,这实际上会从
AppDelegate
执行我想要的操作(比如
UIAlertView
),我只希望它在一个单独的
InAppPurchaseViewController
中运行

问题

从apppurchaseviewcontroller的
InAppPurchaseViewController
(几屏之外),我有一个还原
ui按钮
,我想要的是在点击按钮的过程中执行一个测试,以查看此Apple ID的事务是否存在。这样的事情可能吗

更新

SKPaymentTransactionStateFailed
中,我已将:

        NSString * const SKErrorDomain;
        NSLog(@"The error is %@", SKErrorDomain);

我得到
(null)
作为错误

尝试添加此方法,它处理没有要恢复的购买的情况:

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {

   if (queue.transactions.count == 0){
     NSLog(@"The transaction does not exist");

     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Restore Unsuccessful" message:@"Your Apple ID doesn't have an active purchase for upgrading to Envylope Pro. " delegate:nil cancelButtonTitle:@"Thanks" otherButtonTitles:nil, nil];
     [alertView show];
 }
}

非常感谢您的回复-知道有这种方法可供选择真是太好了。我需要从SKPaymentTransactionStateFailed或类似的案例中调用它吗?抱歉,我之所以问这个问题,是因为它目前没有使用该方法执行任何操作。它是SKPaymentTransactionObserver协议的一部分,因此当您从应用商店收到响应时,它会自动调用。Xcode说:“这个方法是在支付队列处理完所有可恢复的交易后调用的。”试着在真实的设备上测试它,因为模拟器通常会出错。您可以实现paymentQueue:restoreCompletedTransactionsFailedWithError:以检查其是否为真。非常感谢-我运行了一些调试,但由于某些奇怪的原因,它没有在应用程序委托中被调用。非常抱歉地问,我将如何实现restoreCompletedTransactionsFailedWithError?对不起,有点像新手!