In IOS10, I used UNMutableNotificationContent and set delegate,
private func pushNotification() {
let content = UNMutableNotificationContent()
content.title = "aaa"
content.body = "bbb"
content.subtitle = "00000"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let requestIdentifier = "com.aaaaa.bbbbb"
let request = UNNotificationRequest(identifier: requestIdentifier, content: content, trigger: trigger)
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().add(request) { error in
if error == nil {
print("Time Interval Notification scheduled: \\\\(requestIdentifier)")
}
}
}
send notification in foreground, the follows func was called
then i can show the notification in foregound by "completionHandler"
@available(iOS 10.0, *)
public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Swift.Void) {
completionHandler([.alert, .sound])
}
.
.
.
But in IOS8 & 9, i used UILocalNotification
private func pushNotification2() {
let notification = UILocalNotification()
notification.alertAction = "Title Message"
notification.alertBody = "Body Message"
notification.fireDate = NSDate(timeIntervalSinceNow: 0) as Date
notification.soundName = UILocalNotificationDefaultSoundName
notification.category = "INVITE_CATEGORY"
UIApplication.shared.scheduleLocalNotification(notification)
}
and found these in AppDelegate
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
}
func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, for notification: UILocalNotification, completionHandler: @escaping () -> Void) {
}
func application(_ application: UIApplication, handleActionWithIdentifier identifier: String?, for notification: UILocalNotification, withResponseInfo responseInfo: [AnyHashable : Any], completionHandler: @escaping () -> Void) {
}
It's just called first func only when i send notification in foreground, but first func has no "completionHandler" what should i do? thank your help