

Nextrek
@ 1058
Nextrek / iOS / SafariArte / trunk / SafariArte / Controllers / IAPVC / IAPVC.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 |
// // IAPVC.m // SafariArte // // Created by IntellitronikaUser on 13/07/15. // Copyright (c) 2015 Nextrek. All rights reserved. // #import "IAPVC.h" #import "SKProduct+priceAsString.h" #import "iapCell.h" #import "GanjaIAPHelper.h" @interface IAPVC () @property (nonatomic, strong) NSMutableArray *products; @property (nonatomic, weak) IBOutlet UITableView *iapTable; @end @implementation IAPVC - (void)viewDidLoad { [super viewDidLoad]; self.title = NSLocalizedString(@"menu_iap", nil); //registro le notifiche per l'iap [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productPurchased:) name:IAPHelperProductPurchasedNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productError:) name:IAPHelperProductErrorNotification object:nil]; self.iapTable.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; [self reload]; } - (void)reload { [ActivityViewFramed showActivityWithSuperView:APPDEL.window]; [[GanjaIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) { [ActivityViewFramed hideActivityView]; if (success) { self.products = [NSMutableArray arrayWithArray:products]; NSLog(@"ITEMS: %@", self.products); [self.iapTable reloadData]; } }]; } #pragma mark - IAP notification - (void) compraProdotto:(SKProduct *) product { [[GanjaIAPHelper sharedInstance] buyProduct:product]; } - (void)productPurchased:(NSNotification *)notification { NSString * productIdentifier = notification.object; /* @"SA_01" @"SA_02" @"SA_03" */ NSLog(@"CREDITS -- BEFORE: %@", DATAMANAGER.user.credits); if ([productIdentifier isEqualToString:@"SA_01"]) { DATAMANAGER.user.credits = [NSNumber numberWithInt:[DATAMANAGER.user.credits intValue] + 50]; } else if([productIdentifier isEqualToString:@"SA_02"]) { DATAMANAGER.user.credits = [NSNumber numberWithInt:[DATAMANAGER.user.credits intValue] + 100]; } else if([productIdentifier isEqualToString:@"SA_03"]) { DATAMANAGER.user.credits = [NSNumber numberWithInt:[DATAMANAGER.user.credits intValue] + 250]; } NSLog(@"CREDITS -- AFTER: %@", DATAMANAGER.user.credits); [DATAMANAGER saveUser]; } - (void)productError:(NSNotification *)notification { NSString * productIdentifier = notification.object; [DATAMANAGER showErrorAlert:self message:productIdentifier tag:101]; } #pragma mark - Table view methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.products count]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 60.0f; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"iapCell"; iapCell *cell = (iapCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]; cell = [topLevelObjects objectAtIndex:0]; } SKProduct *product = [self.products objectAtIndex:indexPath.row]; cell.iapNameValue.text = [NSString stringWithFormat:@"%@\n%@", product.localizedTitle , product.localizedDescription]; cell.iapPriceValue.text = product.priceAsString; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { SKProduct *product = [self.products objectAtIndex:indexPath.row]; [self compraProdotto:product]; [tableView deselectRowAtIndexPath:indexPath animated:NO]; } - (void)customIOS7dialogButtonTouchUpInside: (CustomIOSAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex { if (alertView.tag == 101) { [alertView close]; } } #pragma mark - MemoryWarning - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end |
Commits for Nextrek/iOS/SafariArte/trunk/SafariArte/Controllers/IAPVC/IAPVC.m
Revision | Author | Commited | Message |
---|---|---|---|
1058
![]() |
![]() |
Sat 23 Jan, 2016 15:50:57 +0000 | Apple release. |
622
![]() |
![]() |
Tue 01 Sep, 2015 06:45:34 +0000 | fixed bug alert & cell tableView IAPPVC |
444
![]() |
![]() |
Tue 28 Jul, 2015 14:26:36 +0000 | added customAlertView |
431
![]() |
![]() |
Thu 23 Jul, 2015 06:56:41 +0000 | graphic fixed |
339
![]() |
![]() |
Wed 15 Jul, 2015 09:48:19 +0000 | bug fixing |
299
![]() |
![]() |
Mon 13 Jul, 2015 15:09:57 +0000 | iAP |
295 |
![]() |
Mon 13 Jul, 2015 13:48:00 +0000 | FinalQuizVC constraints update |