Session Recovery in Deezer iOS SDK

I use the Deezer iOS SDK , everything is going fine in Swift so far, except for the session, in the Android SDK the method .restoreSession()exists to not enter the username of the pop-up window in time, but I do not see it in the iOS SDK, so every time the session time has expired, users get a pop-up login window again using their Deezer account, in any case, to save or restore the session in the iOS SDK?

This is the Android recovery session code:

// restore any saved session
SessionStore sessionStore = new SessionStore();
if (sessionStore.restore(deezerConnect, context)) {
    // The restored session is valid, navigate to the Home Activity
    Intent intent = new Intent(context, HomeActivity.class);
    startActivity(intent); 
}

Is it possible to do this in the iOS SDK?

because when a user logs in with the Deezer SDK, I do not receive a notification from the delegate

class DeezerSession : NSObject, DeezerSessionDelegate
{


    var DZRReqManager:DZRRequestManager = DZRRequestManager()
    var deezerConnect:DeezerConnect!

    let defaults = UserDefaults.standard
    var callbackLogin : (()->())? = nil

    //SHARED INSTANCE
    static var instance: DeezerSession!
    class func sharedInstance() -> DeezerSession {
        if self.instance == nil
        {
            self.instance  = DeezerSession();
        }
        return self.instance
    }

    override init()
    {
        super.init()
        self.deezerConnect                  = DeezerConnect(appId: "***" , andDelegate: self )
        self.DZRReqManager.dzrConnect       = self.deezerConnect
        self.deezerConnect.sessionDelegate  = self

        self.retrieveTokenAndExpirationDate()
    }

    // See http://www.deezer.com/fr/developers/simpleapi/permissions
    // for a description of the permissions
    func connectToDeezerWithPermissions()
    {
        print("[DeezerSession] connectToDeezerWithPermissions.")

        //Check if Session still valid update it
        self.deezerConnect.authorize([DeezerConnectPermissionBasicAccess,
                                      DeezerConnectPermissionManageLibrary,
                                      DeezerConnectPermissionOfflineAccess
                                      ])
    }

    func saveToken(token:String,expirationDate:Date,userId:String)
    {
        print("[DeezerSession] Token. \(token) : Saved ")
        print("[DeezerSession] Expire Date after. \(expirationDate) : Saved ")
        print("[DeezerSession] User ID . \(userId) : Saved ")

        defaults.setValue(token, forKey: "DEEZER_TOKEN_KEY")
        defaults.setValue(expirationDate, forKey: "DEEZER_EXPIRATION_DATE_KEY")
        defaults.setValue(userId, forKey: "DEEZER_USER_ID_KEY")
    }

    func deezerSessionDidConnect()
    {


    }

    func retrieveTokenAndExpirationDate()
    {
        self.deezerConnect.accessToken      = defaults.string(forKey: "DEEZER_TOKEN_KEY")
        self.deezerConnect.expirationDate   = defaults.object(forKey: "DEEZER_EXPIRATION_DATE_KEY") as? Date ?? Date()
        self.deezerConnect.userId           = defaults.string(forKey: "DEEZER_USER_ID_KEY")

        print("[DeezerSession] Token. \(self.deezerConnect.accessToken) : Restored ")
        print("[DeezerSession] Expire Date. \(self.deezerConnect.expirationDate) : Restored ")
        print("[DeezerSession] User ID . \(self.deezerConnect.userId) : Restored ")
    }

    func isSessionValid()-> Bool
    {
        print("[DeezerSession] isSessionValid . \(self.deezerConnect.isSessionValid()) ")
        return self.deezerConnect.isSessionValid()
    }


    func deezerDidLogin()
    {
        print("[DeezerSession] deezerDidLogin.")
        self.saveToken(token : self.deezerConnect.accessToken,
                       expirationDate : self.deezerConnect.expirationDate  ,
                       userId : self.deezerConnect.userId)

        if  self.callbackLogin != nil
        {
            self.callbackLogin!()
        }
    }

     func deezerDidNotLogin()-> Bool
    {
        print("[DeezerSession] deezerDidNotLogin.")
        return true
    }

     func deezerDidLogout()
    {
        print("[DeezerSession] deezerDidLogout.")
    }

}

all delegates do not shoot deezerDidLogout deezerDidNotLogin deezerDidLogin

+4
1

SDK DeezerSessionDelegate. deezerDidLogin, .

, DeezerConnect , . .

, , DeezerConnect ( Keychain) , - [DeezerConnect isSessionValid] . - , .

, Keychain .

: iOS

singleton?

//SHARED INSTANCE
static var instance: DeezerSession!
class func sharedInstance() -> DeezerSession {
    if self.instance == nil
    {
        self.instance  = DeezerSession();
    }
    return self.instance
}

static let shared = DeezerSession()

singleton Swift.

, override init.

+1

Source: https://habr.com/ru/post/1685209/


All Articles