Пример #1
0
        public SpotifyMusicServiceIos()
        {
            // This needs to happen BEFORE auth slash streaming delegate, so if they login with a pre-existing session
            // we get the memo and can pass it on to the existing web api.
            this.setupTokenUpdater();

            sd = new SpotifyAuth(this).CreateStreamingDelegate();
        }
Пример #2
0
        public StreamingDelegate CreateStreamingDelegate()
        {
            Debug.WriteLine("Creating streaming delegate", "auth");

            var sd = new StreamingDelegate(this.service);

            SPTAuth auth = SPTAuth.DefaultInstance;

            // ClientID and RedirectURL come from http://developer.spotify.com/my-applications
            // TODO Move out of the service
            auth.ClientID = service.ClientId;

            // Request permission to do stuff
            // We should leave anything we don't use commented out
            auth.RequestedScopes = new NSObject[] {
                SpotifyConstants.SPTAuthStreamingScope,                   // Playing audio
                SpotifyConstants.SPTAuthPlaylistReadPrivateScope,
                SpotifyConstants.SPTAuthPlaylistReadCollaborativeScope,
                //SpotifyConstants.SPTAuthPlaylistModifyPublicScope,
                //SpotifyConstants.SPTAuthPlaylistModifyPrivateScope,
                //SpotifyConstants.SPTAuthUserFollowModifyScope,
                //SpotifyConstants.SPTAuthUserFollowReadScope,
                SpotifyConstants.SPTAuthUserLibraryReadScope,
                //SpotifyConstants.SPTAuthUserLibraryModifyScope,
                SpotifyConstants.SPTAuthUserReadPrivateScope,             // Gives access to user's country
                //SpotifyConstants.SPTAuthUserReadTopScope,
                //SpotifyConstants.SPTAuthUserReadBirthDateScope,
                SpotifyConstants.SPTAuthUserReadEmailScope
            };

            // Callback
            auth.RedirectURL = new Foundation.NSUrl(service.SpotifyCallback);

            // Enables SPTAuth to automatically store the session object for future use.
            auth.SessionUserDefaultsKey = @"SpotifySession";

            // TODO: Use a token swap service
            //auth.TokenSwapURL;
            //auth.TokenRefreshURL;

            // If we have a valid session, notify that the session was updated so player gets setup
            if (auth.Session != null && auth.Session.IsValid)
            {
                Debug.WriteLine("We have an existing, valid session. Reusing it.", "auth");
                NSNotificationCenter.DefaultCenter.PostNotificationName("sessionUpdated", this);
            }
            else
            {
                Debug.WriteLine("We do not have a valid session.", "auth");
            }
            return(sd);
        }