gpt4 book ai didi

xcode - 无法在Mac上恢复购买

转载 作者:行者123 更新时间:2023-12-02 05:56:15 27 4
gpt4 key购买 nike

我在Mac上恢复购买时遇到问题。
我已经设置了Itunesconnect应用,应用内购买,测试用户。我可以买东西。如果我多次购买相同的非消耗性物品,系统会说它已经购买了,我将免费获得。但是恢复问题。

这是代码:

AppDelegate.h

#import <Cocoa/Cocoa.h>
#import <StoreKit/StoreKit.h>

@interface AppDelegate : NSObject <NSApplicationDelegate, SKProductsRequestDelegate, SKPaymentTransactionObserver>
{
NSArray *m_productIdentifiers;
NSArray* m_products;
}
-(IBAction)Press1:(id)sender;
-(IBAction)Press2:(id)sender;
@property (assign) IBOutlet NSWindow *window;
@end

AppDelegate.m
#import "AppDelegate.h" 

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *receiptPath = [[[NSBundle mainBundle] appStoreReceiptURL] path];
if (![[NSFileManager defaultManager] fileExistsAtPath:receiptPath])
{
exit(173);
}

NSURL *url = [[NSBundle mainBundle] URLForResource:@"products"
withExtension:@"plist"];
m_productIdentifiers = [NSArray arrayWithContentsOfURL:url];

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}

-(IBAction)Press1:(id)sender
{
[self validateProductIdentifiers:m_productIdentifiers];
return;
}

-(IBAction)Press2:(id)sender
{
[self restorePurchases];
}


- (void)validateProductIdentifiers:(NSArray *)productIdentifiers
{
SKProductsRequest *productsRequest = [[SKProductsRequest alloc]
initWithProductIdentifiers:[NSSet setWithArray:productIdentifiers]];
productsRequest.delegate = self;
[productsRequest start];
}


- (void)productsRequest:(SKProductsRequest *)request
didReceiveResponse:(SKProductsResponse *)response
{
m_products = response.products;

for (NSString *dentifier in response.products)
{
NSLog(@"%@",dentifier);
}
}

- (void)requestDidFinish:(SKRequest *)request
{
NSLog(@"requestDidFinish");
return;
}

- (void)request:(SKRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"request");
return;
}

- (void)restorePurchases
{
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction * transaction in transactions) {
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
default:
break;
}
};
}

- (void)completeTransaction:(SKPaymentTransaction *)transaction {
NSLog(@"completeTransaction...");

NSLog(@"completeTransaction... %@",transaction.payment.productIdentifier);
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}

- (void)restoreTransaction:(SKPaymentTransaction *)transaction {
NSLog(@"restoreTransaction...");

NSLog(@"restoreTransaction... %@",transaction.payment.productIdentifier);
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}

- (void)failedTransaction:(SKPaymentTransaction *)transaction {

NSLog(@"failedTransaction...");
if (transaction.error.code != SKErrorPaymentCancelled)
{
NSLog(@"Transaction error: %@", transaction.error.localizedDescription);
}

[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
NSLog(@"restoreCompletedTransactionsFailedWithError: %@", error);
}

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
NSLog(@"paymentQueueRestoreCompletedTransactionsFinished");
}
@end

Press1运作良好。我检索了所有产品ID。但是在激活Press2(恢复)后,系统会询问密码,然后调用 - (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error函数。

控制台说:
11/27/13 4:19:00.022 PM storeagent: promptResponse: <CKSignInPromptResponse:0x7fdefca0b950 returnCode:1>
11/27/13 4:19:00.552 PM storeagent: LoadCompletedMicroPaymentsOperation: Could not install receipt after fetching completed purchases - Error Domain=ISErrorDomain Code=2 "No receipt." UserInfo=0x7fdefca183f0 {NSLocalizedDescription=No receipt., NSLocalizedFailureReason=receiptAsString was nil}
11/27/13 4:19:00.554 PM ***mac: restoreCompletedTransactionsFailedWithError: Error Domain=SKErrorDomain Code=0 "Unknown Error." UserInfo=0x1001e7190 {NSLocalizedDescription=Unknown Error.}

我已经使用发行证书(第三方Mac开发者应用程序: *** )对应用程序进行了签名。
沙盒模式已禁用,但我认为这不是问题的根源。
我没有在构建中包含Embedded.provisionprofile,但我认为现在不需要它。
  • Xcode 4.6.3 + Mac OS 10.7.4
  • Xcode 5.0 + Mac OS 10.8.4
  • 最佳答案

    因此,我终于找到了解决方案。问题出在测试用户中。也许是因为它们是在我们没有Mac开发人员程序(仅ios)时创建的,但是在创建新的测试用户之后,问题就消失了。

    关于xcode - 无法在Mac上恢复购买,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20243870/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com