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
}
}
}
}
}