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)
您正在设置窗口以覆盖 View 的整个边界。要查看这是否是问题所在,只需将该行更改为以下内容:
var rect = UIScreen.main.bounds
rect.origin.y += 20
self.window = UIWindow(frame: rect)
然后看看问题是否消失了。在我的代码中,我只是更改了窗口的顶部位置以允许状态栏。
关于ios - 为什么当我点击推送通知并快速移动 ViewController 时状态栏消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42941877/