Skip to content

Instantly share code, notes, and snippets.

@nth-chile
Forked from prafullakumar/handlepushSwiftui.swift
Last active February 11, 2023 06:35
Show Gist options
  • Save nth-chile/9b9536fc27ffa2e53d0a1e4ba1158aaf to your computer and use it in GitHub Desktop.
Save nth-chile/9b9536fc27ffa2e53d0a1e4ba1158aaf to your computer and use it in GitHub Desktop.
import SwiftUI
@main
struct ios14DemoApp: App {
@StateObject var notificationCenter = NotificationCenter()
var body: some Scene {
WindowGroup {
LocalNotificationDemoView(notificationCenter: notificationCenter)
}
}
}
class NotificationCenter: NSObject, ObservableObject {
override init() {
super.init()
UNUserNotificationCenter.current().delegate = self
}
// didReceive hook
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// ...
}
}
struct LocalNotificationDemoView: View {
@ObservedObject var notificationCenter: NotificationCenter
var body: some View {
Button("schedule Notification") {
// UNUserNotificationCenter.current().add(...)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment