steprescott / SCPStoreKitManager

Block based store kit manager for In-App Purchase on iOS 7, 8 & 9 with receipt validation.
MIT License
68 stars 29 forks source link

Restore does not works at all #23

Open avdyushin opened 9 years ago

avdyushin commented 9 years ago

restoreCompletedTransactions has no delegate methods. Seems to be old version in cocoapods

SoundBlaster commented 8 years ago

This can be fixed by custom category

#import <SCPStoreKitManager/SCPStoreKitManager.h>

@interface SCPStoreKitManager (Restore)
-(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error;
-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue;
@end

#import "SCPStoreKitManager+Restore.h"

@interface SCPStoreKitManager ()
@property (nonatomic, copy) PaymentTransactionStateFailed paymentTransactionStateFailedBlock;
@property (nonatomic, copy) PaymentTransactionStateRestored paymentTransactionStateRestoredBlock;
@end

@implementation SCPStoreKitManager (Restore)
-(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
    NSLog(@"restoreCompletedTransactionsFailedWithError %@", error.localizedDescription);
    self.paymentTransactionStateFailedBlock(queue.transactions);
}

-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
    NSLog(@"paymentQueueRestoreCompletedTransactionsFinished");
    self.paymentTransactionStateRestoredBlock(queue.transactions);
}

@end
o-g-sus commented 7 years ago

I had a problem with a "This In-App Purchase Has Aready Been Bought" message but then failing with restoring the item -> http://greensopinion.com/2017/03/22/This-In-App-Purchase-Has-Already-Been-Bought.html

My problem seemed that the a framework was "stealing" the SKPaymentQueue / SKPaymentTransactionObserver events and my app could not restore the item. Calling [[SKPaymentQueue defaultQueue] addTransactionObserver:[SCPStoreKitManager sharedInstance]]; in AppDelegate before adding other frameworks did the job.