

Nextrek
@ 67
Nextrek / iOS / Emmanuele Rossi / Trivagolando / Trivagolando / InfoVC.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
// // InfoVC.m // Foresta // // Created by Fabrizio on 18/12/12. // Copyright (c) 2012 Odyssey. All rights reserved. // #import "InfoVC.h" @interface InfoVC () { SKProductsRequest *prodRequest; } @end @implementation InfoVC @synthesize version; @synthesize titleLabel; @synthesize inappObserver; @synthesize donateBtn; @synthesize restoreBtn; @synthesize activityIndicator; @synthesize backBtn; @synthesize creativeWebView; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [creativeWebView loadRequest:[NSURLRequest requestWithURL:CreativeCommons]]; if(!DATAMANAGER.purchased) { inappObserver = [[InAppPurchaseObserver alloc] init]; if ([SKPaymentQueue canMakePayments]) { // Yes, In-App Purchase is enabled on this device! // Proceed to fetch available In-App Purchase items. // Replace "Your IAP Product ID" with your actual In-App Purchase Product ID, // fetched from either a remote server or stored locally within your app. [activityIndicator startAnimating]; prodRequest = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject: @"RemoveADV_Trivagolando"]]; prodRequest.delegate = self; [prodRequest start]; } else { // Notify user that In-App Purchase is disabled via button text. donateBtn.enabled = NO; } } [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(purchasing) name:@"purchasing" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(paymentComplete) name:@"paymentComplete" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(paymentFailed) name:@"paymentFailed" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(paymentRestored) name:@"paymentRestored" object:nil]; titleLabel.text = APP_NAME; version.text = [NSString stringWithFormat:@"v. %@", APP_VERSION]; } - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { if(webView == creativeWebView && [DATAMANAGER testConnection] && navigationType == UIWebViewNavigationTypeLinkClicked) { [[UIApplication sharedApplication] openURL:[request URL]]; } return YES; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void) purchasing { [activityIndicator startAnimating]; backBtn.enabled = NO; } - (void) paymentComplete { [activityIndicator stopAnimating]; DATAMANAGER.purchased = YES; [DATAMANAGER savePurchase]; backBtn.enabled = YES; UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Pagamento avvenuto con successo" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [myAlertView show]; } - (void) paymentFailed { [activityIndicator stopAnimating]; DATAMANAGER.purchased = NO; [DATAMANAGER savePurchase]; backBtn.enabled = YES; UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Pagamento non avvenuto, ritenta" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [myAlertView show]; } - (void) paymentRestored { [activityIndicator stopAnimating]; DATAMANAGER.purchased = YES; [DATAMANAGER savePurchase]; backBtn.enabled = YES; UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Restore avvenuto con successo" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [myAlertView show]; } #pragma mark - #pragma mark IBActions - (IBAction) donate { // Replace "Your IAP Product ID" with your actual In-App Purchase Product ID. SKPayment *paymentRequest = [SKPayment paymentWithProductIdentifier: @"RemoveADV_Trivagolando"]; // Assign an Observer class to the SKPaymentTransactionObserver, // so that it can monitor the transaction status. [[SKPaymentQueue defaultQueue] addTransactionObserver:inappObserver]; // Request a purchase of the selected item. [[SKPaymentQueue defaultQueue] addPayment:paymentRequest]; } - (IBAction) restore { [activityIndicator stopAnimating]; [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; [activityIndicator startAnimating]; } -(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue { [self paymentRestored]; } -(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error { [activityIndicator stopAnimating]; } - (IBAction) close { prodRequest.delegate = nil; [self dismissModalViewControllerAnimated:YES]; } #pragma mark - Store Kit // Store Kit returns a response from an SKProductsRequest. - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { [activityIndicator stopAnimating]; // Populate the inappBuy button with the received product info. SKProduct *validProduct = nil; int count = [response.products count]; if (count>0) { validProduct = [response.products objectAtIndex:0]; } if (!validProduct) { donateBtn.enabled = NO; return; } donateBtn.enabled = YES; } @end |
Commits for Nextrek/iOS/Emmanuele Rossi/Trivagolando/Trivagolando/InfoVC.m
Revision | Author | Commited | Message |
---|---|---|---|
67 |
![]() |
Thu 23 Jan, 2014 14:31:55 +0000 | Emmanuele Rossi apps |