2015-11-26 46 views
0

我在快速地面對本地通知的一個奇怪問題。 我提出本地通知這樣Geofencing UILocalNotification無法正常工作迅速

 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) 

調度通知在這種情況下,它不工作。

回答

0

能不能請你投這樣的:

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

還是同樣的問題 –