Hello guys,
I use TwitterKit for my iOS application. I followed the instruction in the document and it seemingly worked well but the session expires in a day.
I think the session won’t be nil. Could you find something wrong in my code below?
final class wdTwitterService: NSObject {
override static func initialize() {
// API keys are written in info.plist.
Fabric.with([Twitter.self])
}
static func login(completion:(String) -> Void, failed: (NSError?) -> Void) {
Twitter.sharedInstance().logInWithCompletion { session, error in
if let session = session {
// Save the logged username
var namesDic = [String: String]()
if let names = wdUserDefault.objectForKey(UD_TWITTER_USERNAMES) as? [String: String] {
namesDic = names
}
namesDic[session.userID] = session.userName
wdUserDefault.setObject(namesDic, key: UD_TWITTER_USERNAMES)
completion(session.userName)
} else {
failed(nil)
}
}
}
static func isLoggedIn() -> Bool {
if let _ = Twitter.sharedInstance().sessionStore.session() {
return true
}
return false
}
static var session: TWTRAuthSession? {
get {
if let session = Twitter.sharedInstance().sessionStore.session() {
return session
}
return nil
}
}
}