Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Commit

Permalink
Adapt for iOS 11
Browse files Browse the repository at this point in the history
  • Loading branch information
polqf committed Jul 4, 2017
1 parent 5cc280f commit 1b0a63f
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions TwitterAuth/Source/TwitterAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,36 +91,43 @@ public class TwitterAuth {
self.notifyWebLoginError(.wrongCallback)
return
}

apiManager.obtainAccessToken(withResult: result) { (result, error) -> () in
guard let result = result else {
self.notifyWebLoginError(error ?? .unknown)
return
}
if self.saveInACAccounts {
self.saveAccount(withResult: result) { succeed in
succeed ? self.notifyWebLoginSuccess(result) : self.notifyWebLoginError(.unableToSaveAccount)
}
return
}
guard let result = result else {
self.notifyWebLoginError(error ?? .unknown)
return
}

// In iOS 11 we can no longer access to Twitter in ACAccounts
var isiOS11 = false
if #available(iOS 11, *) {
isiOS11 = true
}

if isiOS11 || self.saveInACAccounts == false {
self.notifyWebLoginSuccess(result)
return
}

self.saveAccount(withResult: result) { succeed in
succeed ? self.notifyWebLoginSuccess(result) : self.notifyWebLoginError(.unableToSaveAccount)
}
}
}



//MARK: Private methods

private func notifyWebLoginSuccess(_ result: TwitterAuthResult) {
Threading.executeOnMainThread {
self.webLoginDelegate?.didSuccedRetrivingToken(result)
self.hideSafariViewController()
self.webLoginDelegate?.didSuccedRetrivingToken(result)
}
}

private func notifyWebLoginError(_ error: TwitterAuthError) {
Threading.executeOnMainThread {
self.webLoginDelegate?.didFailRetrievingToken(error)
self.hideSafariViewController()
self.webLoginDelegate?.didFailRetrievingToken(error)
}
}

Expand Down

0 comments on commit 1b0a63f

Please sign in to comment.