Skip to content

Instantly share code, notes, and snippets.

@asilturk
Created October 5, 2020 07:17
Show Gist options
  • Save asilturk/99e34e63f1df6edc6a4f368cac284936 to your computer and use it in GitHub Desktop.
Save asilturk/99e34e63f1df6edc6a4f368cac284936 to your computer and use it in GitHub Desktop.
notificationTapped
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// Uygulama calisiyorken (on/arka planda) kullanici bildirime tikladiginda burdan yonlendirilir
NotificationCenter.default.post(name: Notification.Name("NotificationTapped"), object: nil, userInfo: userInfo)
// user tapped the notification bar when the app is in foreground
if(UIApplication.shared.applicationState == .active) { }
// user tapped the notification bar when the app is in background
if(UIApplication.shared.applicationState == .inactive) { }
completionHandler()
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// ...
// Uygulama calismiyorken (terminated), bildirime tiklandiginda yonlendirmeyi saglar.
if let remoteNotification = launchOptions?[UIApplication.LaunchOptionsKey.remoteNotification] as? [String : Any] {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
NotificationCenter.default.post(name: Notification.Name("NotificationTapped"), object: nil, userInfo: remoteNotification)
}
}
return true
}
// uygulama acik iken notificaiton gosterilmesi
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment