Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid WebAuth to retain UIApplication root ViewController #95

Merged
merged 3 commits into from
Mar 5, 2017

Conversation

cocojoe
Copy link
Member

@cocojoe cocojoe commented Mar 3, 2017

If initialised before viewDidAppear the rootView would be stored as nil and any subsequent request to present WebAuth will fail.

Example

class ViewController: UIViewController {

    var webAuth: WebAuth!

    override func viewDidLoad() {

        webAuth = Auth0.webAuth()

func present(_ controller: UIViewController) {
topViewController?.present(controller, animated: true, completion: nil)
}

var topViewController: UIViewController? {
guard let root = rootViewController else { return nil }
guard let root = UIApplication.shared.keyWindow?.rootViewController else { return nil }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep the old behaviour of allowing it to pass a root controller and if its nil, default to the one from UIApplication when there is the need to present a VC

@@ -144,7 +144,7 @@ private func decode(jwt: String) -> [String: Any]? {
let paddingLength = requiredLength - length
if paddingLength > 0 {
let padding = "".padding(toLength: Int(paddingLength), withPad: "=", startingAt: 0)
base64 = base64 + padding
base64 += padding
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a big fan of this, I'd rather use string interpolation so its clearer

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was really just to please a SwiftLint error, I'll make an exception. I was a bit surprised that this was an error

@hzalaz hzalaz added this to the v1-Next milestone Mar 5, 2017
@hzalaz hzalaz changed the title Fix WebAuth cannot be presented in certain circumstances Avoid WebAuth to retain UIApplication root ViewController Mar 5, 2017
@hzalaz hzalaz merged commit 3b1192d into master Mar 5, 2017
@hzalaz hzalaz deleted the fix_webauth_controller branch March 5, 2017 22:19
@hzalaz hzalaz modified the milestones: v1-Next, 1.3.0 Mar 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants