Created
August 21, 2019 05:56
-
-
Save susanna2222/1f1430a69eb46402789666713b9007d7 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
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