Beispiel #1
0
        /// <summary>
        /// Finisheds the launching.
        /// </summary>
        /// <returns><c>true</c>, if launching was finisheded, <c>false</c> otherwise.</returns>
        /// <param name="application">Application.</param>
        /// <param name="launchOptions">Launch options.</param>
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Assembly public key
            string value = Xamarin.InAppPurchase.Utilities.Security.Unify(
                new string[] { "1322f985c2",
                               "a34166b24",
                               "ab2b367",
                               "851cc6" },
                new int[] { 0, 1, 2, 3 });

            // Build a window
            Window = new UIWindow(UIScreen.MainScreen.Bounds);

            // Get the defaul view from the storyboard
            mainView = Storyboard.InstantiateInitialViewController() as MainViewController;

            // Display the first view
            Window.RootViewController = mainView;
            Window.MakeKeyAndVisible();

            // Initialize the In App Purchase Manager
                        #if SIMULATED
            PurchaseManager.SimulateiTunesAppStore = true;
                        #else
            PurchaseManager.SimulateiTunesAppStore = false;
                        #endif
            PurchaseManager.PublicKey           = value;
            PurchaseManager.ApplicationUserName = "******";

            // Warn user that the store is not available
            if (PurchaseManager.CanMakePayments)
            {
                Console.WriteLine("Xamarin.InAppBilling: User can make payments to iTunes App Store.");
            }
            else
            {
                //Display Alert Dialog Box
                using (var alert = new UIAlertView("Xamarin.InAppBilling", "Sorry but you cannot make purchases from the In App Billing store. Please try again later.", null, "OK", null))
                {
                    alert.Show();
                }
            }

            // Warn user if the Purchase Manager is unable to connect to
            // the network.
            PurchaseManager.NoInternetConnectionAvailable += () => {
                //Display Alert Dialog Box
                using (var alert = new UIAlertView("Xamarin.InAppBilling", "No open internet connection is available.", null, "OK", null))
                {
                    alert.Show();
                }
            };

            // Show any invalid product queries
            PurchaseManager.ReceivedInvalidProducts += (productIDs) => {
                // Display any invalid product IDs to the console
                Console.WriteLine("The following IDs were rejected by the iTunes App Store:");
                foreach (string ID in productIDs)
                {
                    Console.WriteLine(ID);
                }
                Console.WriteLine(" ");
            };

            // Report the results of the user restoring previous purchases
            PurchaseManager.InAppPurchasesRestored += (count) => {
                // Anything restored?
                if (count == 0)
                {
                    // No, inform user
                    using (var alert = new UIAlertView("Xamarin.InAppPurchase", "No products were available to be restored from the iTunes App Store.", null, "OK", null))
                    {
                        alert.Show();
                    }
                }
                else
                {
                    // Yes, inform user
                    using (var alert = new UIAlertView("Xamarin.InAppPurchase", String.Format("{0} {1} restored from the iTunes App Store.", count, (count > 1) ? "products were" : "product was"), null, "OK", null))
                    {
                        alert.Show();
                    }
                }
            };

            // Report miscellanous processing errors
            PurchaseManager.InAppPurchaseProcessingError += (message) => {
                //Display Alert Dialog Box
                using (var alert = new UIAlertView("Xamarin.InAppPurchase", message, null, "OK", null))
                {
                    alert.Show();
                }
            };

            // Report any issues with persistence
            PurchaseManager.InAppProductPersistenceError += (message) => {
                using (var alert = new UIAlertView("Xamarin.InAppPurchase", message, null, "OK", null))
                {
                    alert.Show();
                }
            };

            // Setup automatic purchase persistance and load any previous purchases
            PurchaseManager.AutomaticPersistenceType     = InAppPurchasePersistenceType.LocalFile;
            PurchaseManager.PersistenceFilename          = "AtomicData";
            PurchaseManager.ShuffleProductsOnPersistence = false;
            PurchaseManager.RestoreProducts();

                        #if SIMULATED
            // 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"
            });

            // Setup the list of simulated purchases to restore when doing a simulated restore of pruchases
            // from the iTunes App Store
            PurchaseManager.SimulatedRestoredPurchaseProducts = "product.nonconsumable,antivirus.nonrenewingsubscription.duration6months,content.nonconsumable.downloadable";
                        #else
            // Ask the iTunes App Store to return information about available In App Products for sale
            PurchaseManager.QueryInventory(new string[] {
                "xam.iap.nonconsumable.widget",
                "xam.iap.subscription.duration1month",
                "xam.iap.subscription.duration1year",
                "xam.iap.subscription.duration3months"
            });
                        #endif

            // Attach the pruchase manager to the Main View
            mainView.AttachToPurchaseManager(Storyboard, PurchaseManager);

            return(true);
        }
