b65bd3c3c0
This reverts commit 647c60f489.
69 lines
3.2 KiB
Swift
69 lines
3.2 KiB
Swift
//
|
||
// AppDelegate.swift
|
||
// ProjectClock
|
||
//
|
||
// Created by Hykilpikonna on 1/6/21.
|
||
//
|
||
|
||
import UIKit
|
||
import UserNotifications
|
||
|
||
@main
|
||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||
|
||
|
||
|
||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||
UNUserNotificationCenter.current().delegate = self
|
||
// Override point for customization after application launch.
|
||
return true
|
||
}
|
||
|
||
// MARK: UISceneSession Lifecycle
|
||
|
||
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
|
||
// Called when a new scene session is being created.
|
||
// Use this method to select a configuration to create the new scene with.
|
||
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
|
||
}
|
||
|
||
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
|
||
// Called when the user discards a scene session.
|
||
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
|
||
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
|
||
}
|
||
}
|
||
|
||
extension AppDelegate: UNUserNotificationCenterDelegate {
|
||
|
||
// This function will be called right after user tap on the notification
|
||
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
|
||
|
||
// retrieve the root view controller (which is a tab bar controller)
|
||
guard let rootViewController = (UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.window?.rootViewController else {
|
||
return
|
||
}
|
||
|
||
let storyboard = UIStoryboard(name: "Main", bundle: nil)
|
||
|
||
// instantiate the view controller we want to show from storyboard
|
||
// root view controller is tab bar controller
|
||
// the selected tab is a navigation controller
|
||
// then we push the new view controller to it
|
||
if let alarmVC = storyboard.instantiateViewController(withIdentifier: "LiveAlarmViewController") as? LiveAlarmViewController,
|
||
let tabBarController = rootViewController as? UITabBarController,
|
||
let navController = tabBarController.selectedViewController as? UINavigationController {
|
||
|
||
// we can modify variable of the new view controller using notification data
|
||
// (eg: title of notification)
|
||
//alarmVC.senderDisplayName = response.notification.request.content.title
|
||
// you can access custom data of the push notification by using userInfo property
|
||
// response.notification.request.content.userInfo
|
||
navController.pushViewController(alarmVC, animated: true)
|
||
}
|
||
|
||
// tell the app that we have finished processing the user’s action / response
|
||
completionHandler()
|
||
}
|
||
}
|