StoreKit help

Discussion in 'iOS Programming' started by FreddieMac2, Aug 12, 2010.

  1. macrumors newbie

    Joined:
    May 9, 2010
    #1
    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
     
  2. macrumors 603

    Joined:
    Aug 9, 2009
    #2
    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.
     
  3. thread starter macrumors newbie

    Joined:
    May 9, 2010
    #3
    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];
    }
    
     
  4. macrumors 603

    Joined:
    Aug 9, 2009
    #4
    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.
     
  5. thread starter macrumors newbie

    Joined:
    May 9, 2010
    #5

    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.
     
  6. macrumors 603

    Joined:
    Aug 9, 2009
    #6
    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.

    Is it one of your alerts, or one provided by the system? Exactly what does it say?

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

Share This Page