Beispiel #2
0
		/// <summary>
		/// Finisheds the launching.
		/// </summary>
		/// <returns><c>true</c>, if launching was finisheded, <c>false</c> otherwise.</returns>
		/// <param name="application">Application.</param>
		/// <param name="launchOptions">Launch options.</param>
		public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
		{
			// Assembly public key
			string value = Xamarin.InAppPurchase.Utilities.Security.Unify (
				new string[] { "1322f985c2", 
					"a34166b24", 
					"ab2b367", 
					"851cc6" }, 
				new int[] { 0,1,2,3 });

			// Build a window
			Window = new UIWindow (UIScreen.MainScreen.Bounds);

			// Get the defaul view from the storyboard
			mainView = Storyboard.InstantiateInitialViewController () as MainViewController;

			// Display the first view
			Window.RootViewController = mainView;
			Window.MakeKeyAndVisible ();

			// Initialize the In App Purchase Manager
			#if SIMULATED
			PurchaseManager.SimulateiTunesAppStore = true;
			#else
			PurchaseManager.SimulateiTunesAppStore = false;
			#endif
			PurchaseManager.PublicKey = value;
			PurchaseManager.ApplicationUserName = "******";

			// Warn user that the store is not available
			if (PurchaseManager.CanMakePayments) {
				Console.WriteLine ("Xamarin.InAppBilling: User can make payments to iTunes App Store.");
			} else {
				//Display Alert Dialog Box
				using(var alert = new UIAlertView("Xamarin.InAppBilling", "Sorry but you cannot make purchases from the In App Billing store. Please try again later.", null, "OK", null))
				{
					alert.Show();	
				}

			}

			// Warn user if the Purchase Manager is unable to connect to
			// the network.
			PurchaseManager.NoInternetConnectionAvailable += () => {
				//Display Alert Dialog Box
				using(var alert = new UIAlertView("Xamarin.InAppBilling", "No open internet connection is available.", null, "OK", null))
				{
					alert.Show();	
				}
			};

			// Show any invalid product queries
			PurchaseManager.ReceivedInvalidProducts += (productIDs) => {
				// Display any invalid product IDs to the console
				Console.WriteLine("The following IDs were rejected by the iTunes App Store:");
				foreach(string ID in productIDs){
					Console.WriteLine(ID);
				}
				Console.WriteLine(" ");
			};

			// Report the results of the user restoring previous purchases
			PurchaseManager.InAppPurchasesRestored += (count) => {
				// Anything restored?
				if (count==0) {
					// No, inform user
					using(var alert = new UIAlertView("Xamarin.InAppPurchase", "No products were available to be restored from the iTunes App Store.", null, "OK", null))
					{
						alert.Show();	
					}
				} else {
					// Yes, inform user
					using(var alert = new UIAlertView("Xamarin.InAppPurchase", String.Format("{0} {1} restored from the iTunes App Store.",count, (count>1) ? "products were" : "product was"), null, "OK", null))
					{
						alert.Show();	
					}
				}
			};

			// Report miscellanous processing errors
			PurchaseManager.InAppPurchaseProcessingError += (message) => {
				//Display Alert Dialog Box
				using(var alert = new UIAlertView("Xamarin.InAppPurchase", message, null, "OK", null))
				{
					alert.Show();	
				}
			};

			// Report any issues with persistence
			PurchaseManager.InAppProductPersistenceError += (message) => {
				using(var alert = new UIAlertView("Xamarin.InAppPurchase", message, null, "OK", null))
				{
					alert.Show();	
				}
			};

			// Setup automatic purchase persistance and load any previous purchases
			PurchaseManager.AutomaticPersistenceType = InAppPurchasePersistenceType.LocalFile;
			PurchaseManager.PersistenceFilename = "AtomicData";
			PurchaseManager.ShuffleProductsOnPersistence = false;
			PurchaseManager.RestoreProducts ();

			#if SIMULATED
			// 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"
			});

			// Setup the list of simulated purchases to restore when doing a simulated restore of pruchases
			// from the iTunes App Store
			PurchaseManager.SimulatedRestoredPurchaseProducts = "product.nonconsumable,antivirus.nonrenewingsubscription.duration6months,content.nonconsumable.downloadable";
			#else
			// Ask the iTunes App Store to return information about available In App Products for sale
			PurchaseManager.QueryInventory (new string[] { 
				"xam.iap.nonconsumable.widget",
				"xam.iap.subscription.duration1month",
				"xam.iap.subscription.duration1year",
				"xam.iap.subscription.duration3months"
			});
			#endif

			// Attach the pruchase manager to the Main View
			mainView.AttachToPurchaseManager (Storyboard, PurchaseManager);
		
			return true;
		}