Showing posts with label iPhone. Show all posts
Showing posts with label iPhone. Show all posts

Thursday, June 12, 2014

iOS In-App Purchase Error - “Cannot connect to iTunes Store”

From Macgasm

It's true, In-App Purchases are awesome.  However, setting it up could drive you crazy.  I've personally spent too much time tracking this one “Cannot connect to iTunes Store” error down, so I decided to document the fix here.

If you are trying to do an In-App Purchase you might encounter this error.  It happens just as you send the product in for payment.  For me, its with a line like this:

SKPayment * payment = [SKPayment paymentWithProduct:product];

The weird thing is that the product is found just fine.  So, I know the connection to the iTunes Store is working fine.  However, it won't finalize the purchase.  It throws an error that gives (in my case) one of two errors: 0 or 1003.  You can find this error number by implementing the following (Which is taken from Ray Wenderlich's excellent IPAHelper):

- (void)failedTransaction:(SKPaymentTransaction *)transaction {
    if (transaction.error.code != SKErrorPaymentCancelled)
        NSLog(@"Transaction error: %@", transaction.error.localizedDescription);
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];


So, here is how I got both error codes to go away:

Error 0 - You must:
  1. Make sure you have accepted all the documentation terms and conditions within  Check under Contracts, Tax and Banking just to make sure.
  2. Make sure you are using a test user within the iPhone you are testing with.  To do this, go to iTunesConnect => Manage Users.  Then add a new test user.  Finally, on the phone you are developing with, go to Settings and sign out as your current user.  Sign in with the new test user you just made.  This should do it!

Error 1003 - This one seems to be a networking problem.  To clear this, I recommend you delete the App from your test device, Clean the project in Xcode, rebuild and re-deploy.

Another thing you should check is that Apple's service is up.  If you hit the following address, and you see no response, it's down.

Once you get In App Purchases working, its pretty sweet.  Good luck, its worth it!

Thursday, February 21, 2013

iPhone Animation Blocks

The demo in action!
Animating with blocks of code is now one of the easiest things to do in iPhone programming. You must wrap your head around the code style (sort of like using Lambda expressions in C#.) Once you do, it's a snap to add really cool animations to your apps.

Download Sample App

I've attached a quick sample app that shows how to animate an image. The example expands and fades-out an image when you click on it. The magic is in the following code:

      // Create animation with two animation functions: alpha and image size  
   [UIView animateWithDuration:1.0  
                                delay: 0.0  
                               options: UIViewAnimationOptionCurveEaseIn  
                                imgMain.alpha = 0.0;  
                                imgMain.bounds = newSize;  
                           completion:^(BOOL finished){  
                                // Now fade it back in to the right size  
                                [UIView animateWithDuration:1.0  
                                                          delay: 0.0  
                                                         imgMain.alpha = 1.0;  
                                                         imgMain.bounds = origSize;  

Note how we can add any number of animations to the block and they all will be executed at the same time. We also can specify what happens when each animation completes.  It is a lot like using the CAAnimationGroup, but in my opinion, much easier.