Skip to content

Commit

Permalink
fixed issue with wrong state-machine after pull down gesture on prese…
Browse files Browse the repository at this point in the history
…nted SFSafariViewController (#415)

In case the SFSafariViewController is presented modally, it can be dismissed via pull down gesture. In that case the state machine is completely broken. Therefore I added the presentationDelegate, which ensures that the same logic is triggered as in case the "Finished" button is pressed with this interaction.
  • Loading branch information
cbruns1985 authored Feb 21, 2024
1 parent b6faebb commit 6e3080c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
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

0 comments on commit 6e3080c

Please sign in to comment.