Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 10 additions & 25 deletions example/flutter_example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions example/flutter_example/lib/view_model/view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Comment thread
enotniy marked this conversation as resolved.
Mindbox.instance.refreshNotificationPermissionStatus();
}
}

Expand Down