Im trying to update my ui label for a consumable purchase but its not updating after the purchase. It only updates if i logout and back in.
Heres what i did:
The coin label is not updating.
Heres what i did:
Code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)PurchaseProduct:(id)sender{
[[InAppPurchaseManager InAppPurchaseManagerSharedInstance] PurchaseProductWithNumber:[sender tag] Delegate:self WithSelector:@selector(Purchased:) WithErrorSelector:@selector(Error:)];
}
-(IBAction)Restore:(id)sender{
[[InAppPurchaseManager InAppPurchaseManagerSharedInstance] Restore_ProductsWithDelegate:self WithSelector:@selector(Purchased:) WithErrorSelector:@selector(Error:)];
}
-(void)Purchased:(NSString*)product{
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"ads"];
if ([product isEqualToString:Coins_500]) {
[self AddCoins:100];
}
if ([product isEqualToString:Coins_1000]) {
[self AddCoins:300];
}
if ([product isEqualToString:Coins_3000]) {
[self AddCoins:1000];
}
if ([product isEqualToString:Coins_8000]) {
[self AddCoins:3000];
}
if ([product isEqualToString:Coins_25000]) {
[self AddCoins:10000];
}
if ([product isEqualToString:remove_ads]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"removeads"];
}
//updating label only.
}
-(void)AddCoins:(int)coins{
[[DataHolder DataHolderSharedInstance].UserObject refresh];
[DataHolder DataHolderSharedInstance].UserObject[@"coins"]=[NSNumber numberWithInt:[[DataHolder DataHolderSharedInstance].UserObject[@"coins"] intValue]+coins];
[[DataHolder DataHolderSharedInstance].UserObject saveInBackground];
}
-(void)Error:(NSError*)error{
//[[AppManager AppManagerSharedInstance ] Show_Alert_With_Title:@"Error!" message:@"Unexpected Error Occured.Please Try Again Later"];
}
-(IBAction)Back:(id)sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
The coin label is not updating.
Last edited: