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 Task Finish() { _activity?.ResignCurrent(); return(Task.CompletedTask); }
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(); } }; } }