public SpotlightHelper(List <Restaurant> restaurants)
        {
            this.restaurants = restaurants;
            var dataItems = new List <CSSearchableItem>();

            foreach (var r in restaurants)
            {
                var attributeSet = new CSSearchableItemAttributeSet(UTType.Text);
                attributeSet.Title = r.Name;
                attributeSet.ContentDescription = r.Cuisine;
                attributeSet.TextContent        = r.Chef;

                var dataItem = new CSSearchableItem(r.Number.ToString(), "com.xamarin.restguide", attributeSet);
                dataItems.Add(dataItem);
            }

            // HACK: index should be 'managed' rather than deleted/created each time - keep track of what's indexed?
            // see the "To9o" sample for a better user-input search indexing strategy
            CSSearchableIndex.DefaultSearchableIndex.DeleteAll(null);

            CSSearchableIndex.DefaultSearchableIndex.Index(dataItems.ToArray <CSSearchableItem> (), err => {
                if (err != null)
                {
                    Console.WriteLine(err);
                }
                else
                {
                    Console.WriteLine("Indexed items successfully");
                }
            });
        }
Example #2
0
        public void InsertOrUpdateReport(ExpenseReport item)
        {
            //Need to check if iOS 9 for CoreSpotlight
            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                var attributes = new CSSearchableItemAttributeSet(itemContentType: "");
                attributes.Title = "Expense Report: " + item.ReportName;
                attributes.ContentDescription =
                    "Status: " + item.StatusString
                    + "\nTotal: " + item.Total
                    + "\nCreated On:  " + item.CreatedOnString;

                // Create item
                var itemToAdd = new CSSearchableItem(item.ID.ToString(), item.ExpenseReportIdentifier, attributes);

                // Index item
                CSSearchableIndex.DefaultSearchableIndex.Index(new CSSearchableItem[] { itemToAdd }, (error) => {
                    // Successful?
                    if (error != null)
                    {
                        Console.WriteLine(error.LocalizedDescription);
                    }
                });
            }
        }
Example #3
0
        void ReIndexSearchItems(List <TodoItem> items)
        {
            var searchableItems = new List <CSSearchableItem> ();

            foreach (var item in todoItems)
            {
                // Create attributes to describe item
                var attributes = new CSSearchableItemAttributeSet(UTType.Text);
                attributes.Title = item.Name;
                attributes.ContentDescription = item.Notes;

                // Create item
                var searchableItem = new CSSearchableItem(item.ID, "com.companyname.corespotlightsearch", attributes);
                searchableItems.Add(searchableItem);
            }

            // Index items
            CSSearchableIndex.DefaultSearchableIndex.Index(searchableItems.ToArray <CSSearchableItem> (), error => {
                if (error != null)
                {
                    Debug.WriteLine(error);
                }
                else
                {
                    Debug.WriteLine("Successfully indexed items");
                }
            });
        }
        /// <summary>
        /// Add the restaurant collection to the CoreSpotlight index
        /// </summary>
        public SpotlightHelper(List<Restaurant> restaurants)
        {
            this.restaurants = restaurants;
            var dataItems = new List<CSSearchableItem>();
            foreach (var r in restaurants) {
                var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
                attributeSet.Title = r.Name;
                attributeSet.ContentDescription = r.Cuisine;
                attributeSet.TextContent = r.Chef; // also allow search by chef's name

                var dataItem = new CSSearchableItem (r.Number.ToString(), "com.xamarin.restguide", attributeSet);
                dataItems.Add (dataItem);
            }

            // HACK: index could be 'managed' rather than deleted/created each time - keep track of what's indexed?
            // see the "To9o" sample for a better user-input search indexing strategy
            CSSearchableIndex.DefaultSearchableIndex.DeleteAll(deletErr =>
            {
                // Start the new index only after the old one is completely deleted;
                // important for larger indexes, where DeleteAll might take time to finish (thanks @jamesmontemagno)
                CSSearchableIndex.DefaultSearchableIndex.Index (dataItems.ToArray<CSSearchableItem> (), err => {
                    if (err != null) {
                        Console.WriteLine ("Index failed " + err);
                        Xamarin.Insights.Report(new Exception("CoreSpotlight Index Failed"), new Dictionary <string, string> {
                            {"Message", err.ToString()}
                        }, Xamarin.Insights.Severity.Error);
                    } else {
                        Console.WriteLine ("Indexed items successfully");
                        Xamarin.Insights.Track("CoreSpotlight", new Dictionary<string, string> {
                            {"Type", "Indexed successfully"}
                        });
                    }
                });
            });
        }
        public static void BulkIndex(List<Task> tasks)
        {
            // HACK: generating fake GUID keys
            var searchIndexMap2 = new Dictionary<string, Task> ();
            foreach (var r in tasks) {
                searchIndexMap2.Add (Guid.NewGuid ().ToString(), r);
            }
            // mapping keys to objects
            var dataItems = searchIndexMap2.Select (keyValuePair => {
                var guid = keyValuePair.Key;
                var t = keyValuePair.Value;

                var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
                attributeSet.Title = t.Name;
                attributeSet.ContentDescription = t.Notes;
                attributeSet.TextContent = t.Notes;

                var dataItem = new CSSearchableItem (t.Id.ToString(), Spotlight.SearchDomain, attributeSet);
                return dataItem;

            });

            // Delete everything before doing bulk index
            CSSearchableIndex.DefaultSearchableIndex.DeleteAll(null);

            // Bulk index
            CSSearchableIndex.DefaultSearchableIndex.Index (dataItems.ToArray<CSSearchableItem> (), err => {
                if (err != null) {
                    Console.WriteLine (err);
                } else {
                    Console.WriteLine ("Indexed items successfully");
                }
            });
        }
