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

fixed issue with wrong state-machine after pull down gesture on presented SFSafariViewController #415

Merged
merged 3 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ Changelog
Version numbering represents the Swift version, plus a running number representing updates, fixes and new features at the same time.
You can also refer to commit logs to get details on what was implemented, fixed and improved.

#### 5.3.4

- Fixed issue with wrong states on dismiss via pull down gesture.

#### 5.3.3

- Make ASWebAuthenticationSession work on macOS
- Minor maintenance
- Add deprecation notices to using the custom web view controller on iOS, which will be removed in v 6.


#### 5.3.2

- Fix tvOS build.
Expand Down
4 changes: 2 additions & 2 deletions OAuth2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 5.3.3;
MARKETING_VERSION = 5.3.4;
METAL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -971,7 +971,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 5.3.3;
MARKETING_VERSION = 5.3.4;
METAL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 5.0;
Expand Down
20 changes: 13 additions & 7 deletions Sources/iOS/OAuth2Authorizer+iOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI {
/// The OAuth2 instance this authorizer belongs to.
public unowned let oauth2: OAuth2Base

/// Used to store the `SFSafariViewControllerDelegate`.
private var safariViewDelegate: AnyObject?
/// Used to store the `SFSafariViewControllerDelegate` || `UIAdaptivePresentationControllerDelegate`
private var safariViewDelegate: OAuth2SFViewControllerDelegate?

/// Used to store the authentication session.
private var authenticationSession: AnyObject?
Expand Down Expand Up @@ -211,7 +211,7 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI {
safariViewDelegate = OAuth2SFViewControllerDelegate(authorizer: self)
let web = SFSafariViewController(url: url)
web.title = oauth2.authConfig.ui.title
web.delegate = safariViewDelegate as! OAuth2SFViewControllerDelegate
web.delegate = safariViewDelegate
if let barTint = oauth2.authConfig.ui.barTintColor {
web.preferredBarTintColor = barTint
}
Expand All @@ -222,7 +222,7 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI {

willPresent(viewController: web, in: nil)
controller.present(web, animated: true, completion: nil)

web.presentationController?.delegate = safariViewDelegate
return web
}

Expand Down Expand Up @@ -310,18 +310,24 @@ open class OAuth2Authorizer: OAuth2AuthorizerUI {
/**
A custom `SFSafariViewControllerDelegate` that we use with the safari view controller.
*/
class OAuth2SFViewControllerDelegate: NSObject, SFSafariViewControllerDelegate {
class OAuth2SFViewControllerDelegate: NSObject, SFSafariViewControllerDelegate, UIAdaptivePresentationControllerDelegate {

let authorizer: OAuth2Authorizer
weak var authorizer: OAuth2Authorizer?

init(authorizer: OAuth2Authorizer) {
self.authorizer = authorizer
}

@available(iOS 9.0, *)
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
authorizer.safariViewControllerDidCancel(controller)
authorizer?.safariViewControllerDidCancel(controller)
}

// called in case ViewController is dismissed via pulling down the presented sheet.
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
guard let safariViewController = presentationController.presentedViewController as? SFSafariViewController else { return }
authorizer?.safariViewControllerDidCancel(safariViewController)
}
}
#endif

Expand Down