我在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,但我认为我现在不需要它。
答案 0 :(得分:0)
所以,我终于找到了解决方案。问题出在测试用户身上。也许,因为它们是在我们没有Mac开发人员程序(仅限ios)时创建的,但在创建新的测试用户之后,问题就消失了。