Example #6
0
        async Task <CSSearchableItem> AddConferenceToSearch(Conference conference)
        {
            var attributes = new CSSearchableItemAttributeSet(itemContentType: MobileCoreServices.UTType.DelimitedText.ToString());

            attributes.Title = conference.Name;
            attributes.ContentDescription = conference.Description;
            if (!string.IsNullOrWhiteSpace(conference.ImageUrl))
            {
                try {
                    var imageService = ServiceLocator.Current.GetInstance <IImageService> ();
                    var localPath    = await imageService.GetConferenceImagePath(conference);

                    UIImage image = null;
                    await Task.Run(() => {
                        var uiImage = UIImage.FromFile(localPath);
                        if (uiImage != null)
                        {
                            attributes.ThumbnailData = uiImage.AsPNG();
                        }
                    });
                } catch (Exception e) {
                    Insights.Report(e);
                }
            }
            var searchableConference = new CSSearchableItem(conference.Slug, "tekconf", attributes);

            return(searchableConference);
        }
		public SpotlightHelper (List<Restaurant> restaurants)
		{
			this.restaurants = restaurants;
			var dataItems = new List<CSSearchableItem>();
			foreach (var r in restaurants) {
				var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
				attributeSet.Title = r.Name;
				attributeSet.ContentDescription = r.Cuisine;
				attributeSet.TextContent = r.Chef;

				var dataItem = new CSSearchableItem (r.Number.ToString(), "com.xamarin.restguide", attributeSet);
				dataItems.Add (dataItem);
			}

			// HACK: index should be 'managed' rather than deleted/created each time - keep track of what's indexed?
			// see the "To9o" sample for a better user-input search indexing strategy
			CSSearchableIndex.DefaultSearchableIndex.DeleteAll(null);

			CSSearchableIndex.DefaultSearchableIndex.Index (dataItems.ToArray<CSSearchableItem> (), err => {
				if (err != null) {
					Console.WriteLine (err);
				} else {
					Console.WriteLine ("Indexed items successfully");
				}
			});
		}
Example #8
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();
					}
				};
			}
		}
Example #9
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);

			var activity = new NSUserActivity($"{appDomain}.{contentType}");
			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 iOS9SearchModel (List<Restaurant> restaurants)
		{
			searchIndexMap2 = new Dictionary<Guid, Restaurant> ();
			foreach (var r in restaurants) {
				searchIndexMap2.Add (Guid.NewGuid (), r);
			}
			var dataItems = searchIndexMap2.Select (keyValuePair => {
				var guid = keyValuePair.Key;
				var restaurant = keyValuePair.Value;

				var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
				attributeSet.Title = restaurant.Name;
				attributeSet.ContentDescription = restaurant.Text;
				attributeSet.TextContent = restaurant.Text;

				var dataItem = new CSSearchableItem (guid.ToString (), "com.xamarin.restguide", attributeSet);
				return dataItem;

			});

//			searchIndexMap = new Dictionary<Guid, string> ();
//			foreach (var r in restaurants) {
//				searchIndexMap.Add (Guid.NewGuid (), r.Name);
//			}
//
//			//CoreSpotlight initialization
//			var dataItems = searchIndexMap.Select (keyValuePair => {
//				var guid = keyValuePair.Key;
//				var restaurant = keyValuePair.Value;
//
//				var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
//				attributeSet.Title = restaurant;
//				attributeSet.ContentDescription = "My app's data relating to " + restaurant;
//				attributeSet.TextContent = restaurant;
//
//				var dataItem = new CSSearchableItem (guid.ToString (), "com.xamarin.restguide", attributeSet);
//				return dataItem;
//			
//			});

			// HACK: index should be 'managed' rather than deleted/created each time
			CSSearchableIndex.DefaultSearchableIndex.DeleteAll(null);

			CSSearchableIndex.DefaultSearchableIndex.Index (dataItems.ToArray<CSSearchableItem> (), err => {
				if (err != null) {
					Console.WriteLine (err);
				} else {
					Console.WriteLine ("Indexed items successfully");
				}
			});
		}
