iOS/코드조각

[iOS, Swift] LocalNotification Foreground 알림 받기

검은참깨두유vm 2022. 8. 21. 09:26
반응형

iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다.

 

import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        // Delegate 등록, 없으면 실행 X
        UNUserNotificationCenter.current().delegate = self
        
        return true
    }
    
    ...
}

extension AppDelegate: UNUserNotificationCenterDelegate {
    
    // foreground에서 알림 받기
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.list,.banner,.sound,.badge])
    }
}

 

 

 

반응형