jeudi 26 mars 2015

Obtaining a complete NSString from one class to another for the title of a UIButton

I have a simple application and I am now implementing In App Purchases. The layout of the problem at hand is simple:



  • I have a IAPViewController which contains the elements like a UIButton and UILabel

  • I have a e100EntriesPurchase which is what is doing the actual IAPs.


When the user clicks on an element like a UIButton in the IAPViewController, it invokes a method in the e100EntriesPurchase class which shows a UIAlertView to the user. The otherButtonTitle has a formatted text to show the price in your local country.



- (void)displayStoreUI
{
// Obtain formatted price
[self obtainPurchasePricing];

NSLog(@"HERE THE PRICE IS %@", self.productPrice);

NSString *obtainedProductPrice = self.productPrice;
NSLog(@"THE OBTAINED PRODUCT PRICE IS %@", obtainedProductPrice);

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:self.productBeingPurchased.localizedTitle message:self.productBeingPurchased.localizedDescription delegate:self.delegate cancelButtonTitle:obtainedProductPrice otherButtonTitles:@"Maybe later", nil];
alertView.tag = 999;
[alertView show];
}

- (NSString *)obtainPurchasePricing
{
// Displays Local Currency
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.formatterBehavior = NSNumberFormatterBehavior10_4;
formatter.numberStyle = NSNumberFormatterCurrencyStyle;
formatter.locale = self.productBeingPurchased.priceLocale;
self.productPrice = [NSString stringWithFormat:@"Buy this for %@", [formatter stringFromNumber:self.productBeingPurchased.price]];
NSLog(@"The price is %@", self.productPrice);
return self.productPrice;
}


All of the NSLogs are showing the price appropriately.


Now from my IAPViewController, I want the title of the UIButton to be the same as what it is set in the obtainPurchasePricing method, so:



NSString *obtainedPrice = [self.e100EntriesPurchase obtainPurchasePricing];
[self.iap100Button setTitle:obtainedPrice forState:UIControlStateNormal];
NSLog(@"The price is %@", obtainedPrice);


The problem I am facing is that the title of the UIButton is "Buy Now for (null)". The NSLog also doesn't show the actual price. This code above is in the viewDidLoad of the IAPViewController.


The properties in the e100EntriesPurchase class are:



@property (nonatomic, strong) SKProduct *productBeingPurchased;
@property (nonatomic, strong) NSString *productPrice;


What am I missing to obtain the actual price?


Any thoughts on this would really be appreciated!




Aucun commentaire:

Enregistrer un commentaire