Skip to content

Instantly share code, notes, and snippets.

@ysam12345
Created January 9, 2019 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysam12345/ebfc550cdbf6e18d9b0e57044877231b to your computer and use it in GitHub Desktop.
Save ysam12345/ebfc550cdbf6e18d9b0e57044877231b to your computer and use it in GitHub Desktop.
//switch on
var counter = 0
for var i in notificationListData!.data {
let center = CLLocationCoordinate2D(latitude: i.data.lat, longitude: i.data.lon)
let region = CLCircularRegion(center: center, radius: CLLocationDistance(i.data.radius), identifier: String(counter))
region.notifyOnEntry = true
region.notifyOnExit = false
let trigger = UNLocationNotificationTrigger(region: region, repeats: false)
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey: "地理推播", arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey: i.data.content, arguments: nil)
content.sound = UNNotificationSound.default()
let request = UNNotificationRequest(identifier: String(counter), content: content, trigger: trigger)
// Schedule the notification.
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.add(request)
counter += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment