mirror of
https://github.com/OAuthSwift/OAuthSwift.git
synced 2026-04-26 12:45:52 +03:00
[GH-ISSUE #549] Crash on using twitter as client and Webviews #363
Labels
No labels
bug
cocoapod
duplicate
enhancement
feature-request
help wanted
help wanted
invalid
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/OAuthSwift#363
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sanchgoel on GitHub (Sep 30, 2019).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/549
Description:
Crash after line super.handle(url) ... using WebView or WkWebView.
override func handle(_ url: URL) {
targetURL = url
super.handle(url)
self.loadAddressURL()
}
#Error In Xcode
'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <Influencer.TwitterViewController: 0x7f91ddf0b080>.'
Where TwitterViewController is the controller implementing OAuthViewController
OAuth Provider? (Twitter, Github, ..):
Twitter
OAuth Version:
OS (Please fill the version) :
Installation method:
Library version:
Xcode version:
11.x (Swift 5.1)
10.x (Swift 5.0)
10.x (Swift 4.1)
9.3 (Swift 4.1)
9.0 (Swift 4.0)
other: (Please fill in the version you are using.)
objective c
@phimage commented on GitHub (Sep 30, 2019):
it depend on your application code. I cannot figure what append
you use OAuthWebViewController ? if yes try change value of useTopViewControlerInsteadOfNavigation
or put OAuthWebViewController as children of your controller
@sanchgoel commented on GitHub (Oct 3, 2019):
Hey @phimage ... it worked, the webview was redirected to twitter ... login was done and twitter was given authorization. I was redirected to the url, i received token and verifier but i didn't get any callback in the authorize block.
let _ = oauthswift.authorize(
withCallbackURL: URL(string: "https://api-dev.kyral.app/callback/twitter")!) { result in
switch result {
case .success(let (_, _, _)):
self.testTwitter(oauthswift)
case .failure(let error):
print(error.description)
}
}
^ No callback received here.
Here test twitter is the method to get the timeline of twitter.
func testTwitter(_ oauthswift: OAuth1Swift) {
let stringUrl = "https://api.twitter.com/1.1/statuses/mentions_timeline.json"
let _ = oauthswift.client.get(stringUrl, parameters: [:]) { result in
switch result {
case .success(let response):
let jsonDict = try? response.jsonObject()
print(String(describing: jsonDict))
case .failure(let error):
print(error)
}
}
}
Can you please tell me a way by which i can hit this url after receiving oauth_token and oauth_verifier successfully? Or what did i do wrong that i didn't receive any callback in the authorize block.
Thanks!
@phimage commented on GitHub (Oct 3, 2019):
did you pass now into handle(_ url: ? (put a breakpoint)
because handle will decode the url and call the callback passed in
authorize@sanchgoel commented on GitHub (Oct 3, 2019):
@phimage i have implemented the handle method in my webviewcontroller
I tried putting a breakpoint here. i got the url in the handle method but i still didn't get any callback in the authorize block
@sanchgoel commented on GitHub (Oct 23, 2019):
@phimage Any suggestion?
@phimage commented on GitHub (Oct 23, 2019):
@sanchgoel did you respond to my question?
https://github.com/OAuthSwift/OAuthSwift#handle-url-in-appdelegate
@sanchgoel commented on GitHub (Oct 23, 2019):
@phimage I have implemented handle url in app delegate
I am sorry i couldn't explain you my problem properly.
I implemented the twitter login using WKWebView. I am attaching the two files that i created for this ... Can you please see and let me know what i implemented wrong.
I am able to open the twitter login in webview ... then i am able to authorise the app ... I receive the oauth token and verifier from the redirected Url ... But i don't know how to get back to the callback in twitterViewController. Please have a look at the two files attached.
Or if you could suggest how can i call the twitter timeline api using the oauth token and verifier i received in the redirect url.
TwitterFiles.zip
Thanks for helping!
@phimage commented on GitHub (Oct 23, 2019):
your callback url is https://api-dev.kyral.app/callback/twitter
but you keep code about "oauth-swift" url scheme
let url = navigationAction.request.url, url.scheme == "oauth-swift"Dit https://api-dev.kyral.app/callback/twitter redirect to oauth-swift://xxxx.? with token etc??
The app delegate code that must be executed is "OAuthSwift.handle(url: url)"
And IT IS my first question, did you put a breakpoint here...
if you implement as you say app delegate, you have that code
and it is because
UIApplication.shared.open(url, options: [:], completionHandler: nil)will open oauth-swift:// and then the code in app delegate will be executedif you cannot use url scheme because of your https://api-dev.kyral.app/callback/twitter
you check that the url match your one and make the same call that you can see here :
https://github.com/OAuthSwift/OAuthSwift/blob/1.4.1/Demo/Common/WebViewController.swift#L86
or call directly "OAuthSwift.handle(url: url)" to launch the callback
@sanchgoel commented on GitHub (Oct 23, 2019):
@phimage Yes it was not being called due to the https://api-dev.kyral.app/callback/twitter
It worked using the OAuthSwift.handle(url: url)
Thanks a lot!