Adds altstore://source?url=[link] deep link to add sources

This commit is contained in:
Riley Testut
2020-08-28 12:15:15 -07:00
parent 4c3d33efdc
commit 70a475ff5f
3 changed files with 169 additions and 21 deletions

View File

@@ -21,12 +21,52 @@ extension TabBarController
class TabBarController: UITabBarController
{
private var initialSegue: (identifier: String, sender: Any?)?
private var _viewDidAppear = false
required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
NotificationCenter.default.addObserver(self, selector: #selector(TabBarController.openPatreonSettings(_:)), name: AppDelegate.openPatreonSettingsDeepLinkNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(TabBarController.importApp(_:)), name: AppDelegate.importAppDeepLinkNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(TabBarController.presentSources(_:)), name: AppDelegate.addSourceDeepLinkNotification, object: nil)
}
override func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear(animated)
_viewDidAppear = true
if let (identifier, sender) = self.initialSegue
{
self.initialSegue = nil
self.performSegue(withIdentifier: identifier, sender: sender)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
guard segue.identifier == "presentSources",
let notification = sender as? Notification,
let sourceURL = notification.userInfo?[AppDelegate.addSourceDeepLinkURLKey] as? URL
else { return }
let navigationController = segue.destination as! UINavigationController
let sourcesViewController = navigationController.viewControllers.first as! SourcesViewController
sourcesViewController.deepLinkSourceURL = sourceURL
}
override func performSegue(withIdentifier identifier: String, sender: Any?)
{
guard _viewDidAppear else {
self.initialSegue = (identifier, sender)
return
}
super.performSegue(withIdentifier: identifier, sender: sender)
}
}
@@ -34,6 +74,31 @@ extension TabBarController
{
@objc func presentSources(_ sender: Any)
{
if let presentedViewController = self.presentedViewController
{
if let navigationController = presentedViewController as? UINavigationController,
let sourcesViewController = navigationController.viewControllers.first as? SourcesViewController
{
if let notification = (sender as? Notification),
let sourceURL = notification.userInfo?[AppDelegate.addSourceDeepLinkURLKey] as? URL
{
sourcesViewController.deepLinkSourceURL = sourceURL
}
else
{
// Don't dismiss SourcesViewController if it's already presented.
}
}
else
{
presentedViewController.dismiss(animated: true) {
self.presentSources(sender)
}
}
return
}
self.performSegue(withIdentifier: "presentSources", sender: sender)
}
}