PDA

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




jackhdev
May 29, 2011, 10:41 PM
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!

//
// 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



jnoxx
May 30, 2011, 02:42 AM
Is this view pushed via a NavigationController?
U could try
[self.navigationController popToRootViewControllerAnimated:YES];


Or how is this view, is it a modalview?
then do*
[self dismissModalViewControllerAnimated:YES];

if it's a subview that u added
[self.view removeFromSuperview];

Next time, just pop a little bit more information so we can help u out. :)