[GH-ISSUE #167] Example usage for OAuthWebViewController #101

Closed
opened 2026-03-03 16:45:41 +03:00 by kerem · 4 comments
Owner

Originally created by @aozbayra on GitHub (Dec 27, 2015).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/167

Like everyone else I am trying to open the sign in process through a web view instead of Safari. This is the piece of code I have:

    if #available(iOS 9.0, *) {
        oauthswift.authorize_url_handler = SafariURLHandler(viewController: self)
    }
    else {
        let webView = OAuthWebViewController()
        oauthswift.authorize_url_handler = webView
    }

SafariURLHandler works fine but the OAuthWebViewController does not work I need to present the webvViewController both from the root view controller and some other view controller.

What is the proper implementation of OAuthWebViewController in my case? Thank you in advance.

Originally created by @aozbayra on GitHub (Dec 27, 2015). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/167 Like everyone else I am trying to open the sign in process through a web view instead of Safari. This is the piece of code I have: ``` if #available(iOS 9.0, *) { oauthswift.authorize_url_handler = SafariURLHandler(viewController: self) } else { let webView = OAuthWebViewController() oauthswift.authorize_url_handler = webView } ``` SafariURLHandler works fine but the OAuthWebViewController does not work I need to present the webvViewController both from the root view controller and some other view controller. What is the proper implementation of OAuthWebViewController in my case? Thank you in advance.
kerem 2026-03-03 16:45:41 +03:00
Author
Owner

@phimage commented on GitHub (Dec 27, 2015):

version used?
message, log, error ? maybe #154

Did you try breakpoint into OAuthWebViewController, doHandle method ?
Before 0.5.0 only root view controller was used, now there is a code which try to get current controller, see UIApplication.topViewController (could be bugged in specific view controller hierachy)

demo show example of OAuthWebViewController subclass
https://github.com/OAuthSwift/OAuthSwift/blob/master/OAuthSwiftDemo/WebViewController.swift

<!-- gh-comment-id:167435679 --> @phimage commented on GitHub (Dec 27, 2015): version used? message, log, error ? maybe #154 Did you try breakpoint into OAuthWebViewController, doHandle method ? Before 0.5.0 only root view controller was used, now there is a code which try to get current controller, see [UIApplication.topViewController](https://github.com/OAuthSwift/OAuthSwift/blob/master/OAuthSwift/UIApplication%2BOAuthSwift.swift) (could be bugged in specific view controller hierachy) demo show example of OAuthWebViewController subclass https://github.com/OAuthSwift/OAuthSwift/blob/master/OAuthSwiftDemo/WebViewController.swift
Author
Owner

@aozbayra commented on GitHub (Dec 28, 2015):

Ok yeah I know about that recursive code I used it before. I have the above lines on two places on of them being the root view controller. When I try it on the root view controller I am getting the black screen so maybe I am not adding the view to the hierarchy but I thought that was being done inside doHandle on this line:
UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(
self, animated: true, completion: nil)
I pulled the code through cocoaPods and oauthswift.version.shortVersion gives me 2.0. What else would you recommend me to add into this piece of code?
if #available(iOS 9.0, *) {
oauthswift.authorize_url_handler = SafariURLHandler(viewController: self)
}
else {
let webView = OAuthWebViewController()
oauthswift.authorize_url_handler = webView
}

<!-- gh-comment-id:167497370 --> @aozbayra commented on GitHub (Dec 28, 2015): Ok yeah I know about that recursive code I used it before. I have the above lines on two places on of them being the root view controller. When I try it on the root view controller I am getting the black screen so maybe I am not adding the view to the hierarchy but I thought that was being done inside doHandle on this line: UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController( self, animated: true, completion: nil) I pulled the code through cocoaPods and oauthswift.version.shortVersion gives me 2.0. What else would you recommend me to add into this piece of code? if #available(iOS 9.0, *) { oauthswift.authorize_url_handler = SafariURLHandler(viewController: self) } else { let webView = OAuthWebViewController() oauthswift.authorize_url_handler = webView }
Author
Owner

@phimage commented on GitHub (Dec 28, 2015):

There is no version 2.0, see https://github.com/OAuthSwift/OAuthSwift/releases
If you use cocoapod there is a PodFile.lock near PodFile with version used

Please update because that following code is old, previous 0.5.0
UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(
now as I say we try to get current top view controller

and yes the code according to ios version is good, except that instead of using OAuthWebViewController you can make your own class with an embeded webview

<!-- gh-comment-id:167498255 --> @phimage commented on GitHub (Dec 28, 2015): There is no version 2.0, see https://github.com/OAuthSwift/OAuthSwift/releases If you use cocoapod there is a PodFile.lock near PodFile with version used Please update because that following code is old, previous 0.5.0 `UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(` now as I say we try to get current top view controller and yes the code according to ios version is good, except that instead of using `OAuthWebViewController` you can make your own class with an embeded webview
Author
Owner

@aozbayra commented on GitHub (Dec 28, 2015):

As per your advice, I used my own class like in the demo and I have updated my version to 0.5. It is working fine right now, thank you for your help.

<!-- gh-comment-id:167577554 --> @aozbayra commented on GitHub (Dec 28, 2015): As per your advice, I used my own class like in the demo and I have updated my version to 0.5. It is working fine right now, thank you for your help.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#101
No description provided.