Ios LGSideMenuController:注册几个本地推送通知会导致屏幕处理延迟

Ios LGSideMenuController:注册几个本地推送通知会导致屏幕处理延迟,ios,swift,push-notification,Ios,Swift,Push Notification,当我注册几个本地推送通知时,我注意到一个奇怪的问题: for model in myModelArray { let calendar = Calendar.current let scheduleDate = calendar.date(byAdding: .second, value: i * 5, to: Date())! let notification = UILocalNotification() notification.fireDate = sc

当我注册几个本地推送通知时,我注意到一个奇怪的问题:

for model in myModelArray
{
    let calendar = Calendar.current
    let scheduleDate = calendar.date(byAdding: .second, value: i * 5, to: Date())!

    let notification = UILocalNotification()
    notification.fireDate = scheduleDate
    notification.alertBody = "My push notification title"

    UIApplication.shared.scheduleLocalNotification(notification)
    i += 1
}
当我的本地推送通知在后台模式下出现时,我点击它并希望直接显示一个屏幕:

func application(_ application: UIApplication, didReceive notification: UILocalNotification)
{
    let mainMenuVC = self.window?.rootViewController as! MenuViewController
    let navController = mainMenuVC.sideMenuController?.rootViewController as! UINavigationController

    let myDestinationVC = navController.storyboard?.instantiateViewController(withIdentifier: "MyIdentifier") as! MyDestinationViewController
    navController.pushViewController(mydestinationVC, animated: false)
}

但要在我的menuVC和我的destinationVC之间实现过渡需要一分钟。当我的应用程序打开时,按下视图控制器可以完美地工作。我忘了什么吗?我的代码有什么问题?只有当应用程序关闭并在点击推送通知后再次打开时,才会发生延迟

UILocalNotification自iOS10以来已被弃用。您可能会收到推送通知,但永远不会调用func应用程序(application:UIApplication,didReceive通知:UILocalNotification)。您遇到的“延迟”只是第二个本地推送通知,当您的应用程序处于活动状态时,其处理将起作用

改用UnuseNotificationCenter,但保留iOS9设备的“旧处理”

按如下方式设置通知:

        let center = UNUserNotificationCenter.current()
        let content = UNMutableNotificationContent()
        content.title = „MyTitle“
        content.body = „MyBody“
        content.categoryIdentifier = UNNotificationDefaultActionIdentifier

        let units: Set<Calendar.Component> = [.second, .hour, .minute, .day, .month, .year]
        let dateComponents = Calendar.current.dateComponents(units, from: date)

        let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)

        let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
        center.add(request)

谢谢!为什么没有编译器警告指示此弃用?这是一个多么严重的错误。委托方法未触发的唯一情况是应用程序终止时。我将调整iOS10的通知处理。
import UserNotifications

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate
{
 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
 {
    // Local Push notifications
    if #available(iOS 10.0, *)
    {
        let center = UNUserNotificationCenter.current()
        center.delegate = self
        center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in

        }
    }
    else
    {
        application.registerUserNotificationSettings(UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil))
    }

    return true
 }

 @available(iOS 10.0, *)
 func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void)
 {
    // handle your response here
    completionHandler()
 }
}