Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Conversion from NSDecimalNumber to string

$
0
0

I've been following the documentation for in-app purchasing on xamarin.com, but have hit a snag. At a certain point after doing iap.RequestProductData(products); where products is a List of product ids, we have to wait for an asynchronous response from the App Store to get price data using NSNotificationCenter:

priceObserver = NSNotificationCenter.DefaultCenter.AddObserver (
  InAppPurchaseManager.InAppPurchaseManagerProductsFetchedNotification,
(notification) => {
   // display code goes here, to handle the response from the App Store
   var info = notification.UserInfo;
   if (info.ContainsKey(NSProductId)) {

Aside from the fact that info.ContainsKey() requires an NSString which has previously not been mentioned or created anywhere in the walkthrough (it's all been basic product id strings up to that point, but not to worry because it's not hard to make an NSString), the code then goes on to:

       var product = (SKProduct) info.ObjectForKey(NSProductId);
       ...
       buyButton.SetTitle ("Buy " + product.Price, UIControlState.Normal); // price display should be localized
   }
}

Which doesn't work, because product.Price is an NSDecimalNumber and this code throws System.InvalidCast.Exception when trying to use it as a string to set the button title.

product.Price.StringValue property doesn't work either, despite the Xamarin Studio popup info suggestion that it provides a string type, and it also throws a cast exception.

Am I missing something? Anyone have any ideas?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>