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
WebViewAuthenticator
and UIKit
#48
Comments
Of course you can use it with For instance, for logging in, you can rely on import UIKit
import WebKit
import Swiftagram
import SwiftagramCrypto
class LoginViewController: UIViewController {
/// The completion handler.
var completion: ((Secret) -> Void)?
/// The web view.
var webView: WKWebView? {
didSet {
guard let webView = webView else { return }
webView.frame = view.frame
view.addSubview(webView)
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Authenticate.
WebViewAuthenticator(storage: KeychainStorage()) { self.webView = $0 }
.authenticate { [weak self] in
switch $0 {
case .failure(let error): print(error.localizedDescription)
case .success(let secret):
self?.completion?(secret)
self?.dismiss(animated: true, completion: nil)
}
}
}
} |
I try this code to implement in my project. But WKWebView does not load Instagram login, you can try to create the project and set up your own login. It's not working |
What version of Xcode are you on? If it gives you an error, do you mind pasting it here? |
Xcode 11.5. It seems to me that the problem is in the WebViewAuthenticator, because at first I built my project with UIkit and an example from Followers, and it does not work, and then using swift UI everything is fine. |
It's working. Thank you for your support. |
When you reassign the I'll add auto layout constraints to import UIKit
import WebKit
import Swiftagram
import SwiftagramCrypto
class LoginViewController: UIViewController {
/// The completion handler.
var completion: ((Secret) -> Void)?
/// The web view.
var webView: WKWebView? {
didSet {
guard let webView = webView else { return }
webView.frame = view.frame
webView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(webView)
// Add constraints.
NSLayoutConstraint.activate([
webView.topAnchor.constraint(equalTo: webView.topAnchor),
webView.leadingAnchor.constraint(equalTo: webView.leadingAnchor),
webView.trailingAnchor.constraint(equalTo: webView.trailingAnchor),
webView.bottomAnchor.constraint(equalTo: webView.bottomAnchor)
])
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Authenticate.
WebViewAuthenticator(storage: KeychainStorage()) { self.webView = $0 }
.authenticate { [weak self] in
switch $0 {
case .failure(let error): print(error.localizedDescription)
case .success(let secret):
self?.completion?(secret)
self?.dismiss(animated: true, completion: nil)
}
}
}
} |
WebViewAuthenticator
and UIKit
WebViewAuthenticator
and UIKit
Hello. Can't embed swiftagram usage in UIKit. Should the library work not in swift ui or is it not available at the moment?
The text was updated successfully, but these errors were encountered: