diff --git a/example/flutter_example/ios/Runner/AppDelegate.swift b/example/flutter_example/ios/Runner/AppDelegate.swift index f67d7af..f0b1572 100644 --- a/example/flutter_example/ios/Runner/AppDelegate.swift +++ b/example/flutter_example/ios/Runner/AppDelegate.swift @@ -13,10 +13,7 @@ import UserNotifications didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { - UIApplication.shared.registerForRemoteNotifications() - - // Calling the notification request method - registerForRemoteNotifications() + UNUserNotificationCenter.current().delegate = self // tracking sources of referrals to the application via push notifications Mindbox.shared.track(.launch(launchOptions)) @@ -72,27 +69,15 @@ import UserNotifications override func userNotificationCenter( _ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, - withCompletionHandler completionHandler: @escaping () -> Void) { - // Send click to Mindbox - Mindbox.shared.pushClicked(response: response) - - // Sending the fact that the application was opened when switching to push notification - Mindbox.shared.track(.push(response)) - completionHandler() - super.userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler) - } - - func registerForRemoteNotifications() { - UNUserNotificationCenter.current().delegate = self - DispatchQueue.main.async { - UNUserNotificationCenter.current().requestAuthorization(options: [ .alert, .sound, .badge]) { granted, error in - print("Permission granted: \(granted)") - if let error = error { - print("NotificationsRequestAuthorization failed with error: \(error.localizedDescription)") - } - Mindbox.shared.notificationsRequestAuthorization(granted: granted) - } - } + withCompletionHandler completionHandler: @escaping () -> Void + ) { + // Send click to Mindbox + Mindbox.shared.pushClicked(response: response) + + // Sending the fact that the application was opened when switching to push notification + Mindbox.shared.track(.push(response)) + completionHandler() + super.userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler) } func notifyFlutterNewData() { diff --git a/example/flutter_example/lib/view_model/view_model.dart b/example/flutter_example/lib/view_model/view_model.dart index f613f3e..980db72 100644 --- a/example/flutter_example/lib/view_model/view_model.dart +++ b/example/flutter_example/lib/view_model/view_model.dart @@ -66,8 +66,8 @@ class ViewModel { var status = await Permission.notification.status; if (!status.isGranted) { status = await Permission.notification.request(); - Mindbox.instance - .updateNotificationPermissionStatus(granted: status.isGranted); + print("Permission status: $status"); + Mindbox.instance.refreshNotificationPermissionStatus(); } }