Fixes deep links not working when app is not running

This commit is contained in:
Riley Testut 2019-02-21 15:56:49 -08:00
parent e63a525671
commit 0babc81914
3 changed files with 28 additions and 2 deletions

View File

@ -19,6 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate
var window: UIWindow?
private let deepLinkController = DeepLinkController()
private var appLaunchDeepLink: DeepLink?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
{
@ -40,10 +41,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate
// Controllers
ExternalGameControllerManager.shared.startMonitoring()
// Notifications
NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.databaseManagerDidStart(_:)), name: DatabaseManager.didStartNotification, object: DatabaseManager.shared)
// Deep Links
if let shortcut = launchOptions?[.shortcutItem] as? UIApplicationShortcutItem
{
self.deepLinkController.handle(.shortcut(shortcut))
self.appLaunchDeepLink = .shortcut(shortcut)
// false = we handled the deep link, so no need to call delegate method separately.
return false
@ -164,3 +168,15 @@ extension AppDelegate
}
}
private extension AppDelegate
{
@objc func databaseManagerDidStart(_ notification: Notification)
{
guard let deepLink = self.appLaunchDeepLink else { return }
DispatchQueue.main.async {
self.deepLinkController.handle(deepLink)
}
}
}

View File

@ -15,6 +15,11 @@ import Harmony
import Roxas
import ZIPFoundation
extension DatabaseManager
{
static let didStartNotification = Notification.Name("databaseManagerDidStartNotification")
}
extension DatabaseManager
{
enum ImportError: Error, Hashable
@ -97,6 +102,9 @@ extension DatabaseManager
self.prepareDatabase {
self.isStarted = true
NotificationCenter.default.post(name: DatabaseManager.didStartNotification, object: self)
completionHandler(nil)
}
}

View File

@ -105,7 +105,9 @@ extension LaunchViewController
UIView.transition(with: self.view, duration: 0.3, options: [.transitionCrossDissolve], animations: {
showGameViewController()
}, completion: nil)
}) { (finished) in
self.gameViewController.startEmulation()
}
}
else
{