ローカルのプッシュ通知を送信しようとしています。現在はUNLocationNotificationTrigger
と呼ばれていますが、プッシュ通知がトリガーされていません。通知が表示されないのはなぜですか?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
// Enable or disable features based on authorization.
}
return true
}
ビューコントローラ
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
localLocations()
}
func localLocations() {
//My current location is equal to the below coordinates, so I am in the radius
let center = CLLocationCoordinate2D(latitude: xx.xxxxx, longitude: -xx.xxxx)
let region = CLCircularRegion(center: center, radius: 20000, identifier: "Store")
region.notifyOnEntry = true
region.notifyOnExit = false
let trigger = UNLocationNotificationTrigger(region: region, repeats: false)
let content = UNMutableNotificationContent()
content.body = "Grocery Store"
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
_authorizing_ローカル通知のコードを示してください。 – matt
コード – joethemow