Example #1
0
        // Here we handle our WatchKit activity handoff request. We'll take the dictionary passed in as part of the activity's userInfo property, and immediately
        // present a payment sheet. If you're using handoff to allow WatchKit apps to request Apple Pay payments you try to display the payment sheet as soon as
        // possible.
        public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
        {
            // Create a new product detail view controller using the supplied product.
            var rawDictionary = userActivity.UserInfo? ["product"] as NSDictionary;

            if (rawDictionary != null)
            {
                var     productContainer = new ProductContainer(rawDictionary);
                Product product          = productContainer.Product;

                // Firstly, we'll create a product detail page. We can instantiate it from our storyboard...
                var viewController = (ProductTableViewController)RootViewController?.Storyboard?.InstantiateViewController("ProductTableViewController");

                // Manually set the product we want to display.
                if (viewController != null)
                {
                    viewController.Product = product;

                    // The rootViewController should be a navigation controller. Pop to it if needed.
                    RootViewController?.PopToRootViewController(false);

                    // Push the view controller onto our app, so it's the first thing the user sees.
                    RootViewController?.PushViewController(viewController, false);

                    // We also want to immediately show the payment sheet, so we'll trigger that too.
                    viewController.ApplyPayButtonClicked();
                }
            }
            return(true);
        }
		void MakePaymentPressed ()
		{
			// We'll send the product as a dictionary, and convert it to a `Product`
			// value in our app delegate.
			var product = new ProductContainer {
				Name = "Example Charge",
				Description = "An example charge made by a WatchKit Extension",
				Price = "14.99"
			};

			// Create our activity handoff type (registered in the iOS app's Info.plist).
			var activityType = AppConfiguration.UserActivity.Payment;

			// Use Handoff to route the wearer to the payment controller on phone
			var userInfo = new NSDictionary ("product", product.Dictionary);
			UpdateUserActivity (activityType, userInfo, null);

			// Tell the user to use handoff to pay.
			StatusLabel.SetText ("Use handoff to pay!");
		}