Skip to content

Commit

Permalink
Allow developer to get controller to show lock.
Browse files Browse the repository at this point in the history
Always calls callback on success/critical error even if lock was not presented
  • Loading branch information
hzalaz committed Nov 28, 2016
1 parent d9fd2e3 commit a6acaa0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Lock/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ class Router: Navigable {
}
}
self.onAuthentication = { [weak controller] credentials in
Queue.main.async {
controller?.presentingViewController?.dismiss(animated: true, completion: { _ in
lock.callback(.success(credentials))
})
let closure: () -> ()
if let presentingController = controller?.presentingViewController {
closure = {
presentingController.dismiss(animated: true, completion: { _ in
lock.callback(.success(credentials))
})
}
} else {
closure = { lock.callback(.success(credentials)) }
}
Queue.main.async(closure)
}

self.onBack = {
Expand Down
14 changes: 14 additions & 0 deletions LockTests/Router/RouterSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@ class RouterSpec: QuickSpec {
}
}

it("should call callback with auth result when lock was displayed without present") {
controller.presenting = nil
let credentials = Credentials(accessToken: "ACCESS_TOKEN", tokenType: "bearer")
waitUntil(timeout: 2) { done in
lock.callback = { result in
if case .success(let actual) = result {
expect(actual) == credentials
done()
}
}
router.onAuthentication(credentials)
}
}

describe("back") {

beforeEach {
Expand Down

0 comments on commit a6acaa0

Please sign in to comment.