public bool OpenUrl(UIApplication app, NSUrl url, string sourceApplication, NSObject annotation) { Debug.WriteLine("OpenUrl called with url: " + url.AbsoluteString, "auth"); SPTAuth auth = SPTAuth.DefaultInstance; // This is the callback that's triggerred when auth is completed (or fails). SPTAuthCallback authCallback = (NSError error, SPTSession session) => { if (error != null) { Debug.WriteLine("*** Authentication error: " + error.Description, "auth"); } else { auth.Session = session; Debug.WriteLine("Authentication successful. Notifying the plebs.", "auth"); NSNotificationCenter.DefaultCenter.PostNotificationName("sessionUpdated", this); } }; // Handle the callback from the authentication service if (auth.CanHandleURL(url)) { Debug.WriteLine("We can handle this Url.", "auth"); auth.HandleAuthCallbackWithTriggeredAuthURL(url, authCallback); return(true); } Debug.WriteLine("We cannot handle this Url.", "auth"); return(false); }
private void HandleOpenUrl(object sender, OpenUrlEventArgs e) { if (!_auth.CanHandleURL(e.Url)) { return; } _auth.HandleAuthCallbackWithTriggeredAuthURL(e.Url, (error, session) => { if (error != null && session.IsValid) { _auth.Session = session; _spotifyPlayer.LoginWithAccessToken(_auth.Session.AccessToken); } }); }