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

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 12, 2010, 11:36 AM   #1
FreddieMac2
macrumors newbie
 
Join Date: May 2010
StoreKit help

Hello,

I am working with StoreKit and I have implemented code that gives me a successful message coming back from the Sandbox environment. The only issue is that nothing is firing to let my app know the transaction has been successful.

I do have a successful function and the app delegate is defined:
Code:
- (void)completeTransaction:(SKPaymentTransaction *)transaction
{
    [self recordTransaction:transaction];
    [self provideContent:transaction.payment.productIdentifier];
    [self finishTransaction:transaction wasSuccessful:YES];
    NSLog(@"Successful Transaction!");
}
I never see "Successful Transaction" in on the console. Any advise on how to debug this issue?

FM

Last edited by SilentPanda; Aug 12, 2010 at 12:23 PM. Reason: code tags
FreddieMac2 is offline   0 Reply With Quote
Old Aug 12, 2010, 12:30 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Basic debugging strategy: Work your way up.

Wherever completeTransaction: is called from, set a breakpoint on that method and see if it's called. Continue working your way up the call chain until you reach the paymentQueue:updatedTransactions: method. Breakpoint or log that method and make sure it's being called.

Post the code for your paymentQueue:updatedTransactions: code.

Post the code that shows your observer being added.
chown33 is offline   0 Reply With Quote
Old Aug 12, 2010, 03:49 PM   #3
FreddieMac2
Thread Starter
macrumors newbie
 
Join Date: May 2010
Quote:
Originally Posted by chown33 View Post
Basic debugging strategy: Work your way up.

Wherever completeTransaction: is called from, set a breakpoint on that method and see if it's called. Continue working your way up the call chain until you reach the paymentQueue:updatedTransactions: method. Breakpoint or log that method and make sure it's being called.

Post the code for your paymentQueue:updatedTransactions: code.

Post the code that shows your observer being added.
based on someone clicking a buy link in a UIWebView
Code:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
	if (navigationType == UIWebViewNavigationTypeLinkClicked) {
		NSURL *url = [request URL];
		NSString *myItem = [[url path] lastPathComponent];
		myProductID = myItem;
		
		[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
		[self canMakePurchases];
		[self purchaseProduct];
		return NO;
	}	
	return YES;   
}
pulled from the apple website
Code:
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions)
    {
		NSLog(@"Transaction State: %@",transaction.transactionState);
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                [self failedTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
                break;
            default:
                break;
        }
    }
}


//
// call this before making a purchase
//
- (BOOL)canMakePurchases
{
    return [SKPaymentQueue canMakePayments];
}

//
// kick off the upgrade transaction
//
- (void)purchaseProduct{
    SKPayment *payment = [SKPayment paymentWithProductIdentifier:myProductID];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}
FreddieMac2 is offline   0 Reply With Quote
Old Aug 12, 2010, 04:34 PM   #4
chown33
macrumors 603
 
Join Date: Aug 2009
Apply more of the "Work your way up" debugging strategy.

Your paymentQueue:updatedTransactions: method contains an NSLog. What, if anything, is it logging? Post any output.

The paymentQueue:updatedTransactions: method only logs if the NSArray isn't empty. Add logging that will appear if the NSArray is empty. Post any output.

Your shouldStartLoadWithRequest method has no logging. How do you know it's being called? Set a breakpoint or add an NSLog to confirm. Post any output.
chown33 is offline   0 Reply With Quote
Old Aug 13, 2010, 08:41 AM   #5
FreddieMac2
Thread Starter
macrumors newbie
 
Join Date: May 2010
Quote:
Originally Posted by chown33 View Post
Apply more of the "Work your way up" debugging strategy.

Your paymentQueue:updatedTransactions: method contains an NSLog. What, if anything, is it logging? Post any output.

The paymentQueue:updatedTransactions: method only logs if the NSArray isn't empty. Add logging that will appear if the NSArray is empty. Post any output.

Your shouldStartLoadWithRequest method has no logging. How do you know it's being called? Set a breakpoint or add an NSLog to confirm. Post any output.

Thank you for the continued input, I have been attempting to debug as you suggest, which is the normal way I do it but these functions are not being called but I am receiving back a success message from the sandbox environment that shows as an alert, but does not seem to fire any of my functions. I do have the delegate setup, so I am not sure what I am doing wrong. the shouldStartLoadWithRequest is working because the [self purchaseProduct] is called and alert messages begin showing on the screen. Once that happens none of my other functions are fired, but again, I do receive a success message from the sandbox environment.
FreddieMac2 is offline   0 Reply With Quote
Old Aug 13, 2010, 10:34 AM   #6
chown33
macrumors 603
 
Join Date: Aug 2009
Post your logged output.
Don't describe it. Post it.

When all you do is describe it, no one can see the ordering or timing.

Add logging to your shouldStartLoadWithRequest and post its output in sequence. This will clearly identify the beginning of the sequence.

While the transaction is occurring, are you in a runloop or not?


EDIT:
Code:
[self canMakePurchases];
This code is wrong.

The canMakePurchases method returns a BOOL, which is being ignored. The BOOL should be tested in an 'if' statement and used to control whether purchaseProduct is run or not.

Quote:
sandbox environment that shows as an alert
Is it one of your alerts, or one provided by the system? Exactly what does it say?

Quote:
and alert messages begin showing
Do you mean the NSLog messages or some other alert messages? If you'd posted the logged output, we could see this ourselves.

Last edited by chown33; Aug 13, 2010 at 11:06 AM.
chown33 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
How to cancel a StoreKit purchase programmatically as a timeout troop231 iPhone/iPad Programming 0 Jul 9, 2013 05:46 PM

Forum Jump

All times are GMT -5. The time now is 02:17 PM.

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

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