public void Initialize() { this._customPaymentObserver = new CustomPaymentObserver(this); SKPaymentQueue.DefaultQueue.AddTransactionObserver(this._customPaymentObserver); this._queryInventoryObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppQueryInventoryNotification, (notification) => { var info = notification.UserInfo; if (info == null) { // TODO: Had to put this in so it wouldn't crash, needs a revisit return; } var practiceModeProductId = new NSString(this.PracticeModeProductId); var product = (SKProduct)info.ObjectForKey(practiceModeProductId); // Update inventory var newProduct = new InAppProduct(); newProduct.ProductId = this.PracticeModeProductId; newProduct.Type = "inapp"; newProduct.Price = this.LocalizedPrice(product); newProduct.PriceCurrencyCode = product.PriceLocale.CurrencyCode; newProduct.Title = product.LocalizedTitle; newProduct.Description = product.LocalizedDescription; App.ViewModel.Products.Add(newProduct); // Notify anyone who needed to know that our inventory is in if (this.OnQueryInventory != null) { this.OnQueryInventory(); } }); this._queryInventoryErrorObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppQueryInventoryErrorNotification, (notification) => { // Notify anyone who needed to know that there was a query inventory error if (this.OnQueryInventoryError != null) { this.OnQueryInventoryError(0, null); } }); this._purchaseProductObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppPurchaseProductNotification, (notification) => { // Notify anyone who needed to know that product was purchased if (this.OnPurchaseProduct != null) { this.OnPurchaseProduct(); } }); this._purchaseProductErrorObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppPurchaseProductErrorNotification, (notification) => { // Notify anyone who needed to know that there was a product purchase error if (this.OnPurchaseProductError != null) { this.OnPurchaseProductError(0, string.Empty); } }); this._restoreProductsObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppRestoreProductsNotification, (notification) => { // Notify anyone who needed to know that products were restored if (this.OnRestoreProducts != null) { this.OnRestoreProducts(); } }); this._restoreProductsErrorObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppRestoreProductsErrorNotification, (notification) => { // Notify anyone who needed to know that there was an error in restoring products if (this.OnRestoreProductsError != null) { this.OnRestoreProductsError(0, null); } }); if (this.CanMakePayments()) { // Async request // StoreKit -> App Store -> ReceivedResponse (see below) this.QueryInventory(); } }
public void Initialize() { this._customPaymentObserver = new CustomPaymentObserver(this); SKPaymentQueue.DefaultQueue.AddTransactionObserver(this._customPaymentObserver); this._queryInventoryObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppQueryInventoryNotification, (notification) => { var info = notification.UserInfo; if (info == null) { // TODO: Had to put this in so it wouldn't crash, needs a revisit return; } var practiceModeProductId = new NSString(this.PracticeModeProductId); var product = (SKProduct)info.ObjectForKey(practiceModeProductId); // Update inventory var newProduct = new InAppProduct(); newProduct.ProductId = this.PracticeModeProductId; newProduct.Type = "inapp"; newProduct.Price = this.LocalizedPrice(product); newProduct.PriceCurrencyCode = product.PriceLocale.CurrencyCode; newProduct.Title = product.LocalizedTitle; newProduct.Description = product.LocalizedDescription; App.ViewModel.Products.Add(newProduct); // Notify anyone who needed to know that our inventory is in if (this.OnQueryInventory != null) { this.OnQueryInventory(); } }); this._queryInventoryErrorObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppQueryInventoryErrorNotification, (notification) => { // Notify anyone who needed to know that there was a query inventory error if (this.OnQueryInventoryError != null) { this.OnQueryInventoryError(0, null); } }); this._purchaseProductObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppPurchaseProductNotification, (notification) => { // Notify anyone who needed to know that product was purchased if (this.OnPurchaseProduct != null) { this.OnPurchaseProduct(); } }); this._purchaseProductErrorObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppPurchaseProductErrorNotification, (notification) => { // Notify anyone who needed to know that there was a product purchase error if (this.OnPurchaseProductError != null) { this.OnPurchaseProductError(0, string.Empty); } }); this._restoreProductsObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppRestoreProductsNotification, (notification) => { // Notify anyone who needed to know that products were restored if (this.OnRestoreProducts != null) { this.OnRestoreProducts(); } }); this._restoreProductsErrorObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppRestoreProductsErrorNotification, (notification) => { // Notify anyone who needed to know that there was an error in restoring products if (this.OnRestoreProductsError != null) { this.OnRestoreProductsError(0, null); } }); if (this.CanMakePayments()) { // Async request // StoreKit -> App Store -> ReceivedResponse (see below) this.QueryInventory(); } }