Example #11
0
        static Task <bool> IndexItemAsync(CSSearchableItem searchItem)
        {
            var tcs = new TaskCompletionSource <bool>();

            if (CSSearchableIndex.IsIndexingAvailable)
            {
                CSSearchableIndex.DefaultSearchableIndex.Index(new[] { searchItem }, error => tcs.TrySetResult(error == null));
            }
            else
            {
                tcs.SetResult(false);
            }
            return(tcs.Task);
        }
Example #12
0
 CSSearchableItem CreateSearchItem(Song song)
 {
     try{
         var attributes = new CSSearchableItemAttributeSet();
         attributes.Album         = song.Album;
         attributes.ContentType   = UTType.Audio;
         attributes.Title         = song.Name;
         attributes.Artist        = song.Artist;
         attributes.ContentRating = song.Rating;
         attributes.MusicalGenre  = song.Genre;
         attributes.Identifier    = song.Id;
         var item = new CSSearchableItem(song.Id, "songdata", attributes);
         return(item);
     }
     catch (Exception ex) {
         return(null);
     }
 }
Example #13
0
        public void CreateSearchItem(TodoItem item)
        {
            // Create attributes to describe item
            var attributes = new CSSearchableItemAttributeSet (UTType.Text);
            attributes.Title = item.Name;
            attributes.ContentDescription = item.Notes;

            // Create item
            var searchableItem = new CSSearchableItem (item.ID, "com.companyname.corespotlightsearch", attributes);

            // Index item
            CSSearchableIndex.DefaultSearchableIndex.Index (new CSSearchableItem[]{ searchableItem }, error => {
                if (error != null) {
                    Debug.WriteLine (error);
                } else {
                    Debug.WriteLine ("Successfully indexed item");
                }
            });
        }
        public static Task IndexTrips(IEnumerable <Trip> trips)
        {
            return(Task.Run(() =>
            {
                CSSearchableIndex.DefaultSearchableIndex.DeleteAll(deleteError =>
                {
                    if (deleteError != null)
                    {
                        Logger.Instance.Report(new System.Exception("CoreSpotlight Index Deletion Failed"), new Dictionary <string, string>
                        {
                            { "Message", deleteError.ToString() }
                        });
                    }
                });

                var i = 0;
                var dataItems = new List <CSSearchableItem>();
                foreach (var trip in trips)
                {
                    var attributeSet = new CSSearchableItemAttributeSet(UTType.Text);
                    attributeSet.Title = trip.Name;
                    attributeSet.ContentDescription = $"{trip.Name} was on {trip.TimeAgo} and lasted {trip.TotalDistance}.";

                    var dataItem = new CSSearchableItem(i.ToString(), "com.microsoft.MyDriving.trip", attributeSet);
                    dataItems.Add(dataItem);

                    i++;
                }

                CSSearchableIndex.DefaultSearchableIndex.Index(dataItems.ToArray(), insertionError =>
                {
                    if (insertionError != null)
                    {
                        Logger.Instance.Report(new System.Exception("CoreSpotlight Indexing Failed"), new Dictionary <string, string>
                        {
                            { "Message", insertionError.ToString() }
                        });
                    }
                });
            }));
        }
		public static Task IndexTrips(IEnumerable<Trip> trips)
		{
			return Task.Run(() =>
			{
				CSSearchableIndex.DefaultSearchableIndex.DeleteAll(deleteError =>
				{
					if (deleteError != null)
					{
						Logger.Instance.Report(new System.Exception("CoreSpotlight Index Deletion Failed"), new Dictionary<string, string>
						{
							{ "Message", deleteError.ToString () }
						});
					}
				});

				var i = 0;
				var dataItems = new List<CSSearchableItem>();
				foreach (var trip in trips)
				{
					var attributeSet = new CSSearchableItemAttributeSet(UTType.Text);
					attributeSet.Title = trip.Name;
					attributeSet.ContentDescription = $"{trip.Name} was on {trip.TimeAgo} and lasted {trip.TotalDistance}.";

					var dataItem = new CSSearchableItem(i.ToString(), "com.microsoft.MyDriving.trip", attributeSet);
					dataItems.Add(dataItem);

					i++;
				}

				CSSearchableIndex.DefaultSearchableIndex.Index (dataItems.ToArray (), insertionError =>
				{
					if (insertionError != null)
					{
						Logger.Instance.Report(new System.Exception("CoreSpotlight Indexing Failed"), new Dictionary<string, string>
						{
							{ "Message", insertionError.ToString () }
						});
					}
				});
			});
		}
        private void SetupCoreSpotlightSearch()
        {
            // Create attributes to describe an item
            var attributes = new CSSearchableItemAttributeSet(UTType.Data);

            attributes.Title = "Test Cloud";
            attributes.ContentDescription = "Automatically test your app on 1,000 devices in the cloud.";

            // Create item
            var item = new CSSearchableItem("1", "products", attributes);

            // Index item
            CSSearchableIndex.DefaultSearchableIndex.Index(new CSSearchableItem[] { item }, (error) =>
            {
                // Successful?
                if (error != null)
                {
                    Console.WriteLine(error.LocalizedDescription);
                }
            });
        }
        public static void Index(TodoItem t)
        {
            var attributeSet = new CSSearchableItemAttributeSet(UTType.Text);

            attributeSet.Title = t.Name;
            attributeSet.ContentDescription = t.Notes;
            attributeSet.TextContent        = t.Notes;

            var dataItem = new CSSearchableItem(t.Id.ToString(), Spotlight.SearchDomain, attributeSet);

            CSSearchableIndex.DefaultSearchableIndex.Index(new CSSearchableItem[] { dataItem }, err => {
                if (err != null)
                {
                    Console.WriteLine(err);
                }
                else
                {
                    Console.WriteLine("Indexed inividual item successfully");
                }
            });
        }
