55// Created by Meena Alfons on 13/12/2023.
66//
77
8- import os
8+ import BirdKit
99import Foundation
1010import UIKit
11-
12- import BirdKit
11+ import os
1312
1413class AppDelegate : NSObject , UIApplicationDelegate {
15-
14+
1615 static var bird : Bird !
1716 static let logger = Logger ( subsystem: Bundle . main. bundleIdentifier!, category: " AppDelegate " )
18-
19- func application( _ application: UIApplication , didFinishLaunchingWithOptions launchOptions: [ UIApplication . LaunchOptionsKey : Any ] ? = nil ) -> Bool {
17+
18+ func application(
19+ _ application: UIApplication ,
20+ didFinishLaunchingWithOptions launchOptions: [ UIApplication . LaunchOptionsKey : Any ] ? = nil
21+ ) -> Bool {
2022 do {
2123 Self . bird = try Bird ( )
2224 } catch {
2325 Self . logger. info ( " failed to create bird \( error) " )
2426 }
25-
27+
2628 UNUserNotificationCenter . current ( ) . delegate = self
2729 return true
2830 }
29-
31+
3032 // This method will be called from Button "Ask for notifications permission"
3133 static func requestNotificationsPermission( ) {
32- UNUserNotificationCenter . current ( ) . requestAuthorization ( options: [ . badge, . alert, . sound] ) { granted, error in
34+ UNUserNotificationCenter . current ( ) . requestAuthorization ( options: [ . badge, . alert, . sound] ) {
35+ granted, error in
3336 guard granted else {
3437 self . logger. log ( " Notification permission is not gratned " )
3538 return
@@ -40,35 +43,38 @@ class AppDelegate: NSObject, UIApplicationDelegate {
4043 }
4144
4245 }
43-
46+
4447 func application(
4548 _ application: UIApplication ,
4649 didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
4750 ) {
4851 Self . bird. notifications. registerDevice ( deviceToken: deviceToken)
49-
52+
5053 Self . logger. log ( " APNS token: \( deviceToken. map { String ( format: " %02x " , $0) } . joined ( ) ) " )
5154 }
52-
53- func application( _ application: UIApplication , didFailToRegisterForRemoteNotificationsWithError error: Error ) {
55+
56+ func application(
57+ _ application: UIApplication , didFailToRegisterForRemoteNotificationsWithError error: Error
58+ ) {
5459 Self . logger. log ( #function)
5560 }
56-
57-
61+
5862 func application(
5963 _ application: UIApplication ,
6064 didReceiveRemoteNotification userInfo: [ AnyHashable : Any ] ,
6165 fetchCompletionHandler completionHandler: @escaping ( UIBackgroundFetchResult ) -> Void
6266 ) {
63- Self . bird. notifications. handleBackgroundNotification ( userInfo: userInfo, completionHandler: completionHandler)
67+ Self . bird. notifications. handleBackgroundNotification (
68+ userInfo: userInfo, completionHandler: completionHandler)
6469 }
6570}
6671
6772extension AppDelegate : UNUserNotificationCenterDelegate {
6873 func userNotificationCenter(
6974 _ center: UNUserNotificationCenter ,
7075 willPresent notification: UNNotification ,
71- withCompletionHandler completionHandler: @escaping ( UNNotificationPresentationOptions ) -> Void
76+ withCompletionHandler completionHandler: @escaping ( UNNotificationPresentationOptions ) ->
77+ Void
7278 ) {
7379 Self . logger. log ( #function)
7480 let options = Self . bird. notifications. willPresentNotification ( notification)
0 commit comments