2017-04-01 8 views
1

私は辞書の配列を持っています。辞書には、異なるバーの名前/経度/緯度が含まれています。大衆地方自治体の速報3

アプリ内の各バーの位置情報通知を作成します。

私が使用している機能はありますが、なんらかの理由でリストの最初のバーの通知が作成されるだけです。残りの部分は機能しません。

何が悪いと思いますか?私はどんなcontent.badgeのためにあるか分からない。

// Register location based notifications for all bars 
func setupNotifications(){ 
    if(CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways || CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse){ 


     for i in 0...(allBars.count - 1){ 
      let lat = (allBars[i])["Latitude"] as? Double 
      let long = (allBars[i])["Longitude"] as? Double 
      let name = (allBars[i])["Name"] as! String 

      let region = CLCircularRegion(center: CLLocationCoordinate2D(latitude: lat!, longitude: long!), radius: 60, identifier: "\(name)") 

      region.notifyOnEntry = true 
      region.notifyOnExit = false 

      let trigger = UNLocationNotificationTrigger(region: region, repeats: true) 
      let content = UNMutableNotificationContent() 
      content.title = "Rate \(name) in the app!" 
      content.badge = 1 
      content.sound = UNNotificationSound.default() 

      let request = UNNotificationRequest(identifier: "LN\(name)", content: content, trigger: trigger) 
      UNUserNotificationCenter.current().add(request) {(error) in 
       if let error = error{ 
        print("Need notification permissions... \(error)") 
       } 
       else{ 
        //success 
       } 
      } 
     } 
    } 
} 

答えて

1
import UserNotifications 

class ViewController: UIViewController,UNUserNotificationCenterDelegate { 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    print("UNUserNotificationCenter") 

    UNUserNotificationCenter.current().requestAuthorization(options: [.sound,.alert,.badge], completionHandler: { didallow, error in 

    }) 
} 

@IBAction func btn(_ sender: UIButton) { 
    let content = UNMutableNotificationContent() 

    content.title = "the 5 sec are up" 
    content.subtitle = "they are up now" 
    content.body = "the 5 sec are realy up now" 
    content.badge = 1 

    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5.0, repeats: false) 

    let request = UNNotificationRequest(identifier: "time done", content: content, trigger: trigger) 

    UNUserNotificationCenter.current().add(request, withCompletionHandler: nil) 
} 

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { 
    print("Handle push for foreground") 

    print("\(notification.request.content.userInfo)") 
} 


func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) { 
    print("Handle push for background or close") 

    print("\(response.notification.request.content.userInfo)") 

    completionHandler() 
} 
関連する問題