public void SignIn() { var url = NSUrl.FromString(AuthUrl); var callbackScheme = "exampleauth"; var session = new ASWebAuthenticationSession(url, callbackScheme, (callbackUrl, error) => { if (error != null) { // TODO: Handle error return; } if (callbackUrl == null) { // TODO: Handle error return; } // The callback URL format depends on the provider. For this example: // exampleauth://auth?token=1234 var queryItems = NSUrlComponents.FromString(callbackUrl.AbsoluteString).QueryItems; var token = queryItems?.FirstOrDefault(x => x.Name == "token")?.Value; // TODO: Check token }) { PresentationContextProvider = _presentationContext }; session.Start(); }
public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation) { if (url != null) { NSUrlComponents urlComponents = new NSUrlComponents(url, false); string data = ""; NSUrlQueryItem[] allItems = urlComponents.QueryItems; foreach (NSUrlQueryItem item in allItems) { if (item.Name == "data") { data = item.Value; } } if (!string.IsNullOrEmpty(data)) { IMessageService messageService; using (var scope = AppContainer.Container.BeginLifetimeScope()) { messageService = AppContainer.Container.Resolve <IMessageService>(); } messageService.AppLaunchedFromDeepLink(data); } } return(true); }
private void NavigateUniversalLinks(NSUrl url) { try { var urlComponents = new NSUrlComponents(url, true); if (urlComponents.Path?.StartsWith("/cocoa/a/") == true) { var processingNumber = urlComponents .QueryItems? .FirstOrDefault(item => item.Name == AppConstants.LinkQueryKeyProcessingNumber)? .Value; if (processingNumber != null && Validator.IsValidProcessingNumber(processingNumber)) { var navigationParameters = NotifyOtherPage.BuildNavigationParams(processingNumber); InvokeOnMainThread(async() => await AppInstance?.NavigateToSplashAsync(Destination.NotifyOtherPage, navigationParameters)); } else { _loggerService.Value.Error("Failed to navigate NotifyOtherPage with invalid processingNumber"); InvokeOnMainThread(async() => await AppInstance?.NavigateToSplashAsync(Destination.HomePage, new NavigationParameters())); } } } catch (Exception e) { _loggerService.Value.Exception("Failed to NavigateUniversalLinks", e); } }
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options) { var uri = new NSUrlComponents(url, true); var token = uri.PercentEncodedQueryItems.FirstOrDefault(x => x.Name == "token")?.Value; var refreshToken = uri.PercentEncodedQueryItems.FirstOrDefault(x => x.Name == "refresh_token")?.Value; if (!string.IsNullOrWhiteSpace(token)) { Xamarin.Forms.Application.Current.Properties["token"] = token; Xamarin.Forms.Application.Current.Properties["refresh_token"] = refreshToken; Xamarin.Forms.Application.Current.MainPage = new MasterPage(); } else { var model = new Core.Models.User.ExternalLoginConfirmModel(); model.Email = uri.PercentEncodedQueryItems.FirstOrDefault(x => x.Name == "email").Value; model.FirstName = uri.PercentEncodedQueryItems.FirstOrDefault(x => x.Name == "gname").Value; model.LastName = uri.PercentEncodedQueryItems.FirstOrDefault(x => x.Name == "sname").Value; model.Cookie = uri.PercentEncodedQueryItems.FirstOrDefault(x => x.Name == "externalToken").Value; model.Provider = uri.PercentEncodedQueryItems.FirstOrDefault(x => x.Name == "provider").Value; Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new ExtrenalLoginConfirmPage(model)); } return(true); }
private async void GetScan(object s, object e) { ZXing.Mobile.MobileBarcodeScanner scanner = new ZXing.Mobile.MobileBarcodeScanner(); ZXing.Result result = await scanner.Scan(); if (result == null) { return; } Console.WriteLine("Scanned Barcode: " + result.Text); NSUrlComponents comps = NSUrlComponents.FromString(result.Text); if (comps != null && comps.QueryItems != null) { foreach (NSUrlQueryItem queryItem in comps.QueryItems) { if (queryItem.Name == "code") { var suppress = GetAndOpenActivity(queryItem.Value); return; } } } AppUtils.ShowSimpleDialog(this, "Not found", "Are you sure that was a valid OurPlace QR code?", "Got it"); }
public override async Task <bool> PrepareData(PlaybackData data, bool isPlaying) { playbackData = data; stateObserver?.Dispose(); stateObserver = null; CurrentSongId = data.SongId; AVPlayerItem playerItem = null; var songPlaybackData = data.SongPlaybackData; if (songPlaybackData.IsLocal || songPlaybackData.CurrentTrack.ServiceType == MusicPlayer.Api.ServiceType.iPod) { if (songPlaybackData.Uri == null) { return(false); } var url = string.IsNullOrWhiteSpace(songPlaybackData?.CurrentTrack?.FileLocation) ? new NSUrl(songPlaybackData.Uri.AbsoluteUri) : NSUrl.FromFilename(songPlaybackData.CurrentTrack.FileLocation); playerItem = AVPlayerItem.FromUrl(url); await playerItem.WaitStatus(); } else { #if HttpPlayback var urlEndodedSongId = HttpUtility.UrlEncode(data.SongId); var url = $"http://localhost:{LocalWebServer.Shared.Port}/api/GetMediaStream/Playback?SongId={urlEndodedSongId}"; playerItem = AVPlayerItem.FromUrl(new NSUrl(url)); #else NSUrlComponents comp = new NSUrlComponents( NSUrl.FromString( $"http://localhost/{songPlaybackData.CurrentTrack.Id}.{data.SongPlaybackData.CurrentTrack.FileExtension}"), false); comp.Scheme = "streaming"; if (comp.Url != null) { var asset = new AVUrlAsset(comp.Url, new NSDictionary()); asset.ResourceLoader.SetDelegate(resourceDelegate, DispatchQueue.MainQueue); playerItem = new AVPlayerItem(asset, (NSString)"duration"); stateObserver = playerItem.AddObserver("status", NSKeyValueObservingOptions.New, (obj) => { if (shouldBePlaying) { player.Play(); } Console.WriteLine($"Player Status {playerItem.Status}"); }); } #endif } player.ReplaceCurrentItemWithPlayerItem(playerItem); IsPrepared = true; return(true); }
public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation) { bool success = false; try { if (url != null) { NSUrlComponents urlComponents = new NSUrlComponents(url, false); string data = ""; string name = ""; NSUrlQueryItem[] allItems = urlComponents.QueryItems; foreach (NSUrlQueryItem item in allItems) { if (item.Name == "data") { data = item.Value; } else if (item.Name == "name") { name = item.Value; } } if (!string.IsNullOrEmpty(data) && !string.IsNullOrEmpty(name)) { success = true; Task.Factory.StartNew(async() => { await GlobalVars.ImportUserEventList(data, name); }); } } } catch (Exception) { } //if (success) //{ // return base.OpenUrl(application, url, sourceApplication, annotation); //} return(success); // }
public IceCream(MSMessage message) { if (message == null) { return; } var messageURL = message.Url; var urlComponents = new NSUrlComponents(messageURL, false); if (urlComponents.QueryItems == null) { return; } CheckQueryItems(urlComponents.QueryItems); }
private void Notify(NSUrl url) { NSUrlComponents components = new NSUrlComponents(url, false); NSUrlQueryItem token_part = ( from NSUrlQueryItem qi in components.QueryItems where qi.Name == "token" select qi ).FirstOrDefault(); if (token_part != null) { NSNotification notification = new NSNotification(null); NSNotificationCenter.DefaultCenter.PostNotification(notification); } }
private static NSDictionary SCC_HTTPGETParameters(NSUrl url) { var parameters = new NSMutableDictionary(); var components = NSUrlComponents.FromUrl(url, false); foreach (var queryItem in components.QueryItems) { if (queryItem.Value.Length > 0) { parameters.Add(new NSString(queryItem.Name), new NSString(queryItem.Value)); } else { parameters.Add(new NSString(queryItem.Name), null); } } return(parameters); }
MSMessage ComposeMessage(IceCream iceCream, string caption, MSSession session = null) { var components = new NSUrlComponents { QueryItems = iceCream.QueryItems }; var layout = new MSMessageTemplateLayout { Image = iceCream.RenderSticker(true), Caption = caption }; var message = new MSMessage(session ?? new MSSession()) { Url = components.Url, Layout = layout }; return(message); }
public void DecidePolicy(WKWebView webView, WKNavigationAction navigationAction, Action <WKNavigationActionPolicy> decisionHandler) { NSUrlComponents components = new NSUrlComponents(navigationAction.Request.Url, false) { Query = null }; if (_browserLinks.Contains(components.Url.AbsoluteString) || components.Host.Equals("privacy.microsoft.com", StringComparison.InvariantCultureIgnoreCase) || components.Host.Equals("www.microsoft.com", StringComparison.InvariantCultureIgnoreCase)) { UIApplication.SharedApplication.OpenUrl(navigationAction.Request.Url); decisionHandler(WKNavigationActionPolicy.Cancel); return; } decisionHandler(WKNavigationActionPolicy.Allow); }
public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation) { var urlComponents = new NSUrlComponents(url, false); var queryItems = urlComponents.QueryItems; foreach (NSUrlQueryItem item in queryItems) { if (item.Name == "id") { var package = item.Value; if (package != null && package != "") { Xamarin.Forms.MessagingCenter.Send <string, string>(Constants.NOTIFICATION, Constants.APP_LAUNCHED_FROM_DEEP_LINK, package); } } } return(true); }
public static IceCreamHistory Load() { var iceCreams = GetSavedIceCreams().Select(sic => { var components = NSUrlComponents.FromUrl(new NSUrl(sic), false); return(new IceCream(components.QueryItems)); }).ToList(); if (iceCreams.Count == 0) { iceCreams.Add(new IceCream(BaseType.base01, ScoopsType.scoops05, ToppingType.topping09)); iceCreams.Add(new IceCream(BaseType.base03, ScoopsType.scoops07, ToppingType.topping01)); iceCreams.Add(new IceCream(BaseType.base04, ScoopsType.scoops08, ToppingType.topping07)); iceCreams.Add(new IceCream(BaseType.base02, ScoopsType.scoops03, ToppingType.topping10)); iceCreams.Add(new IceCream(BaseType.base01, ScoopsType.scoops01, ToppingType.topping05)); var historyToSave = new IceCreamHistory(iceCreams); historyToSave.Save(); } return(new IceCreamHistory(iceCreams)); }
public override async Task <bool> PrepareData(PlaybackData data, bool isPlaying) { CurrentSongId = data.SongId; AVPlayerItem playerItem = null; var playbackData = data.SongPlaybackData; if (playbackData.IsLocal || playbackData.CurrentTrack.ServiceType == MusicPlayer.Api.ServiceType.iPod) { if (playbackData.Uri == null) { return(false); } var url = string.IsNullOrWhiteSpace(playbackData?.CurrentTrack?.FileLocation) ? new NSUrl(playbackData.Uri.AbsoluteUri) : NSUrl.FromFilename(playbackData.CurrentTrack.FileLocation); playerItem = AVPlayerItem.FromUrl(url); await playerItem.WaitStatus(); } else { #if HttpPlayback var urlEndodedSongId = HttpUtility.UrlEncode(data.SongId); var url = $"http://localhost:{LocalWebServer.Shared.Port}/api/GetMediaStream/Playback?SongId={urlEndodedSongId}"; playerItem = AVPlayerItem.FromUrl(new NSUrl(url)); #else NSUrlComponents comp = new NSUrlComponents( NSUrl.FromString( $"http://localhost/{playbackData.CurrentTrack.Id}.{data.SongPlaybackData.CurrentTrack.FileExtension}"), false); comp.Scheme = "streaming"; if (comp.Url != null) { var asset = new AVUrlAsset(comp.Url, new NSDictionary()); asset.ResourceLoader.SetDelegate(NativeAudioPlayer.LoaderDelegate, DispatchQueue.MainQueue); playerItem = new AVPlayerItem(asset); } #endif } player.ReplaceCurrentItemWithPlayerItem(playerItem); IsPrepared = true; return(true); }
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options) { if (this.Window?.RootViewController is UINavigationController navigationController && navigationController?.ViewControllers?.FirstOrDefault() is ForecastViewController initialViewController) { // Extract the daysFromNow query string parameter from the incoming URL. var components = NSUrlComponents.FromUrl(url, false); var daysFromNowValue = components?.QueryItems?.FirstOrDefault(item => item.Name == "daysFromNow")?.Value; if (string.IsNullOrEmpty(daysFromNowValue)) { throw new Exception("Expected daysFromNow parameter to have a value"); } if (int.TryParse(daysFromNowValue, out int daysFromNow)) { // Scroll the initial view controller to the correct index. initialViewController.ScrollToForecast(daysFromNow); return(true); } else { throw new Exception("Expected daysFromNow to be an integer"); } }
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options) { if (url != null) { NSUrlComponents urlComponents = new NSUrlComponents(url, false); string email = ""; NSUrlQueryItem[] allItems = urlComponents.QueryItems; foreach (NSUrlQueryItem item in allItems) { if (item.Name == "email") { email = item.Value; } } if (email != null && email != "") { Xamarin.Forms.MessagingCenter.Send <string, string>("", "AppLaunchedFromDeepLink", email); } } return(true); }
MSMessage ComposeMessage(IceCream iceCream, string caption, MSSession session = null) { var components = new NSUrlComponents { QueryItems = iceCream.QueryItems }; var layout = new MSMessageTemplateLayout { Image = iceCream.RenderSticker (true), Caption = caption }; var message = new MSMessage (session ?? new MSSession()) { Url = components.Url, Layout = layout }; return message; }
async Task <Tuple <bool, AVPlayerItem> > prepareSong(Song song, bool playVideo = false) { try { isVideo = playVideo; LogManager.Shared.Log("Preparing Song", song); var data = GetPlaybackData(song.Id); var playbackData = await MusicManager.Shared.GetPlaybackData(song, playVideo); if (playbackData == null) { return(new Tuple <bool, AVPlayerItem>(false, null)); } if (data.CancelTokenSource.IsCancellationRequested) { return(new Tuple <bool, AVPlayerItem>(false, null)); } AVPlayerItem playerItem = null; if (song == CurrentSong) { Settings.CurrentTrackId = playbackData.CurrentTrack.Id; isVideo = playbackData.CurrentTrack.MediaType == MediaType.Video; Settings.CurrentPlaybackIsVideo = isVideo; NotificationManager.Shared.ProcVideoPlaybackChanged(isVideo); } if (playbackData.IsLocal || playbackData.CurrentTrack.ServiceType == MusicPlayer.Api.ServiceType.iPod) { if (playbackData.Uri == null) { return(new Tuple <bool, AVPlayerItem>(false, null)); } LogManager.Shared.Log("Local track found", song); var url = string.IsNullOrWhiteSpace(playbackData?.CurrentTrack?.FileLocation) ? new NSUrl(playbackData.Uri.AbsoluteUri) : NSUrl.FromFilename(playbackData.CurrentTrack.FileLocation); playerItem = AVPlayerItem.FromUrl(url); await playerItem.WaitStatus(); NotificationManager.Shared.ProcSongDownloadPulsed(song.Id, 1f); } else { data.SongPlaybackData = playbackData; data.DownloadHelper = await DownloadManager.Shared.DownloadNow(playbackData.CurrentTrack.Id, playbackData.Uri); if (data.CancelTokenSource.IsCancellationRequested) { return(new Tuple <bool, AVPlayerItem>(false, null)); } LogManager.Shared.Log("Loading online Track", data.SongPlaybackData.CurrentTrack); SongIdTracks[data.SongPlaybackData.CurrentTrack.Id] = song.Id; NSUrlComponents comp = new NSUrlComponents( NSUrl.FromString( $"http://localhost/{playbackData.CurrentTrack.Id}.{data.SongPlaybackData.CurrentTrack.FileExtension}"), false); comp.Scheme = "streaming"; if (comp.Url != null) { var asset = new AVUrlAsset(comp.Url, new NSDictionary()); asset.ResourceLoader.SetDelegate(LoaderDelegate, DispatchQueue.MainQueue); playerItem = new AVPlayerItem(asset); } if (data.CancelTokenSource.IsCancellationRequested) { return(new Tuple <bool, AVPlayerItem>(false, null)); } await playerItem.WaitStatus(); } lastSeconds = -1; var success = !data.CancelTokenSource.IsCancellationRequested; return(new Tuple <bool, AVPlayerItem>(true, playerItem)); } catch (Exception ex) { LogManager.Shared.Report(ex); return(new Tuple <bool, AVPlayerItem>(false, null)); } }