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;
		}
		/// <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);
		}
Esempio n. 4
0
		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();
					}
				};
			}
		}
Esempio n. 5
0
        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;
        }
Esempio n. 6
0
        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 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 ();

		}
Esempio n. 8
0
		// 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 (nameof (INSendMessageIntent));
			var userActivity = new NSUserActivity ("com.appracatappra.askquestion");

			// Define details
			var info = new NSMutableDictionary ();
			info.Add (new NSString ("question"), new NSString (intent.Content));

			// Populate Activity
			userActivity.Title = "Ask Eliza a Question";
			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);
		}
		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();
			}

        }