|
1 | 1 | import UIKit
|
2 | 2 | import Flutter
|
3 | 3 | import UserNotifications
|
4 |
| - |
5 | 4 | @UIApplicationMain
|
6 | 5 | @objc class AppDelegate: FlutterAppDelegate {
|
7 |
| - override func application( |
8 |
| - _ application: UIApplication, |
9 |
| - didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? |
10 |
| - ) -> Bool { |
11 |
| - GeneratedPluginRegistrant.register(with: self) |
| 6 | + override func application( |
| 7 | + _ application: UIApplication, |
| 8 | + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? |
| 9 | + ) -> Bool { |
| 10 | + GeneratedPluginRegistrant.register(with: self) |
| 11 | + if #available(iOS 10.0, *) { |
12 | 12 | UNUserNotificationCenter.current().delegate = self
|
| 13 | + } else { |
| 14 | + // Fallback on earlier versions |
| 15 | + } |
| 16 | + if #available(iOS 10.0, *) { |
13 | 17 | UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]){ (granted, error) in
|
14 | 18 | print("grant: \(granted)")
|
15 | 19 | }
|
16 |
| - UIApplication.shared.registerForRemoteNotifications() |
17 |
| - return super.application(application, didFinishLaunchingWithOptions: launchOptions) |
| 20 | + } else { |
| 21 | + // Fallback on earlier versions |
18 | 22 | }
|
19 |
| -} |
20 |
| - |
21 |
| -func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { |
22 |
| - let freshchatSdkPlugin = FreshchatSdkPlugin() |
23 |
| - print("Device Token \(deviceToken)") |
24 |
| - print("Device token is set") |
25 |
| - freshchatSdkPlugin.setPushRegistrationToken(deviceToken) |
26 |
| -} |
27 |
| - |
28 |
| -func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { |
29 |
| - let freshchatSdkPlugin = FreshchatSdkPlugin() |
30 |
| - if freshchatSdkPlugin.isFreshchatNotification(userInfo){ |
31 |
| - NSLog("is Freshchat Notification") |
32 |
| - freshchatSdkPlugin.handlePushNotification(userInfo) |
33 |
| - }else{ |
34 |
| - NSLog("Not Freshchat Notification") |
| 23 | + UIApplication.shared.registerForRemoteNotifications() |
| 24 | + return super.application(application, didFinishLaunchingWithOptions: launchOptions) |
| 25 | + } |
| 26 | + override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { |
| 27 | + let freshchatSdkPlugin = FreshchatSdkPlugin() |
| 28 | + print("Device Token \(deviceToken)") |
| 29 | + print("Device token is set") |
| 30 | + freshchatSdkPlugin.setPushRegistrationToken(deviceToken) |
| 31 | + } |
| 32 | + //@available(iOS 10.0, *) |
| 33 | + override func userNotificationCenter(_ center: UNUserNotificationCenter, |
| 34 | + willPresent: UNNotification, |
| 35 | + withCompletionHandler: @escaping (UNNotificationPresentationOptions)->()) { |
| 36 | + let freshchatSdkPlugin = FreshchatSdkPlugin() |
| 37 | + if freshchatSdkPlugin.isFreshchatNotification(willPresent.request.content.userInfo) { |
| 38 | + freshchatSdkPlugin.handlePushNotification(willPresent.request.content.userInfo) //Handled for freshchat notifications |
| 39 | + } else { |
| 40 | + withCompletionHandler([.alert, .sound, .badge]) //For other notifications |
| 41 | + } |
| 42 | + } |
| 43 | + //@available(iOS 10.0, *) |
| 44 | + override func userNotificationCenter(_ center: UNUserNotificationCenter, |
| 45 | + didReceive: UNNotificationResponse, |
| 46 | + withCompletionHandler: @escaping ()->()) { |
| 47 | + let freshchatSdkPlugin = FreshchatSdkPlugin() |
| 48 | + if freshchatSdkPlugin.isFreshchatNotification(didReceive.notification.request.content.userInfo) { |
| 49 | + freshchatSdkPlugin.handlePushNotification(didReceive.notification.request.content.userInfo) //Handled for freshchat notifications |
| 50 | + withCompletionHandler() |
| 51 | + } else { |
| 52 | + withCompletionHandler() //For other notifications |
| 53 | + } |
35 | 54 | }
|
36 |
| - completionHandler(.newData) |
37 |
| -} |
38 |
| - |
39 |
| -func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { |
40 |
| - print("Failed to register for notifications: \(error.localizedDescription)") |
41 | 55 | }
|
42 |
| - |
|
0 commit comments