// 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); }
public override void ConfirmStartTimer(StartTimerIntent intent, Action <StartTimerIntentResponse> completion) { if (togglAPI == null) { var userActivity = new NSUserActivity(startTimerActivityType); userActivity.SetResponseText("Log in to use this shortcut."); completion(new StartTimerIntentResponse(StartTimerIntentResponseCode.FailureNoApiToken, userActivity)); return; } var lastUpdated = SharedStorage.instance.GetLastUpdateDate(); togglAPI.TimeEntries.GetAllSince(lastUpdated) .Subscribe(tes => { // If there are no changes since last sync, or there are changes in the server but not in the app, we are ok if (tes.Count == 0 || tes.OrderBy(te => te.At).Last().At >= lastUpdated) { completion(new StartTimerIntentResponse(StartTimerIntentResponseCode.Ready, null)); } else { var userActivity = new NSUserActivity(startTimerActivityType); userActivity.SetResponseText("Open the app to sync your data, then try again."); completion(new StartTimerIntentResponse(StartTimerIntentResponseCode.FailureSyncConflict, userActivity)); } } ); }
public override void RestoreUserActivityState(NSUserActivity activity) { base.RestoreUserActivityState (activity); Console.Write ("RestoreUserActivityState "); if ((activity.ActivityType == ActivityTypes.Detail) || (activity.ActivityType == ActivityTypes.Add)) { Console.WriteLine ("NSUserActivity " + activity.ActivityType); if (activity.UserInfo == null || activity.UserInfo.Count == 0) { // new todo current = new Task(); } else { // load existing todo var id = activity.UserInfo.ObjectForKey (ActivityKeys.Id).ToString (); current = AppDelegate.Current.TaskMgr.GetTask (Convert.ToInt32 (id)); } } if (activity.ActivityType == CSSearchableItem.ActionType) { Console.WriteLine ("CSSearchableItem.ActionType"); var uid = activity.UserInfo [CoreSpotlight.CSSearchableItem.ActivityIdentifier]; current = AppDelegate.Current.TaskMgr.GetTask (Convert.ToInt32 (uid.Description)); Console.WriteLine ("eeeeeeee RestoreUserActivityState " + uid); } // CoreSpotlight index can get out-of-date, show 'empty' task if the requested id is invalid if (current == null) { current = new Task { Name = "(not found)" }; } }
//Universal Links public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { AppsFlyerLib.Shared.ContinueUserActivity(userActivity, completionHandler); return(true); }
/// <summary> /// Navigates the Webview to the given URL string. /// </summary> /// <param name="url">URL.</param> private void NavigateToURL(string url) { // Properly formatted? if (!url.StartsWith ("http://")) { // Add web url = "http://" + url; } // Display the give webpage WebView.LoadRequest(new NSUrlRequest(NSUrl.FromString(url))); // Invalidate existing Activity if (UserActivity != null) { UserActivity.Invalidate(); UserActivity = null; } // Create a new user Activity to support this tab UserActivity = new NSUserActivity (ThisApp.UserActivityTab4); UserActivity.Title = "Coffee Break Tab"; // Update the activity when the tab's URL changes var userInfo = new NSMutableDictionary (); userInfo.Add (new NSString ("Url"), new NSString (url)); UserActivity.AddUserInfoEntries (userInfo); // Inform Activity that it has been updated UserActivity.BecomeCurrent (); // Log User Activity Console.WriteLine ("Creating User Activity: {0} - {1}", UserActivity.Title, url); }
public void HandleCreateNote(INCreateNoteIntent intent, Action <INCreateNoteIntentResponse> completion) { // データ登録 var client = new HttpClient(); client.BaseAddress = new Uri($"{Consts.AzureApiUrl}/"); var item = new Item { Text = intent.Title.SpokenPhrase, Description = ((INTextNoteContent)intent.Content).Text }; var serializedItem = JsonConvert.SerializeObject(item); Task.WaitAll( client.PostAsync($"api/item", new StringContent(serializedItem, Encoding.UTF8, "application/json")) ); var userActivity = new NSUserActivity("INCreateNoteIntent"); var response = new INCreateNoteIntentResponse(INCreateNoteIntentResponseCode.Success, userActivity); response.CreatedNote = new INNote(intent.Title, new[] { intent.Content }, null, null, null, null); completion(response); }
public void AddBeerToIndex(Beer beer) { var activity = new NSUserActivity("com.micjames.beerdrinkin.beerdetails"); if (!string.IsNullOrEmpty(beer.Description)) { var info = new NSMutableDictionary(); info.Add(new NSString("name"), new NSString(beer.Name)); info.Add(new NSString("description"), new NSString(beer.Description)); if (beer?.Image?.MediumUrl != null) { info.Add(new NSString("imageUrl"), new NSString(beer.Image.LargeUrl)); } var attributes = new CSSearchableItemAttributeSet(); attributes.DisplayName = beer.Name; attributes.ContentDescription = beer.Description; var keywords = new NSString[] { new NSString(beer.Name), new NSString("beerName") }; activity.Keywords = new NSSet<NSString>(keywords); activity.ContentAttributeSet = attributes; activity.Title = beer.Name; activity.UserInfo = info; activity.EligibleForSearch = true; activity.EligibleForPublicIndexing = true; activity.BecomeCurrent(); } }
public void AddBeerToIndex(Beer beer) { var activity = new NSUserActivity("com.micjames.beerdrinkin.beerdetails"); if (!string.IsNullOrEmpty(beer.Description)) { var info = new NSMutableDictionary(); info.Add(new NSString("name"), new NSString(beer.Name)); info.Add(new NSString("description"), new NSString(beer.Description)); if (beer?.Image?.MediumUrl != null) { info.Add(new NSString("imageUrl"), new NSString(beer.Image.LargeUrl)); } var attributes = new CSSearchableItemAttributeSet(); attributes.DisplayName = beer.Name; attributes.ContentDescription = beer.Description; var keywords = new NSString[] { new NSString(beer.Name), new NSString("beerName") }; activity.Keywords = new NSSet <NSString>(keywords); activity.ContentAttributeSet = attributes; activity.Title = beer.Name; activity.UserInfo = info; activity.EligibleForSearch = true; activity.EligibleForPublicIndexing = true; activity.BecomeCurrent(); } }
public static NSUserActivity CreateNSUserActivity(Restaurant userInfo) { var activityType = ActivityTypes.View; var activity = new NSUserActivity(activityType); activity.EligibleForSearch = true; // HACK: can result in duplicates with CoreSpotlight activity.EligibleForPublicIndexing = false; activity.EligibleForHandoff = false; activity.Title = "Restaurant " + userInfo.Name; // var keywords = new NSString[] {new NSString("Add"), new NSString("Todo"), new NSString("Empty"), new NSString("Task") }; // activity.Keywords = new NSSet<NSString>(keywords); var attributeSet = new CoreSpotlight.CSSearchableItemAttributeSet (); attributeSet.DisplayName = userInfo.Name; attributeSet.ContentDescription = userInfo.Cuisine + " " + userInfo.Chef; // Handoff https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/Handoff/AdoptingHandoff/AdoptingHandoff.html // attributeSet.RelatedUniqueIdentifier = userInfo.Number.ToString(); // CoreSpotlight "id" activity.AddUserInfoEntries(NSDictionary.FromObjectAndKey(new NSString(userInfo.Number.ToString()), ActivityKeys.Id)); activity.ContentAttributeSet = attributeSet; activity.BecomeCurrent (); // don't forget to ResignCurrent() return activity; }
void SetupSearch() { var activity = new NSUserActivity("com.micjames.beerdrinkin.beerdetails"); if (!string.IsNullOrEmpty(beer.Description)) { var info = new NSMutableDictionary(); info.Add(new NSString("id"), new NSString(beer.BreweryDbId)); info.Add(new NSString("name"), new NSString(beer.Name)); info.Add(new NSString("description"), new NSString(beer.Description)); info.Add(new NSString("imageUrl"), new NSString(beer.ImageMedium)); info.Add(new NSString("abv"), new NSString(beer?.ABV.ToString())); info.Add(new NSString("breweryDbId"), new NSString(beer.BreweryDbId)); var attributes = new CSSearchableItemAttributeSet(); attributes.DisplayName = beer.Name; attributes.ContentDescription = beer.Description; var keywords = new NSString[] { new NSString(beer.Name), new NSString("beerName") }; activity.Keywords = new NSSet <NSString>(keywords); activity.ContentAttributeSet = attributes; activity.Title = beer.Name; activity.UserInfo = info; activity.EligibleForSearch = true; activity.EligibleForPublicIndexing = true; activity.BecomeCurrent(); } }
void CheckForAppLink(NSUserActivity userActivity) { var strLink = string.Empty; switch (userActivity.ActivityType) { case "NSUserActivityTypeBrowsingWeb": strLink = userActivity.WebPageUrl.AbsoluteString; break; case "com.apple.corespotlightitem": if (userActivity.UserInfo.ContainsKey(CSSearchableItem.ActivityIdentifier)) { strLink = userActivity.UserInfo.ObjectForKey(CSSearchableItem.ActivityIdentifier).ToString(); } break; default: if (userActivity.UserInfo.ContainsKey(new NSString("link"))) { strLink = userActivity.UserInfo[new NSString("link")].ToString(); } break; } if (!string.IsNullOrEmpty(strLink)) { _application.SendOnAppLinkRequestReceived(new Uri(strLink)); } }
public override void ConfirmContinueTimer(ContinueTimerIntent intent, Action <ContinueTimerIntentResponse> completion) { if (togglAPI == null) { completion(new ContinueTimerIntentResponse(ContinueTimerIntentResponseCode.FailureNoApiToken, null)); return; } togglAPI.TimeEntries.GetAll() .ToObservable() .FirstAsync() .Select(timeEntries => timeEntries.First()) .Subscribe( timeEntry => { lastEntry = timeEntry; var userActivity = new NSUserActivity(continueTimerActivityType); userActivity.SetEntryDescription(timeEntry.Description); completion(new ContinueTimerIntentResponse(ContinueTimerIntentResponseCode.Ready, userActivity)); }, exception => { completion(new ContinueTimerIntentResponse(ContinueTimerIntentResponseCode.Failure, null)); }); }
public static NSUserActivity CreateNSUserActivity(Restaurant userInfo) { var activityType = ActivityTypes.View; var activity = new NSUserActivity(activityType); activity.EligibleForSearch = true; // HACK: can result in duplicates with CoreSpotlight activity.EligibleForPublicIndexing = false; activity.EligibleForHandoff = false; activity.Title = "Restaurant " + userInfo.Name; // var keywords = new NSString[] {new NSString("Add"), new NSString("Todo"), new NSString("Empty"), new NSString("Task") }; // activity.Keywords = new NSSet<NSString>(keywords); var attributeSet = new CoreSpotlight.CSSearchableItemAttributeSet(); attributeSet.DisplayName = userInfo.Name; attributeSet.ContentDescription = userInfo.Cuisine + " " + userInfo.Chef; // Handoff https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/Handoff/AdoptingHandoff/AdoptingHandoff.html // attributeSet.RelatedUniqueIdentifier = userInfo.Number.ToString(); // CoreSpotlight "id" activity.AddUserInfoEntries(NSDictionary.FromObjectAndKey(new NSString(userInfo.Number.ToString()), ActivityKeys.Id)); activity.ContentAttributeSet = attributeSet; activity.BecomeCurrent(); // don't forget to ResignCurrent() return(activity); }
/// <summary> /// this is call when the app is opening because a universal link is clicked (iOS 9 min) /// </summary> public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { Console.WriteLine("!!!!! AppDelegate.ContinueUserActivity"); if (userActivity.ActivityType == NSUserActivityType.BrowsingWeb) { Console.WriteLine("ActivityType == BrowsingWeb"); } string url = userActivity.WebPageUrl.ToString(); Console.WriteLine(url); int index = url.IndexOf("$deeplink_path="); if (index > 0) { // this is a link like https://bnc.lt/a/.../deeplink_path=athlete/2 // convert this to https://snookerbyb.com/athlete/2 string newUrl = url.Substring(index + 15, url.Length - index - 15); url = "https://snookerbyb.com/" + newUrl; Console.WriteLine("converted url to: " + url); } App.Navigator.ProcessOpenUrl(url); return(true); // note: do NOT call the base }
public override void ConfirmStopTimer(StopTimerIntent intent, Action <StopTimerIntentResponse> completion) { if (togglAPI == null) { var userActivity = new NSUserActivity(stopTimerActivityType); userActivity.SetResponseText("Log in to use this shortcut."); completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.FailureNoApiToken, userActivity)); return; } var lastUpdated = SharedStorage.instance.GetLastUpdateDate(); togglAPI.TimeEntries.GetAll() .Select(checkSyncConflicts(lastUpdated)) .Select(getRunningTimeEntry) .Subscribe( runningTE => { runningEntry = runningTE; var userActivity = new NSUserActivity(stopTimerActivityType); userActivity.SetEntryDescription(runningTE.Description); completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.Ready, userActivity)); }, exception => { SharedStorage.instance.AddSiriTrackingEvent(SiriTrackingEvent.Error(exception.Message)); completion(responseFromException(exception)); }); }
/// <summary> /// Restores the state of the user activity. /// </summary> /// <param name="activity">Activity.</param> public override void RestoreUserActivityState(NSUserActivity activity) { base.RestoreUserActivityState(activity); // Log activity Console.WriteLine("Restoring Activity {0}", activity.Title); }
public override void ConfirmStopTimer(StopTimerIntent intent, Action <StopTimerIntentResponse> completion) { if (togglAPI == null) { var userActivity = new NSUserActivity(stopTimerActivityType); userActivity.SetResponseText(Resources.SiriShortcutLoginToUseShortcut); completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.FailureNoApiToken, userActivity)); return; } togglAPI.TimeEntries.GetAll() .Select(getRunningTimeEntry) .Subscribe( runningTE => { runningEntry = runningTE; var userActivity = new NSUserActivity(stopTimerActivityType); userActivity.SetEntryDescription(runningTE.Description); completion(new StopTimerIntentResponse(StopTimerIntentResponseCode.Ready, userActivity)); }, exception => { SharedStorage.instance.AddSiriTrackingEvent(SiriTrackingEvent.Error(exception.Message)); completion(responseFromException(exception)); }); }
// Handle the completed intent (required). public void HandleSendMessage(INSendMessageIntent intent, Action <INSendMessageIntentResponse> completion) { // Implement your application logic to send a message here. var userActivity = new NSUserActivity("com.trinetix.handlemessage"); // Define details var info = new NSMutableDictionary(); info.Add(new NSString("message"), new NSString(intent.Content)); // Populate Activity userActivity.UserInfo = info; // Add App Search ability //userActivity.EligibleForHandoff = true; //userActivity.EligibleForSearch = true; //userActivity.EligibleForPublicIndexing = true; //userActivity.BecomeCurrent(); // Assemble response and send it var response = new INSendMessageIntentResponse(INSendMessageIntentResponseCode.InProgress, userActivity); completion(response); }
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { var intent = userActivity.GetInteraction()?.Intent; if (intent is AddMeasureIntent adMeasureIntent) { HandleIntent(adMeasureIntent); return(true); } else if (intent is AddShortInsulinIntent addShortInsulinIntent) { HandleIntent(addShortInsulinIntent); return(true); } else if (userActivity.ActivityType == NSUserActivityHelper.AddMeasureActivityType) { HandleAddMeasureUserActivity(); return(true); } return(false); }
/// <summary> /// Navigates the Webview to the given URL string. /// </summary> /// <param name="url">URL.</param> private void NavigateToURL(string url) { // Properly formatted? if (!url.StartsWith("http://")) { // Add web url = "http://" + url; } // Display the give webpage WebView.LoadRequest(new NSUrlRequest(NSUrl.FromString(url))); // Invalidate existing Activity if (UserActivity != null) { UserActivity.Invalidate(); UserActivity = null; } // Create a new user Activity to support this tab UserActivity = new NSUserActivity(ThisApp.UserActivityTab4); UserActivity.Title = "Coffee Break Tab"; // Update the activity when the tab's URL changes var userInfo = new NSMutableDictionary(); userInfo.Add(new NSString("Url"), new NSString(url)); UserActivity.AddUserInfoEntries(userInfo); // Inform Activity that it has been updated UserActivity.BecomeCurrent(); // Log User Activity Console.WriteLine("Creating User Activity: {0} - {1}", UserActivity.Title, url); }
public static string CallHandleFromActivity(NSUserActivity activity) { // Is this a start call activity? if (activity.ActivityType == ActivityType) { // Yes, trap any errors try { // Get first contact var interaction = activity.GetInteraction(); var startAudioCallIntent = interaction.Intent as INStartAudioCallIntent; var contact = startAudioCallIntent.Contacts[0]; // Get the person handle return(contact.PersonHandle.Value); } catch { // Error, report null return(null); } } else { // Not handled return(null); } }
// Handle links received as Universal Links on iOS 9 or later public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { return(DynamicLinks.SharedInstance.HandleUniversalLink(userActivity.WebPageUrl, (dynamicLink, error) => { if (error != null) { ShowMessage("Seems that something wrong happened with Universal Links.", error.LocalizedDescription, application.KeyWindow.RootViewController); return; } if (dynamicLink.Url == null) { ShowMessage("Dynamic Link Received", "But it seems that it does not have an Url to evaluate.", application.KeyWindow.RootViewController); return; } if (string.IsNullOrWhiteSpace(dynamicLink.Url.Path) || dynamicLink.Url.Path == "/") { GoToViewController(string.Empty); } else { GoToViewController(dynamicLink.Url.PathComponents [1]); } })); }
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { switch (userActivity.ActivityType) { case "com.micjames.beerdrinkin.mybeers": break; case "com.micjames.beerdrinkin.wishlist": break; case "com.micjames.beerdrinkin.search": break; case "com.micjames.beerdrinkin.profile": break; case "com.micjames.beerdrinkin.beerdetails": var info = userActivity.UserInfo; if (this.Window.RootViewController.ChildViewControllers[0] is UITabBarController) { var tabController = this.Window.RootViewController.ChildViewControllers[0] as UITabBarController; tabController.SelectedIndex = 2; var beerItem = new BeerItem(); var id = new NSObject(); info.TryGetValue(new NSString("id"), out id); var name = new NSObject(); info.TryGetValue(new NSString("name"), out name); var description = new NSObject(); info.TryGetValue(new NSString("description"), out description); var imageUrl = new NSObject(); info.TryGetValue(new NSString("imageUrl"), out imageUrl); var breweryDbId = new NSObject(); info.TryGetValue(new NSString("breweryDbId"), out breweryDbId); beerItem.Name = name.ToString(); beerItem.Description = description.ToString(); beerItem.ImageMedium = imageUrl.ToString(); beerItem.BreweryDbId = breweryDbId.ToString(); if (!string.IsNullOrEmpty(beerItem.BreweryDbId)) { var storyboard = UIStoryboard.FromName("Main", null); var vc = storyboard.InstantiateViewController("beerDescriptionTableView") as BeerDescriptionTableView; vc.SetBeer(beerItem); var navigationControler = tabController.SelectedViewController as UINavigationController; navigationControler.PushViewController(vc, true); } } break; } return(true); }
public void HandleSetTaskAttribute(INSetTaskAttributeIntent intent, Action <INSetTaskAttributeIntentResponse> completion) { Console.WriteLine("Set task attribute"); var userActivity = new NSUserActivity("INSetTaskAttributeIntent"); var response = new INSetTaskAttributeIntentResponse(INSetTaskAttributeIntentResponseCode.Success, userActivity); completion(response); }
public static bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { if (userActivity.WebPageUrl != null) { FirebaseDynamicLinks.SharedInstance?.HandleUniversalLink(userActivity.WebPageUrl, HandleDynamicLink); } return(false); }
public override void UpdateUserActivityState(NSUserActivity activity) { base.UpdateUserActivityState(activity); UserInfo info = GetFilterValues(); activity.AddUserInfoEntries(info.Dictionary); }
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { if (Xamarin.Essentials.Platform.ContinueUserActivity(application, userActivity, completionHandler)) { return(true); } return(base.ContinueUserActivity(application, userActivity, completionHandler)); }
public override bool ContinueUserActivity( UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { this.CheckForAppLink(userActivity); return(true); }
public UIViewController GetViewControllerForUseractivity(NSUserActivity userActivity) { return((UIViewController) Activator.CreateInstance( Type.GetType(userActivity.ActivityType) ?? Type.GetType(userActivity.Title) ?? typeof(MenuViewController))); }
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { // Report Activity Console.WriteLine("Continuing User Activity: {0}", userActivity.ToString()); Tune.HandleContinueUserActivity(userActivity, completionHandler); return(true); }
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { if (!string.IsNullOrEmpty(Settings.APIToken)) { (App.Current as App).GoToApp(new Uri(userActivity.WebPageUrl.AbsoluteString)); return(true); } return(false); }
public void ConfirmSendMessage(INSendMessageIntent intent, Action <INSendMessageIntentResponse> completion) { // Verify user is authenticated and your app is ready to send a message. var userActivity = new NSUserActivity("INSendMessageIntent"); var response = new INSendMessageIntentResponse(INSendMessageIntentResponseCode.Ready, userActivity); completion(response); }
// Handle the completed intent (required). public void HandleSendMessage(INSendMessageIntent intent, Action <INSendMessageIntentResponse> completion) { // Implement your application logic to send a message here. var userActivity = new NSUserActivity("INSendMessageIntent"); var response = new INSendMessageIntentResponse(INSendMessageIntentResponseCode.Success, userActivity); completion(response); }
public bool HandleUserActivity(NSUserActivity userActivity) { var userInfo = new UserInfo(userActivity.UserInfo); bool rc = HandleActivityUserInfo(userInfo); ClearActivityContinuationInProgress(); return(rc); }
// Called on the main thread after the NSUserActivity object is available. // Use the data you stored in the NSUserActivity object to re-create what the user was doing. // You can create/fetch any restorable objects associated with the user activity, and pass them to the restorationHandler. public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { var vc = PrimaryViewController; vc.HandleUserActivity (userActivity); completionHandler(new NSObject[]{ NavigationController, vc}); return true; }
public override bool ContinueUserActivity (UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { if (userActivity.ActivityType == CSSearchableItem.ActionType) { #region Spotlight var uuid = userActivity.UserInfo.ObjectForKey (CSSearchableItem.ActivityIdentifier); Xamarin.Insights.Track("SearchResult", new Dictionary<string, string> { {"Type", "CoreSpotlight"} }); System.Console.WriteLine ("Show the page for " + uuid); var restaurantName = SearchModel.Lookup (uuid.ToString ()); System.Console.WriteLine ("which is " + restaurantName); MessagingCenter.Send<RestaurantGuide.App, string> (App.Current as RestaurantGuide.App, "show", restaurantName); #endregion } else { #region NSUserActivity // dang it, the userInfo is blank unless I hack the UserActivity_iOS.Start() method // https://forums.developer.apple.com/thread/9690 if (userActivity.ActivityType == ActivityTypes.View) { Xamarin.Insights.Track("SearchResult", new Dictionary<string, string> { {"Type", "NSUserActivity"} }); var uid = "0"; if (userActivity.UserInfo.Count == 0) { // new item } else { uid = userActivity.UserInfo.ObjectForKey (ActivityKeys.Id).ToString (); if (uid == "0") { Console.WriteLine ("No userinfo found for " + ActivityTypes.View); } else { Console.WriteLine ("Should display id " + uid); // handled in DetailViewController.RestoreUserActivityState } } ContinueNavigation (uid); } if (userActivity.ActivityType == CSSearchableItem.ActionType) { Xamarin.Insights.Track("SearchResult", new Dictionary<string, string> { {"Type", "CoreSpotlight"} }); var uid = userActivity.UserInfo.ObjectForKey (CSSearchableItem.ActivityIdentifier).ToString(); System.Console.WriteLine ("Show the detail for id:" + uid); ContinueNavigation (uid); } completionHandler(null); // TODO: display UI in Forms somehow #endregion } return true; }
static async Task AddLinkAsync(IAppLinkEntry deepLinkUri) { var appDomain = NSBundle.MainBundle.BundleIdentifier; string contentType, associatedWebPage; bool shouldAddToPublicIndex; //user can provide associatedWebPage, contentType, and shouldAddToPublicIndex TryGetValues(deepLinkUri, out contentType, out associatedWebPage, out shouldAddToPublicIndex); //our unique identifier will be the only content that is common to spotlight search result and a activity //this id allows us to avoid duplicate search results from CoreSpotlight api and NSUserActivity //https://developer.apple.com/library/ios/technotes/tn2416/_index.html var id = deepLinkUri.AppLinkUri.ToString(); var searchableAttributeSet = await GetAttributeSet(deepLinkUri, contentType, id); var searchItem = new CSSearchableItem(id, appDomain, searchableAttributeSet); //we need to make sure we index the item in spotlight first or the RelatedUniqueIdentifier will not work await IndexItemAsync(searchItem); #if __UNIFIED__ var activity = new NSUserActivity($"{appDomain}.{contentType}"); #else var activity = new NSUserActivity (new NSString($"{appDomain}.{contentType}")); #endif activity.Title = deepLinkUri.Title; activity.EligibleForSearch = true; //help increase your website url index rating if (!string.IsNullOrEmpty(associatedWebPage)) activity.WebPageUrl = new NSUrl(associatedWebPage); //make this search result available to Apple and to other users thatdon't have your app activity.EligibleForPublicIndexing = shouldAddToPublicIndex; activity.UserInfo = GetUserInfoForActivity(deepLinkUri); activity.ContentAttributeSet = searchableAttributeSet; //we don't need to track if the link is active iOS will call ResignCurrent if (deepLinkUri.IsLinkActive) activity.BecomeCurrent(); var aL = deepLinkUri as AppLinkEntry; if (aL != null) { aL.PropertyChanged += (sender, e) => { if (e.PropertyName == AppLinkEntry.IsLinkActiveProperty.PropertyName) { if (aL.IsLinkActive) activity.BecomeCurrent(); else activity.ResignCurrent(); } }; } }
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { if (userActivity.ActivityType == ActivityTypes.View) { string id = userActivity.UserInfo.ObjectForKey (new NSString ("Id")).ToString (); if (!string.IsNullOrWhiteSpace (id)) { MessagingCenter.Send<NSUserActivitySearch.App, string> (Xamarin.Forms.Application.Current as NSUserActivitySearch.App, "ShowItem", id); } } return true; }
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { if (userActivity.ActivityType == CSSearchableItem.ActionType) { string id = userActivity.UserInfo.ObjectForKey (CSSearchableItem.ActivityIdentifier).ToString (); if (!string.IsNullOrEmpty (id)) { MessagingCenter.Send<CoreSpotlightSearch.App, string> (Xamarin.Forms.Application.Current as CoreSpotlightSearch.App, "ShowItem", id); } } return true; }
public override bool ContinueUserActivity (UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { /// Get any properties we want from UserInfo dictionary. string vin = userActivity.UserInfo ["VIN"].ToString (); /// Trigger event HandoffOccurred?.Invoke (this, new HandoffArgs (vin)); return true; }
public override bool ContinueUserActivity (UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { switch (userActivity.ActivityType) { case "com.micjames.beerdrinkin.mybeers": break; case "com.micjames.beerdrinkin.wishlist": break; case "com.micjames.beerdrinkin.search": break; case "com.micjames.beerdrinkin.profile": break; case "com.micjames.beerdrinkin.beerdetails": var info = userActivity.UserInfo; if (this.Window.RootViewController.ChildViewControllers[0] is UITabBarController) { var tabController = this.Window.RootViewController.ChildViewControllers[0] as UITabBarController; tabController.SelectedIndex = 2; var beerItem = new BeerItem(); var id = new NSObject(); info.TryGetValue(new NSString("id"), out id); var name = new NSObject(); info.TryGetValue(new NSString("name"), out name); var description = new NSObject(); info.TryGetValue(new NSString("description"), out description); var imageUrl = new NSObject(); info.TryGetValue(new NSString("imageUrl"), out imageUrl); var breweryDbId = new NSObject(); info.TryGetValue(new NSString("breweryDbId"), out breweryDbId); beerItem.Name = name.ToString(); beerItem.Description = description.ToString(); beerItem.ImageMedium = imageUrl.ToString(); beerItem.BreweryDbId = breweryDbId.ToString(); if (!string.IsNullOrEmpty(beerItem.BreweryDbId)) { var storyboard = UIStoryboard.FromName("Main", null); var vc = storyboard.InstantiateViewController ("beerDescriptionTableView") as BeerDescriptionTableView; vc.SetBeer (beerItem); var navigationControler = tabController.SelectedViewController as UINavigationController; navigationControler.PushViewController (vc, true); } } break; } return true; }
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { //TODO Complete loading the beer - This is part of iOS 9 integration. var userInfo = userActivity.UserInfo; var beerID = userInfo.ValueForKey(new NSString("kCSSearchableItemActivityIdentifier")); Console.WriteLine(beerID); Window.RestoreUserActivityState(userActivity); return true; }
public override bool ContinueUserActivity (UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { // Take action based on the activity type switch (userActivity.ActivityType) { case "com.appracatappra.askquestion": // Pass question to Eliza to answer Controller.AskQuestion (userActivity.UserInfo.ValueForKey (new NSString ("question")).ToString(), true); break; } // Inform system this is handled return true; }
public override bool ContinueUserActivity (UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { if (userActivity.ActivityType == CSSearchableItem.ActionType) { var uuid = userActivity.UserInfo.ObjectForKey (CSSearchableItem.ActivityIdentifier); System.Console.WriteLine ("Show the page for " + uuid); var restaurantName = SearchModel.Lookup (uuid.ToString()); System.Console.WriteLine ("which is " + restaurantName); MessagingCenter.Send<RestaurantGuide.App, string> (App.Current as RestaurantGuide.App, "show", restaurantName); } return true; }
NSUserActivity CreateActivity() { var activity = new NSUserActivity(activityName); activity.EligibleForSearch = true; activity.EligibleForPublicIndexing = true; activity.EligibleForHandoff = false; activity.Title = "Favorites"; activity.AddUserInfoEntries(NSDictionary.FromObjectAndKey(new NSString("Favorites"), new NSString("Name"))); //var keywords = new string[] { }; activity.Keywords = new NSSet<NSString>(new NSString("Favorites"), new NSString("Soccer"), new NSString("Favorites")); activity.ContentAttributeSet = new CSSearchableItemAttributeSet("Open favorites"); return activity; }
NSUserActivity CreateActivity() { var activity = new NSUserActivity(activityName); activity.EligibleForSearch = true; activity.EligibleForPublicIndexing = true; activity.EligibleForHandoff = false; activity.Title = monkey.Name; activity.AddUserInfoEntries(NSDictionary.FromObjectAndKey(new NSString(monkey.Name), new NSString("Name"))); var keywords = new string[] { monkey.Name, "Monkey" }; activity.Keywords = new NSSet(keywords); activity.ContentAttributeSet = new CoreSpotlight.CSSearchableItemAttributeSet(monkey.Details); return activity; }
// http://www.raywenderlich.com/84174/ios-8-handoff-tutorial public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { Console.WriteLine ("ffffffff ContinueUserActivity"); UIViewController tvc = null; // NSUserActivity if ((userActivity.ActivityType == ActivityTypes.Add) || (userActivity.ActivityType == ActivityTypes.Detail)) { if (userActivity.UserInfo.Count == 0) { // new item } else { var uid = userActivity.UserInfo.ObjectForKey ((NSString)"id").ToString (); if (uid == "0") { Console.WriteLine ("No userinfo found for " + ActivityTypes.Detail); } else { Console.WriteLine ("Should display id " + uid); // handled in DetailViewController.RestoreUserActivityState } } tvc = ContinueNavigation (); Insights.Track("SearchResult", new Dictionary<string, string> { {"Type", "NSUserActivity"} }); } // CoreSpotlight if (userActivity.ActivityType == CSSearchableItem.ActionType) { var uid = userActivity.UserInfo.ObjectForKey (CSSearchableItem.ActivityIdentifier).ToString(); System.Console.WriteLine ("Show the detail for id:" + uid); tvc = ContinueNavigation (); Insights.Track("SearchResult", new Dictionary<string, string> { {"Type", "CoreSpotlight"} }); } completionHandler(new NSObject[] {tvc}); return true; }
NSUserActivity CreateActivity(TodoItem item) { // Create app search activity var activity = new NSUserActivity (ActivityTypes.View); // Populate activity activity.Title = item.Name; // Add additional data var attributes = new CSSearchableItemAttributeSet (); attributes.DisplayName = item.Name; attributes.ContentDescription = item.Notes; activity.ContentAttributeSet = attributes; activity.AddUserInfoEntries (NSDictionary.FromObjectAndKey (new NSString (item.ID), new NSString ("Id"))); // Add app search ability activity.EligibleForSearch = true; activity.BecomeCurrent (); // Don't forget to ResignCurrent() later return activity; }
/// <returns>To be added.</returns> /// <summary> /// Continues the user activity. /// </summary> /// <param name="application">Application.</param> /// <param name="userActivity">User activity.</param> /// /// <param name="completionHandler">Completion Handler.</param> public override bool ContinueUserActivity (UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { // Report Activity Console.WriteLine ("Continuing User Activity: {0}", userActivity.ToString()); // Get input and output streams from the Activity userActivity.GetContinuationStreams ((NSInputStream arg1, NSOutputStream arg2, NSError arg3) => { // Send required data via the streams // ... }); // Take action based on the Activity type switch (userActivity.ActivityType) { case "com.xamarin.monkeybrowser.tab1": // Preform handoff Tab1.PerformHandoff (userActivity); completionHandler (new NSObject[]{Tab1}); break; case "com.xamarin.monkeybrowser.tab2": // Preform handoff Tab2.PerformHandoff (userActivity); completionHandler (new NSObject[]{Tab2}); break; case "com.xamarin.monkeybrowser.tab3": // Preform handoff Tab3.PerformHandoff (userActivity); completionHandler (new NSObject[]{Tab3}); break; case "com.xamarin.monkeybrowser.tab4": // Preform handoff Tab4.PerformHandoff (userActivity); completionHandler (new NSObject[]{Tab4}); break; } // Inform system we handled this return true; }
public void ConfirmSendMessage (INSendMessageIntent intent, Action<INSendMessageIntentResponse> completion) { // Verify user is authenticated and your app is ready to send a message. var userActivity = new NSUserActivity (nameof (INSendMessageIntent)); var response = new INSendMessageIntentResponse (INSendMessageIntentResponseCode.Ready, userActivity); completion (response); }
// This is called on the main thread when a user activity managed by UIKit has been updated. // You can use this as a last chance to add additional data to the userActivity. public override void UserActivityUpdated(UIApplication application, NSUserActivity userActivity) { Console.WriteLine ("UserActivityUpdated"); }
public override bool ContinueUserActivity (UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { var settingsService = ServiceLocator.Current.GetInstance<ISettingsService> (); var schedulesService = ServiceLocator.Current.GetInstance<ISchedulesService> (); if (userActivity.ActivityType == CSSearchableItem.ActionType) { var tabController = this.Window.RootViewController as UITabBarController; var navController = tabController.ViewControllers [0] as UINavigationController; var identifier = userActivity?.UserInfo?.ObjectForKey (CSSearchableItem.ActivityIdentifier); if (identifier != null && identifier.ToString ().Contains ("|\\/|")) { // This is a session or a speaker var parts = identifier.ToString ().Split (new [] { "|\\/|" }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { //This is a session var conferenceSlug = parts [0]; var sessionSlug = parts [1]; var conferencesViewModel = Application.Locator.Conferences; var task = Task.Run (async () => { await conferencesViewModel.LoadConferences (Priority.Explicit); }); task.Wait (); var conference = conferencesViewModel.Conferences.Single (c => c.Slug == conferenceSlug); var session = conference.Sessions.Single (s => s.Slug == sessionSlug); var conferenceVm = new ConferenceDetailViewModel (conference, schedulesService, settingsService); var sessionVm = new SessionDetailViewModel (session, conference.Name); Application.Locator.Conference = conferenceVm; Application.Locator.Session = sessionVm; var storyboard = UIStoryboard.FromName ("Main", null); var conferencesViewController = storyboard.InstantiateViewController ("ConferencesViewController") as ConferencesViewController; var conferenceDetailViewController = storyboard.InstantiateViewController ("ConferenceDetailViewController") as ConferenceDetailViewController; var sessionsViewController = storyboard.InstantiateViewController ("SessionsViewController") as SessionsViewController; var sessionDetailViewController = storyboard.InstantiateViewController ("SessionDetailViewController"); navController.SetViewControllers (new UIViewController[] { conferencesViewController, conferenceDetailViewController, sessionsViewController, sessionDetailViewController }, animated: false); } else if (parts.Length == 3) { //This is a speaker var conferenceSlug = parts [0]; var sessionSlug = parts [1]; var speakerSlug = parts [2]; var conferencesViewModel = Application.Locator.Conferences; var task = Task.Run (async () => { await conferencesViewModel.LoadConferences (Priority.Explicit); }); task.Wait (); var conference = conferencesViewModel.Conferences.Single (c => c.Slug == conferenceSlug); var session = conference.Sessions.Single (s => s.Slug == sessionSlug); var speaker = session.Speakers.Single (s => s.Slug == speakerSlug); var conferenceVm = new ConferenceDetailViewModel (conference, schedulesService, settingsService); var sessionVm = new SessionDetailViewModel (session, conference.Name); var speakerVm = new SpeakerDetailViewModel (session, speaker); Application.Locator.Conference = conferenceVm; Application.Locator.Session = sessionVm; Application.Locator.Speaker = speakerVm; var storyboard = UIStoryboard.FromName ("Main", null); var conferencesViewController = storyboard.InstantiateViewController ("ConferencesViewController") as ConferencesViewController; var conferenceDetailViewController = storyboard.InstantiateViewController ("ConferenceDetailViewController") as ConferenceDetailViewController; var sessionsViewController = storyboard.InstantiateViewController ("SessionsViewController") as SessionsViewController; var sessionDetailViewController = storyboard.InstantiateViewController ("SessionDetailViewController"); var speakerDetailViewController = storyboard.InstantiateViewController ("SpeakerDetailViewController"); navController.SetViewControllers (new UIViewController[] { conferencesViewController, conferenceDetailViewController, sessionsViewController, sessionDetailViewController, speakerDetailViewController }, animated: false); } } else { // This is a conference var conferenceSlug = identifier.ToString (); var conferencesViewModel = Application.Locator.Conferences; var task = Task.Run (async () => { await conferencesViewModel.LoadConferences (Priority.Explicit); }); task.Wait (); var conference = conferencesViewModel.Conferences.Single (c => c.Slug == conferenceSlug); var vm = new ConferenceDetailViewModel (conference, schedulesService, settingsService); Application.Locator.Conference = vm; var storyboard = UIStoryboard.FromName ("Main", null); var conferenceDetailViewController = storyboard.InstantiateViewController ("ConferenceDetailViewController") as ConferenceDetailViewController; ; navController.SetViewControllers (new UIViewController[] { conferenceDetailViewController }, animated: false); } } return true; }
public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) { CheckForAppLink(userActivity); return true; }
/// <summary> /// Restores the state of the user activity. /// </summary> /// <param name="activity">Activity.</param> public override void RestoreUserActivityState (NSUserActivity activity) { base.RestoreUserActivityState (activity); // Log activity Console.WriteLine ("Restoring Activity {0}", activity.Title); }
public override void UserActivityReceivedData (NSUserActivity userActivity, NSInputStream inputStream, NSOutputStream outputStream) { // Log Console.WriteLine ("User Activity Received Data: {0}", userActivity.Title); }
public void PerformHandoff(NSUserActivity activity) { // Hide busy indicator HideBusy (); // Extract URL from dictionary var url = activity.UserInfo ["Url"].ToString (); // Display value URL.Text = url; // Display the give webpage WebView.LoadRequest(new NSUrlRequest(NSUrl.FromString(url))); // Save activity UserActivity = activity; UserActivity.BecomeCurrent (); }
public override void UserActivityWasContinued (NSUserActivity userActivity) { Console.WriteLine ("User Activity Was Continued: {0}", userActivity.Title); }
public override void UserActivityUpdated(UIApplication application, NSUserActivity userActivity) { CheckForAppLink(userActivity); }
public override void UserActivityWillSave (NSUserActivity userActivity) { Console.WriteLine ("User Activity will be Saved: {0}", userActivity.Title); }
void CheckForAppLink(NSUserActivity userActivity) { var strLink = string.Empty; switch (userActivity.ActivityType) { case "NSUserActivityTypeBrowsingWeb": strLink = userActivity.WebPageUrl.AbsoluteString; break; case "com.apple.corespotlightitem": if (userActivity.UserInfo.ContainsKey(CSSearchableItem.ActivityIdentifier)) strLink = userActivity.UserInfo.ObjectForKey(CSSearchableItem.ActivityIdentifier).ToString(); break; default: if (userActivity.UserInfo.ContainsKey(new NSString("link"))) strLink = userActivity.UserInfo[new NSString("link")].ToString(); break; } if (!string.IsNullOrEmpty(strLink)) _application.SendOnAppLinkRequestReceived(new Uri(strLink)); }