Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 10, 2011, 02:28 PM   #1
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
In-App Purchase Issue

Edit: I'm not sure if anything in my first post is terribly relevant to the issue I'm having... maybe it'd be best to skip to my follow up post?

I'd like to make it so that users of my app can pay to remove an iAd banner from it.

There's a "Remove Ads" button just above the banner. Here's the code for when it's hit:

Code:
-(IBAction)removeAds:(id)sender
{
    if ([SKPaymentQueue canMakePayments])
    {
        SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject: @"findItFirstRemoveAds"]];
        request.delegate = self;
        [request start];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"In-App Purchases are Disabled"
                                                        message:@"The ads could not be removed because In-App Purchases are disabled on this device. To change this, go to your device Settings, choose General, then Restrictions, and enable In-App Purchases."
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        alert.delegate = self;
        [alert show];
        [alert release]; 
    }
}
This object is the delegate for the purchase. Initially, my program would crash when it tried to run the next section, but checking the crash logs, I determined that the app store was sending back a response.products array that was empty. So I added a check to see how big the array is. If it's anything other than 1, it has to be an issue, right?

Code:
#pragma mark - SKRequestDelegate
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    if ([response.products count] == 1)
    {
        SKProduct *adRemovalProduct = [response.products objectAtIndex:0];
    
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
        [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
        [numberFormatter setLocale:adRemovalProduct.priceLocale];
    
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:adRemovalProduct.localizedTitle
                                                        message:[NSString stringWithFormat:@"%@ %@", adRemovalProduct.localizedDescription, [numberFormatter stringFromNumber:adRemovalProduct.price], nil]
                                                       delegate:self cancelButtonTitle:@"No Thanks" otherButtonTitles:@"Purchase", nil];
        [alert show];
        [alert release];
        [numberFormatter release];
    }
    
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Such Product"
                                                        message:@"The product you attempted to purchase is not yet available on the App Store. The developer apologizes for any inconvience. Your account was not charged."
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    
    [request autorelease];
}
Now, rather than crash, my app always says that no such product exists (the message I programmed it to display if there's an issue with the array size.)

I've attached a screenshot of what iTunes Connect shows for In-App purchases in my app.

Thumb resize.

It says "Ready to Submit" as the status, but when I click on it, it takes me to a page where I can edit details on it, but the "Submit for Review" button is grayed out, for no apparent reason.

So, can anyone help me out here? What am I doing wrong? I can't imagine Apple actually wants me to submit the binary at this point, because it doesn't make any sense to not be able to test the In-App Purchase feature of my app until after I submit it, does it?

Edit: Before anyone asks, the 512x512 is just a dummy image. I haven't actually made an icon for my app yet.
Attached Thumbnails
Click image for larger version

Name:	In-App Purchase.png
Views:	3827
Size:	117.2 KB
ID:	298437  
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)

Last edited by ArtOfWarfare; Aug 11, 2011 at 07:09 PM.
ArtOfWarfare is offline   0 Reply With Quote
Old Aug 11, 2011, 01:18 AM   #2
ArtOfWarfare
Thread Starter
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
I think I've made some progress by following the detailed walkthrough here:

http://troybrant.net/blog/2010/01/in...l-walkthrough/

Since my prior post, I've:
1.) Prepared my app binary for upload, which entailed changing a few build settings and entitlements and stuff.
2.) Uploaded my app binary for review.
3.) Rejected my own binary.

This has caused the status of my In-App Purchase to become "Waiting for Review". After waiting about four hours, the empty array stopped being returned and I started getting back my localized product description that I'd posted on iTunes Connect.

So... to respond to the fact that the purchase button was pressed on my UIAlertView, I have this:

Code:
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != [alertView cancelButtonIndex])
    {
        [[SKPaymentQueue defaultQueue] addPayment:[SKPayment paymentWithProductIdentifier:@"findItFirstRemoveAds"]];
    }
}
And then the observer gets this:

