![](/img/trans.png)
[英]How to load viewController when user tap on notification in iOS Swift?
[英]Why status bar disappear when I tap push notification and move ViewController in swift
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
/* */
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = UIViewController()
self.window?.windowLevel = UIWindowLevelAlert + 1
self.window?.makeKeyAndVisible()
/*
fetch and add push notification data
*/
goAnotherVC()
}
func goAnotherVC() {
if (application.applicationState == UIApplicationState.active) {
/* active stage is working */
} else if (application.applicationState == UIApplicationState.inactive || application.applicationState == UIApplicationState.background) {
if (type == "1" || type == "2") {
let storyboard: UIStoryboard = UIStoryboard(name: "MyAppointments", bundle: nil)
let apptVC = storyboard.instantiateViewController(withIdentifier: "NotificationDetailViewController") as! NotificationDetailViewController
let navigationController = UINavigationController.init(rootViewController: apptVC)
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()
} else if (type == "3") {
let storyboard: UIStoryboard = UIStoryboard(name: "MyAppointments", bundle: nil)
let apptVC = storyboard.instantiateViewController(withIdentifier: "NotificationDetailViewController") as! NotificationDetailViewController
let navigationController = UINavigationController.init(rootViewController: apptVC)
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()
} else if (type == "4") {
let storyboard: UIStoryboard = UIStoryboard(name: "Enquiry", bundle: nil)
let enqVC = storyboard.instantiateViewController(withIdentifier: "EnquiryDetailViewController") as! EnquiryDetailViewController
let navigationController = UINavigationController.init(rootViewController: enqVC)
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()
}
}
}
上面的代碼是獲取推送通知數據,並在用戶點擊時發送到相關的View Controller。 但是我發現打開View Controller時缺少狀態欄。 謝謝,請讓我知道如何解決它。
乍看之下(並且沒有實際驗證代碼),我懷疑罪魁禍首是:
self.window = UIWindow(frame: UIScreen.main.bounds)
您正在設置窗口以覆蓋視圖的整個邊界。 要查看是否是問題所在,只需將該行更改為以下內容:
var rect = UIScreen.main.bounds
rect.origin.y += 20
self.window = UIWindow(frame: rect)
並查看問題是否消失。 在我的代碼中,我只是更改了窗口的頂部位置以允許使用狀態欄。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.