PDA

View Full Version : StoreKit help




FreddieMac2
Aug 12, 2010, 11:36 AM
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:
- (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



chown33
Aug 12, 2010, 12:30 PM
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.

FreddieMac2
Aug 12, 2010, 03:49 PM
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
- (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
- (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];
}

chown33
Aug 12, 2010, 04:34 PM
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.

FreddieMac2
Aug 13, 2010, 08:41 AM
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.

chown33
Aug 13, 2010, 10:34 AM
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:
[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.

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

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.