Example #18
0
        /// <summary>
        /// Add the restaurant collection to the CoreSpotlight index
        /// </summary>
        public SpotlightHelper(List <Restaurant> restaurants)
        {
            this.restaurants = restaurants;
            var dataItems = new List <CSSearchableItem>();

            foreach (var r in restaurants)
            {
                var attributeSet = new CSSearchableItemAttributeSet(UTType.Text);
                attributeSet.Title = r.Name;
                attributeSet.ContentDescription = r.Cuisine;
                attributeSet.TextContent        = r.Chef;          // also allow search by chef's name

                var dataItem = new CSSearchableItem(r.Number.ToString(), "com.xamarin.restguide", attributeSet);
                dataItems.Add(dataItem);
            }

            // HACK: index could be 'managed' rather than deleted/created each time - keep track of what's indexed?
            // see the "To9o" sample for a better user-input search indexing strategy
            CSSearchableIndex.DefaultSearchableIndex.DeleteAll(deletErr =>
            {
                // Start the new index only after the old one is completely deleted;
                // important for larger indexes, where DeleteAll might take time to finish (thanks @jamesmontemagno)
                CSSearchableIndex.DefaultSearchableIndex.Index(dataItems.ToArray <CSSearchableItem> (), err => {
                    if (err != null)
                    {
                        Console.WriteLine("Index failed " + err);
                        Xamarin.Insights.Report(new Exception("CoreSpotlight Index Failed"), new Dictionary <string, string> {
                            { "Message", err.ToString() }
                        }, Xamarin.Insights.Severity.Error);
                    }
                    else
                    {
                        Console.WriteLine("Indexed items successfully");
                        Xamarin.Insights.Track("CoreSpotlight", new Dictionary <string, string> {
                            { "Type", "Indexed successfully" }
                        });
                    }
                });
            });
        }
        public static void BulkIndex(List <TodoItem> todoItems)
        {
            // HACK: generating fake GUID keys
            var searchIndexMap2 = new Dictionary <string, TodoItem> ();

            foreach (var r in todoItems)
            {
                searchIndexMap2.Add(Guid.NewGuid().ToString(), r);
            }
            // mapping keys to objects
            var dataItems = searchIndexMap2.Select(keyValuePair => {
                var guid = keyValuePair.Key;
                var t    = keyValuePair.Value;

                var attributeSet   = new CSSearchableItemAttributeSet(UTType.Text);
                attributeSet.Title = t.Name;
                attributeSet.ContentDescription = t.Notes;
                attributeSet.TextContent        = t.Notes;

                var dataItem = new CSSearchableItem(t.Id.ToString(), Spotlight.SearchDomain, attributeSet);
                return(dataItem);
            });

            // Delete everything before doing bulk index
            CSSearchableIndex.DefaultSearchableIndex.DeleteAll(null);

            // Bulk index
            CSSearchableIndex.DefaultSearchableIndex.Index(dataItems.ToArray <CSSearchableItem> (), err => {
                if (err != null)
                {
                    Console.WriteLine(err);
                }
                else
                {
                    Console.WriteLine("Indexed items successfully");
                }
            });
        }
        public static void Index(Task t)
        {
            var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
            attributeSet.Title = t.Name;
            attributeSet.ContentDescription = t.Notes;
            attributeSet.TextContent = t.Notes;

            var dataItem = new CSSearchableItem (t.Id.ToString(), Spotlight.SearchDomain, attributeSet);

            CSSearchableIndex.DefaultSearchableIndex.Index (new CSSearchableItem[] {dataItem}, err => {
                if (err != null) {
                    Console.WriteLine (err);
                    Insights.Report(new Exception("CoreSpotlight Index Failed"), new Dictionary <string, string> {
                        {"Message", err.ToString()}
                    }, Xamarin.Insights.Severity.Error);
                } else {
                    Console.WriteLine ("Indexed inividual item successfully");
                    Insights.Track("CoreSpotlight", new Dictionary<string, string> {
                        {"Type", "Indexed successfully"}
                    });
                }
            });
        }