Code:
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions)
    {
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
            case SKPaymentTransactionStateRestored:
                adsAreRemoved = YES;
                [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"adRemovalPurchased"];
                [[NSUserDefaults standardUserDefaults] synchronize];
                if (self.bannerIsVisible)
                {
                    [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
                    adView.frame = CGRectOffset(adView.frame, 0, adView.frame.size.height);
                    [UIView commitAnimations];
                    self.bannerIsVisible = NO;
                }
                
                [UIView beginAnimations:@"animateEggDropBannerOff" context:NULL];
                eggDropBanner.frame = CGRectOffset(eggDropBanner.frame, 0, eggDropBanner.frame.size.height);
                [UIView commitAnimations];
                
                [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
                
                break;
            case SKPaymentTransactionStateFailed:
                if (transaction.error.code != SKErrorPaymentCancelled)
                {
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Purchase Failed"
                                                                    message:@"Your ad removal purchase has failed for an unknown reason. Your account was not charged."
                                                                   delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                    [alert show];
                    [alert release];
                }
                
                [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
                
                break;
            default:
                break;
        }
    }
}
Now... my issue is, I hit the purchase button, wait for about a minute, and then I get a message saying that the purchase failed.

Two questions:
1.) Why is my purchase failing?
2.) Why doesn't it ever ask for my account name / password? (I feel like if I knew the answer to #2 it might explain #1.)

Edit: I've now also added code to check each of the possible SKError codes... and it returns... none of them! It doesn't return Invalid Client, Payment Cancelled, Payment Invalid, Payment Not Allowed, or even Unknown Error! I therefore have some kind of mystical, super unknown error. Also, it doesn't report that the purchase has failed until 6 and a half minutes after the user told it to make a purchase.
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)

Last edited by ArtOfWarfare; Aug 11, 2011 at 02:35 AM.
ArtOfWarfare is offline   0 Reply With Quote
Old Aug 11, 2011, 08:46 AM   #3
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
You have read the In App Purchase Programming Guide, yeah? Especially the section on "Testing a Store"?
__________________
dejo is online now   0 Reply With Quote
Old Aug 11, 2011, 10:25 AM   #4
Luke Redpath
macrumors 6502a
 
Join Date: Nov 2007
Have you signed out of your regular iTunes account on your test device? You should do this and when prompted in-app, sign in with a test user you have created in iTunes Connect (don't sign in with this user in Settings > Store beforehand).
Luke Redpath is offline   0 Reply With Quote
Old Aug 11, 2011, 10:42 AM   #5
ArtOfWarfare
Thread Starter
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by Luke Redpath View Post
Have you signed out of your regular iTunes account on your test device? You should do this and when prompted in-app, sign in with a test user you have created in iTunes Connect (don't sign in with this user in Settings > Store beforehand).
I had signed out, but when I double checked after reading your post, I found somehow I was still signed in. I signed out again. Checked my in-app purchase. It still fails, still for no known reason, not even SKErrorUnknown. I asked it to log the error code and it gave me -1001. Does anyone know the significance of that?
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote
Old Aug 11, 2011, 02:14 PM   #6
Luke Redpath
macrumors 6502a
 
Join Date: Nov 2007
Quote:
Originally Posted by ArtOfWarfare View Post
I had signed out, but when I double checked after reading your post, I found somehow I was still signed in. I signed out again. Checked my in-app purchase. It still fails, still for no known reason, not even SKErrorUnknown. I asked it to log the error code and it gave me -1001. Does anyone know the significance of that?
FWIW, the sandbox environment seems to have been down for the past few hours. I've been having troubles here too (right as we're about to submit!).
Luke Redpath is offline   0 Reply With Quote
Old Aug 11, 2011, 02:22 PM   #7
ArtOfWarfare
Thread Starter
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by Luke Redpath View Post
FWIW, the sandbox environment seems to have been down for the past few hours. I've been having troubles here too (right as we're about to submit!).
Would it still be capable of giving me the details about the purchase? Would that prevent it from asking me to log in?

Edit: Evidently the answer is "yes" on both accounts, as now, without any changes to my code at all, it works pretty well. Although naming my product "Purchase Ad Removal" is kind of silly as now Apple's automatic confirmation says "Do you really want to buy one Purchase Ad Removal?"
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)

Last edited by ArtOfWarfare; Aug 11, 2011 at 06:52 PM.
ArtOfWarfare is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
iPhone: Cydia purchase verification issue Dee Ann Jailbreaks and iOS Hacks 13 Dec 30, 2013 12:27 AM
Mac app In-app Purchase : Invalid product ID Nobita.ZZZ Mac Programming 0 Feb 19, 2013 05:59 AM
App Store Purchase Issue Oakmhcky21 iOS 6 0 Sep 22, 2012 03:53 AM
How to set-up In App Purchase free trial period in iOS app mr-plef iPhone/iPad Programming 0 Sep 6, 2012 06:47 AM
Lost OS X Lion purchase in app store and iDentify app won't update Stonefly Mac Applications and Mac App Store 3 Jun 12, 2012 09:23 PM

Forum Jump

All times are GMT -5. The time now is 12:44 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC