public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); // setup the observer to wait for prices to come back from StoreKit <- AppStore priceObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppPurchaseManager.InAppPurchaseManagerProductsFetchedNotification, (notification) => { var info = notification.UserInfo; var NSimagesProductId = new NSString(hostedImagesProductId); var NSfilesystemProductId = new NSString(hostedFilesystemProductId); if (info == null) { // if info is null, probably NO valid prices returned, therefore it doesn't exist at all hostedImagesDescription.Text = "check iTunes connect setup"; hostedFilesystemDescription.Text = "check iTunes connect setup"; hostedImagesButton.SetTitle("invalid product id", UIControlState.Disabled); hostedFilesystemButton.SetTitle("invalid product id", UIControlState.Disabled); } else { // we only update the button with a price if the user hasn't already purchased it if (!hostedImagesPurchased && info.ContainsKey(NSimagesProductId)) { pricesLoaded = true; var product = (SKProduct)info.ObjectForKey(NSimagesProductId); Console.WriteLine("Product id: " + product.ProductIdentifier); Console.WriteLine("Product title: " + product.LocalizedTitle); Console.WriteLine("Product description: " + product.LocalizedDescription); Console.WriteLine("Product price: " + product.Price); Console.WriteLine("Product l10n price: " + product.LocalizedPrice()); Console.WriteLine("Product downloadable: " + product.Downloadable); // iOS6 Console.WriteLine("Product version: " + product.DownloadContentVersion); // iOS6 if (product.DownloadContentLengths != null) { Console.WriteLine("Product length: " + product.DownloadContentLengths[0]); // iOS6 } hostedImagesButton.Enabled = true; hostedImagesTitle.Text = product.LocalizedTitle; hostedImagesDescription.Text = product.LocalizedDescription; hostedImagesButton.SetTitle("Buy " + product.LocalizedPrice(), UIControlState.Normal); } // we only update the button with a price if the user hasn't already purchased it if (!hostedFilesystemPurchased && info.ContainsKey(NSfilesystemProductId)) { pricesLoaded = true; var product = (SKProduct)info.ObjectForKey(NSfilesystemProductId); Console.WriteLine("Product id: " + product.ProductIdentifier); Console.WriteLine("Product title: " + product.LocalizedTitle); Console.WriteLine("Product description: " + product.LocalizedDescription); Console.WriteLine("Product price: " + product.Price); Console.WriteLine("Product l10n price: " + product.LocalizedPrice()); Console.WriteLine("Product downloadable: " + product.Downloadable); // iOS6 Console.WriteLine("Product version: " + product.DownloadContentVersion); // iOS6 if (product.DownloadContentLengths != null) { Console.WriteLine("Product length: " + product.DownloadContentLengths[0]); // iOS6 } hostedFilesystemButton.Enabled = true; hostedFilesystemTitle.Text = product.LocalizedTitle; hostedFilesystemDescription.Text = product.LocalizedDescription; hostedFilesystemButton.SetTitle("Buy " + product.LocalizedPrice(), UIControlState.Normal); } } }); // only if we can make payments, request the prices if (iap.CanMakePayments()) { // now go get prices, if we don't have them already if (!pricesLoaded) { iap.RequestProductData(products); // async request via StoreKit -> App Store } } else { // can't make payments (purchases turned off in Settings?) hostedImagesButton.SetTitle("AppStore disabled", UIControlState.Disabled); hostedFilesystemButton.SetTitle("AppStore disabled", UIControlState.Disabled); } // update the buttons before displaying, to reflect past purchases UpdateButtons(); priceObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppPurchaseManager.InAppPurchaseManagerTransactionSucceededNotification, (notification) => { // update the buttons after a successful purchase UpdateButtons(); }); requestObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppPurchaseManager.InAppPurchaseManagerRequestFailedNotification, (notification) => { // TODO: Console.WriteLine("Request Failed"); hostedImagesButton.SetTitle("Network down?", UIControlState.Disabled); hostedFilesystemButton.SetTitle("Network down?", UIControlState.Disabled); }); }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); // setup the observer to wait for prices to come back from StoreKit <- AppStore priceObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppPurchaseManager.InAppPurchaseManagerProductsFetchedNotification, (notification) => { var info = notification.UserInfo; var NSgreyscaleProductId = new NSString(greyscaleProductId); var NSsepiaProductId = new NSString(sepiaProductId); // we only update the button with a price if the user hasn't already purchased it if (!greyscalePurchased && info.ContainsKey(NSgreyscaleProductId)) { pricesLoaded = true; var product = (SKProduct)info.ObjectForKey(NSgreyscaleProductId); Console.WriteLine("Product id: " + product.ProductIdentifier); Console.WriteLine("Product title: " + product.LocalizedTitle); Console.WriteLine("Product description: " + product.LocalizedDescription); Console.WriteLine("Product price: " + product.Price); Console.WriteLine("Product l10n price: " + product.LocalizedPrice()); greyscaleButton.Enabled = true; greyscaleTitle.Text = product.LocalizedTitle; greyscaleDescription.Text = product.LocalizedDescription; greyscaleButton.SetTitle("Buy " + product.LocalizedPrice(), UIControlState.Normal); } // we only update the button with a price if the user hasn't already purchased it if (!sepiaPurchased && info.ContainsKey(NSsepiaProductId)) { pricesLoaded = true; var product = (SKProduct)info.ObjectForKey(NSsepiaProductId); Console.WriteLine("Product id: " + product.ProductIdentifier); Console.WriteLine("Product title: " + product.LocalizedTitle); Console.WriteLine("Product description: " + product.LocalizedDescription); Console.WriteLine("Product price: " + product.Price); Console.WriteLine("Product l10n price: " + product.LocalizedPrice()); sepiaButton.Enabled = true; sepiaTitle.Text = product.LocalizedTitle; sepiaDescription.Text = product.LocalizedDescription; sepiaButton.SetTitle("Buy " + product.LocalizedPrice(), UIControlState.Normal); } }); // only if we can make payments, request the prices if (iap.CanMakePayments()) { // now go get prices, if we don't have them already if (!pricesLoaded) { iap.RequestProductData(products); // async request via StoreKit -> App Store } } else { // can't make payments (purchases turned off in Settings?) greyscaleButton.SetTitle("AppStore disabled", UIControlState.Disabled); sepiaButton.SetTitle("AppStore disabled", UIControlState.Disabled); } // update the buttons before displaying, to reflect past purchases UpdateButtons(); priceObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppPurchaseManager.InAppPurchaseManagerTransactionSucceededNotification, (notification) => { // update the buttons after a successful purchase UpdateButtons(); }); requestObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppPurchaseManager.InAppPurchaseManagerRequestFailedNotification, (notification) => { // TODO: Console.WriteLine("Request Failed"); greyscaleButton.SetTitle("Network down?", UIControlState.Disabled); sepiaButton.SetTitle("Network down?", UIControlState.Disabled); }); }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); // setup the observer to wait for prices to come back from StoreKit <- AppStore priceObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppPurchaseManager.InAppPurchaseManagerProductsFetchedNotification, (notification) => { NSDictionary info = notification.UserInfo; var NSgreyscaleProductId = new NSString(greyscaleProductId); var NSsepiaProductId = new NSString(sepiaProductId); if (info == null) { // if info is null, probably NO valid prices returned, therefore it doesn't exist at all greyscaleDescription.Text = "check iTunes connect setup"; sepiaDescription.Text = "check iTunes connect setup"; greyscaleButton.SetTitle("invalid product id", UIControlState.Disabled); sepiaButton.SetTitle("invalid product id", UIControlState.Disabled); return; } // we only update the button with a price if the user hasn't already purchased it if (!greyscalePurchased && info.ContainsKey(NSgreyscaleProductId)) { pricesLoaded = true; var product = (SKProduct)info [NSgreyscaleProductId]; Print(product); SetVisualState(greyscaleButton, greyscaleTitle, greyscaleDescription, product); } // we only update the button with a price if the user hasn't already purchased it if (!sepiaPurchased && info.ContainsKey(NSsepiaProductId)) { pricesLoaded = true; var product = (SKProduct)info.ObjectForKey(NSsepiaProductId); Print(product); SetVisualState(sepiaButton, sepiaTitle, sepiaDescription, product); } }); // only if we can make payments, request the prices if (iap.CanMakePayments()) { // now go get prices, if we don't have them already if (!pricesLoaded) { iap.RequestProductData(products); // async request via StoreKit -> App Store } } else { // can't make payments (purchases turned off in Settings?) greyscaleButton.SetTitle("AppStore disabled", UIControlState.Disabled); sepiaButton.SetTitle("AppStore disabled", UIControlState.Disabled); } // update the buttons before displaying, to reflect past purchases UpdateButtons(); priceObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppPurchaseManager.InAppPurchaseManagerTransactionSucceededNotification, (notification) => { // update the buttons after a successful purchase UpdateButtons(); }); requestObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppPurchaseManager.InAppPurchaseManagerRequestFailedNotification, (notification) => { // TODO: Console.WriteLine("Request Failed"); greyscaleButton.SetTitle("Network down?", UIControlState.Disabled); sepiaButton.SetTitle("Network down?", UIControlState.Disabled); }); }