title: Spotify session management
body: <p>I have a spotify login in my app and try to made an autologin:</p>
  
  <p><strong>Login function</strong></p>
  
  <pre><code>func getSpotifyToken(fromController controller: UIViewController, success: (spotifyToken: String?) -&gt; Void, failure: (error: NSError?) -&gt; Void) {
  
      loginSuccessBlock = success
      loginFailureBlock = failure
  
      SPTAuth.defaultInstance().clientID        = SpotifyClientID
      SPTAuth.defaultInstance().redirectURL     = NSURL(string: SpotifyRedirectURI)
      SPTAuth.defaultInstance().requestedScopes = [SPTAuthStreamingScope, SPTAuthPlaylistReadPrivateScope]
  
      let spotifyLoginController = SPTAuthViewController.authenticationViewController()
      spotifyLoginController.delegate = self
      spotifyLoginController.clearCookies { () -&gt; Void in
          controller.presentViewController(spotifyLoginController, animated: true, completion: nil)
      }
  }
  </code></pre>
  
  <p><strong>Check if session exist</strong></p>
  
  <pre><code>private func spotifyConnected() -&gt; Bool {        
      if SPTAuth.defaultInstance().session == nil {
          self.loadSpotifySession()
      }        
      return SPTAuth.defaultInstance().session != nil
  }
  </code></pre>
  
  <p><strong>Save session</strong></p>
  
  <pre><code>private func saveSpotifySession() {
      let sessionData = NSKeyedArchiver.archivedDataWithRootObject(SPTAuth.defaultInstance().session)
      NSUserDefaults.standardUserDefaults().setObject(sessionData, forKey: Spotify_Session_Key)
      NSUserDefaults.standardUserDefaults().synchronize()
  }
  </code></pre>
  
  <p><strong>Load session</strong></p>
  
  <pre><code>private func loadSpotifySession() {        
      if let sessionData = NSUserDefaults.standardUserDefaults().objectForKey(Spotify_Session_Key) as? NSData {
          let session = NSKeyedUnarchiver.unarchiveObjectWithData(sessionData) as! SPTSession
          SPTAuth.defaultInstance().session = session
      }
  }
  </code></pre>
  
  <p><strong>Renew session - call at app start</strong></p>
  
  <pre><code>func renewSpotifySession() {        
      guard spotifyConnected() else {
          return
      }
  
      SPTAuth.defaultInstance().renewSession(SPTAuth.defaultInstance().session) { (error: NSError!, session: SPTSession!) -&gt; Void in
          if session != nil {
              SPTAuth.defaultInstance().session = session                
          } else {
              print("Failed to refresh spotify session")
          }
      }        
  }
  </code></pre>
  
  <p>renewSession return nil.
  I saw some info about refreshToken, But I don't know, where I can catch it.</p>
  
  <p>How I can renew spotify session? maybe I made something wrong?</p>