-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make iOS twitter login default using SFSafariViewController
- Loading branch information
huiping.guo
committed
Jan 15, 2020
1 parent
8889232
commit 2a0b841
Showing
3 changed files
with
75 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// WebAuthenticationViewController.swift | ||
// SwifteriOS | ||
// | ||
// Created by Huiping Guo on 2020/01/14. | ||
// Copyright © 2020 Matt Donnelly. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
import SafariServices | ||
|
||
class WebAuthenticationViewController: UIViewController { | ||
|
||
let queryUrl: URL | ||
|
||
let dismissHandler: (() -> Void)? | ||
|
||
init(queryUrl: URL, dismissHandler: (() -> Void)? = nil) { | ||
self.queryUrl = queryUrl | ||
self.dismissHandler = dismissHandler | ||
super.init(nibName: nil, bundle: nil) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
embedViewController(viewController: createWebViewController()) | ||
} | ||
|
||
func embedViewController(viewController: UIViewController) { | ||
guard let subview = viewController.view, let superview = view else { return } | ||
|
||
addChild(viewController) | ||
view.addSubview(subview) | ||
|
||
subview.translatesAutoresizingMaskIntoConstraints = false | ||
subview.topAnchor.constraint(equalTo: superview.topAnchor, constant: 0).isActive = true | ||
subview.bottomAnchor.constraint(equalTo: superview.bottomAnchor, constant: 0).isActive = true | ||
subview.leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: 0).isActive = true | ||
subview.trailingAnchor.constraint(equalTo: superview.trailingAnchor, constant: 0).isActive = true | ||
|
||
viewController.didMove(toParent: self) | ||
} | ||
|
||
func createWebViewController() -> SFSafariViewController { | ||
let safariView = SFSafariViewController(url: queryUrl) | ||
safariView.delegate = self | ||
safariView.modalTransitionStyle = .coverVertical | ||
safariView.modalPresentationStyle = .overFullScreen | ||
return safariView | ||
} | ||
} | ||
|
||
extension WebAuthenticationViewController: SFSafariViewControllerDelegate { | ||
func safariViewControllerDidFinish(_ controller: SFSafariViewController) { | ||
dismissHandler?() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters