When in-app purchase completes, how do I get it to bring up a view controller?

Discussion in 'iPhone/iPad Programming' started by jackhdev, May 29, 2011.

  1. jackhdev, May 29, 2011
    Last edited by a moderator: May 30, 2011

    macrumors 6502

    Joined:
    Apr 9, 2011
    Location:
    Bismarck, North Dakota
    #1
    Hi, I have already coded an in-app purchase, but when it completes, how do I get it to bring up a view controller (a user pays to access this view).

    You see where it says: //ADD IN VIEW CONTROLLER COMMAND HERE??? Is that where the command should be added? Could you please write out the lines of code that needs to be inserted there? I'm not a great programmer yet, so any help is truly appreciated!

    Code:
    //
    //  PurchaserViewController.m
    //  Purchaser
    //
    //  Created by Victor Chitjian on 7/31/10.
    //  Copyright __MyCompanyName__ 2010. All rights reserved.
    //
    
    #import "PurchaserViewController.h"
    
    @implementation PurchaserViewController
    
    
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
        [super viewDidLoad];
    	
    	if ([SKPaymentQueue canMakePayments]) {
    		NSLog(@"Parental-controls are disabled");
    		
    		SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.ChillySky.iPadAppVideo.SDKDownload"]];
    		productsRequest.delegate = self;
    		[productsRequest start];
    	} else {
    		NSLog(@"Parental-controls are enabled");
    	}
    }
    
    - (IBAction)purchase {
    	SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.ChillySky.iPadAppVideo.SDKDownload"];
    	[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    	[[SKPaymentQueue defaultQueue] addPayment:payment];
    }
    
    
    
    - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
    	SKProduct *validProduct = nil;
    	int count = [response.products count];
    	if (count > 0) {
    		validProduct = [response.products objectAtIndex:0];
    	} else if (!validProduct) {
    		NSLog(@"No products available");
    	}
    }
    
    - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
    	for (SKPaymentTransaction *transaction in transactions) {
    		switch (transaction.transactionState) {
    			case SKPaymentTransactionStatePurchasing:
    				
    				break;
    				
    			case SKPaymentTransactionStatePurchased:
    				//ADD IN VIEW CONTROLLER COMMAND HERE???
    				
    				[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    				
    				break;
    				
    			case SKPaymentTransactionStateRestored:
    				[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    				
    				break;
    				
    			case SKPaymentTransactionStateFailed:
    				if (transaction.error.code != SKErrorPaymentCancelled) {
    					NSLog(@"An error encounterd");
    				}
    				
    				[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    				
    				break;
    		}
    	}
    }
    
    
    - (void)didReceiveMemoryWarning {
    	// Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
    	
    	// Release any cached data, images, etc that aren't in use.
    }
    
    - (void)viewDidUnload {
    	// Release any retained subviews of the main view.
    	// e.g. self.myOutlet = nil;
    }
    
    
    - (void)dealloc {
        [super dealloc];
    }
    
    @end
     
  2. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    Is this view pushed via a NavigationController?
    U could try
    Code:
        [self.navigationController popToRootViewControllerAnimated:YES];

    Or how is this view, is it a modalview?
    then do*
    Code:
    [self dismissModalViewControllerAnimated:YES];
    if it's a subview that u added
    Code:
    [self.view removeFromSuperview];
    Next time, just pop a little bit more information so we can help u out. :)
     

Share This Page