Ios 地理围栏UILocalNotification无法正常工作swift

Ios 地理围栏UILocalNotification无法正常工作swift,ios,swift,notifications,uilocalnotification,Ios,Swift,Notifications,Uilocalnotification,我在swift中遇到了一个奇怪的本地通知问题。 我是这样提交本地通知的 let notification = UILocalNotification() var body = "Hi Krishna"; if(region.identifier == "entry1") { body += " Welcome"; } else { body += " Bye! Bye!";

我在swift中遇到了一个奇怪的本地通知问题。 我是这样提交本地通知的

        let notification = UILocalNotification()
        var body = "Hi Krishna";
        if(region.identifier == "entry1") {
            body += " Welcome";
        } else {
            body += " Bye! Bye!";
        }
        notification.alertBody = body
        notification.soundName = "Default";

        notification.userInfo = ["id": "id"];

        notification.fireDate = NSDate(timeIntervalSinceNow: 1)
        UIApplication.sharedApplication().scheduleLocalNotification(notification)
以及我如何在appdelegate中处理启动选项

    if(launchOptions != nil) {
        window?.rootViewController?.view.backgroundColor = UIColor.cyanColor();
        if let notification = launchOptions![UIApplicationLaunchOptionsLocalNotificationKey] as? UILocalNotification {
            window?.rootViewController?.view.backgroundColor = UIColor.blackColor();
            if let userInfo = notification.userInfo {
                window?.rootViewController?.view.backgroundColor = UIColor.blueColor();
                if let id = userInfo["id"] as? String {
                    window?.rootViewController?.view.backgroundColor = UIColor.redColor();
                }
            }
        }
    }
出于调试目的,我正在更改视图的背景色。 当我点击通知,我得到青色,这意味着下面的线是失败的

launchOptions![UIApplicationLaunchOptionsLocalNotificationKey] as? UILocalNotification
因为我在这条线的正上方设置了青色。 所以我不明白为什么这不是UILocalNotification的强制转换? 有人能帮我摆脱这个问题吗?+

还有一件事,如果我在正常工作的话,它会正常工作,但我在使用地理围栏,并且我正在安排来自

locationManager(manager: CLLocationManager, didExitRegion region: CLRegion)

在这种情况下,它不起作用。

您可以在AppDelegate中实现
应用程序(\uuIdReceiveLocalNotification:)
(它直接向您提供通知)并在那里处理通知


更多::

你能试着像这样投吗:

if let notification:UILocalNotification = launchOptions?[UIApplicationLaunchOptionsLocalNotificationKey] as? UILocalNotification {
        //do stuff with notification
}

只有在应用处于活动状态时才会调用didReceiveLocalNotification