Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save susanna2222/1f1430a69eb46402789666713b9007d7 to your computer and use it in GitHub Desktop.
Save susanna2222/1f1430a69eb46402789666713b9007d7 to your computer and use it in GitHub Desktop.
func setupLocalNotificationByRegion(){
if !isAllowReceiveNotification() {
return
}
// setup notification content
let content = UNMutableNotificationContent()
content.title = "Tokyo Tower"
content.body = "Welcome to Tokyo Tower, A symbol of Japan's post-war rebirth as a major economic power!"
content.badge = 0
content.sound = UNNotificationSound.default
// setup trigger by region
let center = CLLocationCoordinate2D(latitude: 35.658626, longitude: 139.745471)
let region = CLCircularRegion(center: center, radius: 30, identifier: "SampleRegion")
region.notifyOnEntry = true
region.notifyOnExit = false
// setup notification trigger
let trigger = UNLocationNotificationTrigger(region: region, repeats: true)
// setup notification request
let request = UNNotificationRequest(identifier: "SampleRequest", content: content, trigger: trigger)
// add request to notification center
notificationCenter.add(request, withCompletionHandler: {error in
if(error != nil){
print("RequestLocationNotification ERROR: " + error!.localizedDescription)
}else{
print("RequestLocationNotification: " + request.identifier)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment