public override void ViewDidLoad() { base.ViewDidLoad(); // Wireup switch ShuffleSwitch.On = PurchaseManager.ShuffleProductsOnPersistence; ShuffleSwitch.ValueChanged += (sender, e) => { // Read new value PurchaseManager.ShuffleProductsOnPersistence = ShuffleSwitch.On; }; // Wireup amount to consume AddProduct.ShouldBeginEditing = delegate(UITextField field){ //Placeholder UIView.BeginAnimations("keyboard"); UIView.SetAnimationDuration(0.3f); MoveView(-170); UIView.CommitAnimations(); return(true); }; AddProduct.ShouldReturn = delegate(UITextField field){ field.ResignFirstResponder(); //this.View.EndEditing(true); UIView.BeginAnimations("keyboard"); UIView.SetAnimationDuration(0.3f); MoveView(0); UIView.CommitAnimations(); //field.Text holds the current value return(true); }; AddProduct.ShouldEndEditing = delegate(UITextField field){ field.ResignFirstResponder(); //this.View.EndEditing(true); UIView.BeginAnimations("keyboard"); UIView.SetAnimationDuration(0.3f); MoveView(0); UIView.CommitAnimations(); //field.Text holds the current value return(true); }; // Stop editing if the user touches the view ViewTouched.AddTarget(async delegate() { // Close the keyboard if displayed AddProduct.EndEditing(true); }); // Wireup the add button AddButton.TouchUpInside += (sender, e) => { // Close the keyboard if displayed AddProduct.EndEditing(true); // Ask iTunes App Store to fetch the product's details if (AddProduct.Text != "") { PurchaseManager.QueryInventory(AddProduct.Text); // Clear AddProduct.Text = ""; } }; // Adjust GUI if we are running against the real iTunes App Store if (!PurchaseManager.SimulateiTunesAppStore) { // Hide the simulation interface AddLabel.Hidden = true; AddProduct.Hidden = true; AddButton.Hidden = true; AddDescription.Hidden = true; } // Wireup reset button ResetButton.TouchUpInside += (caller, e) => { //Verify that the user really wants to erase all purchase information UIAlertView alert = new UIAlertView("WARNING!", "Do you really want to erase all purchase information for this user? This command cannot be undone!", null, "Cancel", "Erase"); //Wireup events alert.CancelButtonIndex = 0; alert.Clicked += (sender, buttonArgs) => { //Did the user verify termination? if (buttonArgs.ButtonIndex == 1) { //Yes, nuke all information _purchaseManager.PurgeProducts(); // Reload the interface with the requested products // Ask the iTunes App Store to return information about available In App Products for sale _purchaseManager.QueryInventory(new string[] { "product.nonconsumable", "feature.nonconsumable", "feature.nonconsumable.fail", "gold.coins.consumable_x25", "gold.coins.consumable_x50", "gold.coins.consumable_x100", "newsletter.freesubscription", "magazine.subscription.duration1month", "antivirus.nonrenewingsubscription.duration6months", "antivirus.nonrenewingsubscription.duration1year", "product.nonconsumable.invalid", "content.nonconsumable.downloadable", "content.nonconsumable.downloadfail", "content.nonconsumable.downloadupdate" }); } }; //Display dialog alert.Show(); }; }
/// <summary> /// Views the did load. /// </summary> public override void ViewDidLoad() { base.ViewDidLoad(); // Wireup amount to consume AmountToConsume.ShouldBeginEditing = delegate(UITextField field){ //Placeholder UIView.BeginAnimations("keyboard"); UIView.SetAnimationDuration(0.3f); MoveView(-170); UIView.CommitAnimations(); return(true); }; AmountToConsume.ShouldReturn = delegate(UITextField field){ field.ResignFirstResponder(); //this.View.EndEditing(true); UIView.BeginAnimations("keyboard"); UIView.SetAnimationDuration(0.3f); MoveView(0); UIView.CommitAnimations(); //field.Text holds the current value return(true); }; AmountToConsume.ShouldEndEditing = delegate(UITextField field){ field.ResignFirstResponder(); //this.View.EndEditing(true); UIView.BeginAnimations("keyboard"); UIView.SetAnimationDuration(0.3f); MoveView(0); UIView.CommitAnimations(); //field.Text holds the current value return(true); }; // Stop editing if the user touches the view ViewTouched.AddTarget(async delegate() { // Close the keyboard if displayed AmountToConsume.EndEditing(true); }); // Wireup the consume button ConsumeButton.TouchUpInside += (object sender, EventArgs e) => { // Close the keyboard if displayed AmountToConsume.EndEditing(true); // Trap all errors try { // Verify int amount = int.Parse(AmountToConsume.Text); int available = PurchaseManager.ProductQuantityAvailable("gold.coins"); // Valid amount? if (amount < 1 || amount > available) { //Display Alert Dialog Box using (var alert = new UIAlertView("Xamarin.InAppPurchase", "Not a valid amount to consume. The amount to consume must be at least one and less than the available amount.", null, "OK", null)) { alert.Show(); } // Abort return; } // Ask the purchase manager to consume the amount PurchaseManager.ConsumeProductQuantity("gold.coins", amount); } catch { //Display Alert Dialog Box using (var alert = new UIAlertView("Xamarin.InAppPurchase", "Not a valid amount to consume.", null, "OK", null)) { alert.Show(); } } }; }