Example #21
0
        public void CreateSearchItem(TodoItem item)
        {
            // Create attributes to describe item
            var attributes = new CSSearchableItemAttributeSet(UTType.Text);

            attributes.Title = item.Name;
            attributes.ContentDescription = item.Notes;

            // Create item
            var searchableItem = new CSSearchableItem(item.ID, "com.companyname.corespotlightsearch", attributes);

            // Index item
            CSSearchableIndex.DefaultSearchableIndex.Index(new CSSearchableItem[] { searchableItem }, error => {
                if (error != null)
                {
                    Debug.WriteLine(error);
                }
                else
                {
                    Debug.WriteLine("Successfully indexed item");
                }
            });
        }
Example #22
0
        void ReIndexSearchItems(List<TodoItem> items)
        {
            var searchableItems = new List<CSSearchableItem> ();
            foreach (var item in todoItems) {
                // Create attributes to describe item
                var attributes = new CSSearchableItemAttributeSet (UTType.Text);
                attributes.Title = item.Name;
                attributes.ContentDescription = item.Notes;

                // Create item
                var searchableItem = new CSSearchableItem (item.ID, "com.companyname.corespotlightsearch", attributes);
                searchableItems.Add (searchableItem);
            }

            // Index items
            CSSearchableIndex.DefaultSearchableIndex.Index (searchableItems.ToArray<CSSearchableItem> (), error => {
                if (error != null) {
                    Debug.WriteLine (error);
                } else {
                    Debug.WriteLine ("Successfully indexed items");
                }
            });
        }
Example #23
0
		static Task<bool> IndexItemAsync(CSSearchableItem searchItem)
		{
			var tcs = new TaskCompletionSource<bool>();
			if (CSSearchableIndex.IsIndexingAvailable)
			{
				CSSearchableIndex.DefaultSearchableIndex.Index(new[] { searchItem }, error => tcs.TrySetResult(error == null));
			}
			else
				tcs.SetResult(false);
			return tcs.Task;
		}
		async Task<CSSearchableItem> AddConferenceToSearch (Conference conference)
		{
			var attributes = new CSSearchableItemAttributeSet (itemContentType: MobileCoreServices.UTType.DelimitedText.ToString ());
			attributes.Title = conference.Name;
			attributes.ContentDescription = conference.Description;
			if (!string.IsNullOrWhiteSpace (conference.ImageUrl)) {
				try {
					var imageService = ServiceLocator.Current.GetInstance<IImageService> ();
					var localPath = await imageService.GetConferenceImagePath (conference);
					UIImage image = null;
					await Task.Run (() => {
						var uiImage = UIImage.FromFile (localPath);
						if (uiImage != null) {
							attributes.ThumbnailData = uiImage.AsPNG ();
						}
					});
				} catch (Exception e) {
					Insights.Report (e);
				}
			}
			var searchableConference = new CSSearchableItem (conference.Slug, "tekconf", attributes);
			return searchableConference;
		}