Created
January 9, 2019 04:16
-
-
Save ysam12345/ebfc550cdbf6e18d9b0e57044877231b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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