Slide 33
Slide 33 text
App Delegate
import UIKit
import UserNotifications
import CoreSpotlight
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var tabBarController: UITabBarController?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.window = UIWindow(frame: UIScreen.main.bounds)
self.tabBarController = UITabBarController()
tabBarController.viewControllers = [FirstViewController(), SecondViewController(), ThirdViewController()]
window?.rootViewController = tabBarController
return true
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
switch userActivity.activityType {
case NSUserActivityTypeBrowsingWeb:
guard let url = userActivity.webpageURL else { fatalError("unreachable") }
let detailViewController = DetailViewController()
detailViewController.identifier = url.lastPathComponent
(tabBarController?.viewControllers?[0] as? UINavigationController)?.pushViewController(detailViewController, animated: true)
case CSSearchableItemActionType:
guard let identifier = userActivity.userInfo?[CSSearchableItemActivityIdentifier] as? String else { fatalError("unreachable")}
let detailViewController = DetailViewController()
detailViewController.identifier = identifier
(tabBarController?.viewControllers?[0] as? UINavigationController)?.pushViewController(detailViewController, animated: true)
case CSQueryContinuationActionType:
guard let query = userActivity.userInfo?[CSSearchQueryString] as? String else {
fatalError("unreachable")
}
let detailViewController = DetailViewController()
detailViewController.identifier = query
(tabBarController?.viewControllers?[0] as? UINavigationController)?.pushViewController(detailViewController, animated: true)
case "com.d-date.CoordinatorExample.intent": // Siri shortcut
let identifier = userActivity.userInfo?["signiture"] as? String
let detailViewController = DetailViewController()
detailViewController.identifier = identifier
(tabBarController?.viewControllers?[0] as? UINavigationController)?.pushViewController(detailViewController, animated: true)
default:
break
}
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if url.scheme == "coordinator-example-widget" {
let identifier = url.lastPathComponent
let detailViewController = DetailViewController()
detailViewController.identifier = identifier
(tabBarController?.viewControllers?[0] as? UINavigationController)?.pushViewController(detailViewController, animated: true)
} else if url.scheme == "adjustSchemeExample" {
let detailViewController = DetailViewController()
detailViewController.identifier = identifier
(tabBarController?.viewControllers?[0] as? UINavigationController)?.pushViewController(detailViewController, animated: true)
} else if url.scheme == "FirebaseDynamicLinksExmaple" {
let detailViewController = DetailViewController()
detailViewController.identifier = identifier
(tabBarController?.viewControllers?[0] as? UINavigationController)?.pushViewController(detailViewController, animated: true)
}
}
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
let text = shortcutItem.type.replacingOccurrences(of: bundleIdentifier + ".", with: "").lowercased()
switch text {
case "a":
let detailViewController = DetailViewController()
detailViewController.identifier = identifier
(tabBarController?.viewControllers?[0] as? UINavigationController)?.pushViewController(detailViewController, animated: true)
case "b":
let detailViewController = DetailViewController()
detailViewController.identifier = identifier
(tabBarController?.viewControllers?[0] as? UINavigationController)?.pushViewController(detailViewController, animated: true)
case "c":
let detailViewController = DetailViewController()
detailViewController.identifier = identifier
(tabBarController?.viewControllers?[0] as? UINavigationController)?.pushViewController(detailViewController, animated: true)
default:
break
}
}
}
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let detailViewController = DetailViewController()
detailViewController.identifier = identifier
(tabBarController?.viewControllers?[0] as? UINavigationController)?.pushViewController(detailViewController, animated: true)
completionHandler()
}
}
•
※ιʔείʔυΠϝʔδͰ͢