Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 04-04-2011, 08:33 PM   #1 (permalink)
ppn
Registered Member
 
Join Date: Oct 2010
Posts: 45
ppn is on a distinguished road
Default In App purchase - hide button when complete

I'm implementing an in app purchase and everything works fine in the sandbox environment but I can't seem to hide the "upgrade" button once the purchase is complete. I have a bool value to store whether the app has been purchased but after the purchase, I need to go to another view and come back before the upgrade button is hidden.

Any suggestions? I've followed the example in this website for the in app purchase template. Is there a way to send a notification to my main view and request it to hide the button?

Code:
- (IBAction)upgrade:(id)sender{
    InAppPurchase *inAppPurchase = [[InAppPurchase alloc] init];
    [inAppPurchase requestProUpgradeProductData];
    [inAppPurchase purchaseProUpgrade];
    if ([[NSUserDefaults standardUserDefaults] boolForKey:kupgradePurchased] == YES) {
        upgrade.hidden = YES;
    }
}

Last edited by ppn; 04-04-2011 at 09:02 PM.
ppn is offline   Reply With Quote
Old 04-08-2011, 01:54 PM   #2 (permalink)
Registered Member
 
twild's Avatar
 
Join Date: Apr 2009
Posts: 107
twild is on a distinguished road
Default

Are you sure the purchase has been completed before you check that it has been purchased? Probably not

You should probably put the "hide button" code in some type of delegate.
twild is offline   Reply With Quote
Old 04-08-2011, 09:26 PM   #3 (permalink)
ppn
Registered Member
 
Join Date: Oct 2010
Posts: 45
ppn is on a distinguished road
Default

That's the thing. It's not complete before I check for it. Does the in app purchase return anything once the purchase is complete? Can the in app purchase call on anything to hide the button for me?
ppn is offline   Reply With Quote
Old 04-08-2011, 09:53 PM   #4 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

Your main view can also register to get a notification. Just repeat this line here in your main view, at some point before the purchase occurs:
Code:
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
Then, in your main view, write a new function that updates your UI instead of updating the transactions:
Code:
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
    //Update your UI in here
}
__________________
My development blog: http://jrinn.com
JasonR is offline   Reply With Quote
Old 04-09-2011, 12:38 AM   #5 (permalink)
ppn
Registered Member
 
Join Date: Oct 2010
Posts: 45
ppn is on a distinguished road
Default

If I put the line below then I get warning: Sending 'MainViewController' to parameter of incompatible type 'id<SKPaymentTransactionObserver'. I don't have all my inapp purchase in my mainviewcontroller.

Code:
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
Should I put:

Code:
[[SKPaymentQueue defaultQueue] addTransactionObserver:inAppPurchase];
Since I allocated and initialized an instance of InAppPurchase in my main view controller
ppn is offline   Reply With Quote
Old 04-09-2011, 03:59 PM   #6 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

Which ever is easier to do the UI update in. You could just add <SKPaymentTransactionObserver> to your MainViewController as well.
__________________
My development blog: http://jrinn.com
JasonR is offline   Reply With Quote
Old 04-10-2011, 02:34 PM   #7 (permalink)
ppn
Registered Member
 
Join Date: Oct 2010
Posts: 45
ppn is on a distinguished road
Default

It doesn't work.

Here's what I have in my mainview.h file:

Code:
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate, QuizViewControllerDelegate, LessonTableViewControllerDelegate, TabBarViewControllerDelegate, SKPaymentTransactionObserver>
In my mainview.m file I have. I put a debug code and when I finish with the in app purchase, it doesn't look like the updatdTransaction method is being called. The debug code doesn't show up on the console. I have to go to another view and then come back for the upgrade button to be hidden.

Any idea why it's not being called?

Code:
- (IBAction)upgrade:(id)sender{
    if ([[NSUserDefaults standardUserDefaults] boolForKey:kupgradePurchased] == YES) {
        upgrade.hidden = YES;
    } else {
        if ([SKPaymentQueue canMakePayments]) {
            InAppPurchase *inAppPurchase = [[InAppPurchase alloc] init];
            [inAppPurchase requestProUpgradeProductData];
            [inAppPurchase purchaseProUpgrade];
            [[SKPaymentQueue defaultQueue] addTransactionObserver:inAppPurchase];
        } else {
            [self purchasesDisabled];
        }
    }
}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
    debug(@"Update Transaction being called");
    if ([[NSUserDefaults standardUserDefaults] boolForKey:kupgradePurchased] == YES) {
       upgrade.hidden = YES;
    }    
}
ppn is offline   Reply With Quote
Old 04-10-2011, 05:41 PM   #8 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,586
JasonR is on a distinguished road
Default

You added the InAppPurchase object as your observer, but the method you want called is in MainViewController. Which way do you want it? It looks to me like you should replace inAppPurchase with self in that line. And maybe even move it to be before the InAppPurchase alloc line.
__________________
My development blog: http://jrinn.com
JasonR is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 378
16 members and 362 guests
AyClass, baja_yu, checkright, dre, epaga, fvisticot, givensur, Meoz, Newbie123, Objective Zero, Punkjumper, reficul, sacha1996, skrew88, tomtom100
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,642
Threads: 94,110
Posts: 402,857
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pinacate
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:32 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0