Easiest Way To Implement Restore Purchase Function To Your App

photo from: mobil-ganz-einfach.de
A Restore Purchase function in any iOS Project/App is necessary. First is because App Store or Apple will not accept your project if they detect In App Purchase on your app. So let's get started, this will be a quick tutorial, since it is quite easy to implement.

You do not have to install third party libraries like MKStoreKit for Restoring Purchases.

First step, import StoreKit.

@import StoreKit;

Above is what we call 'Semantic Import'. Again, one of its advantages is that you'll never have to import the library or framework in your project settings.

Next, in your selector or method, use this code:
// RESTORE PURCHASE
-(void)restorePreviousPurchase{
    // You can add HUDs here to tell the user 'Please Wait...'
   
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

Finally, add these delegate methods:

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
    NSLog(@"received restored transactions: %i", queue.transactions.count);
    if( queue.transactions.count == 0 ) {
        // no restored purchases

    } else {
        // user has purchases before
        // SUCCESS RESTORE PURCHASE, DO YOUR NEXT TASKS HERE
        // example: Show Alert, Store defaults, etc...
    }
    
    // DIMISS THE HUD
}

- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error {
    NSLog(@"%@",error);
    
    // DISMISS THE HUD
    // Do whatever you want here
}

- (void)failedTransaction:(SKPaymentTransaction *)transaction
{
    // DISMISS THE HUD
}

So there you go. I put important comments to the codes above to make your life easier. If you have any questions, just post it in the comment section or contact me. Cheers! Subscribe!

56th Day As An iOS Developer With No Experience

Aggreements, Tax, and Banking Information on iTunesConnect are compulsory to be done. 

SATURDAY - While typing this blog entry, out of the blue, I suddenly remembered my time when I was still working at the fortune 100 company. I was renting an apartment back then, and I used to eat at Wendy's and Mcdonalds near my apartment at dawn.

I would like to share my experience today. I realised that it is necessary that you fill up and give attention to your Agreements, Tax, and Banking information on your ItunesConnect in order for your In App Purchase to be tested. Yes! That's correct, you cannot test your In App Purchases even if you have sandbox users ready, Apple needs contracts first before testing. I told my boss about this and it seemed that he only realised it too, I couldn't believe it. So again, if you want your In App Purchase to be tested in your app, then your information should look like my screenshot above.

53rd Day As An iOS Developer With No Experience

53rd Day As An iOS Developer With No Experience

Thursday - November 12, 2015


1 word: IAP. I learned IAP today, it means, In-App Purchase. But before I discuss the In-App Purchase feature of iOS, I'd like to tell you that I learned how to prevent or turn on/off the auto-rotation of your app. One solution for that will be in your projects' general settings. You can set the Device Orientation of your project/app. Now, this solution can't be applied if you are targeting iPads. And why you ask? Simply because the AppStore will not accept your app if they see that you are supporting iPads yet you did not check all the device orientations.

Next, you put these codes in each of your screens:

- (BOOL)shouldAutorotate
{
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

Okay, going back to the IAP basics that I've learned, I'm going to prepare a tutorial for this. Just a basic. But it can be applied to your app for production.

Lastly, I'll be preparing too a tutorial for Singleton in iOS.

SINGLETON TUTORIAL FOR IOS.