Skip to content

Commit

Permalink
Pull request #367: Okoroleva MM-6937 ANB list
Browse files Browse the repository at this point in the history
Merge in MML/infobip-mobile-messaging-ios from okoroleva-MM-6937-ANB_list to master

Squashed commit of the following:

commit bd56f05896d9ebeec6d5a09ab5eda687bf1cda21
Author: Olga Koroleva <[email protected]>
Date:   Thu Nov 21 09:56:55 2024 +0100

    added banner and list to save previous behaviour

commit a4f4ef66c9cc20d6284a043721ffa8c1b320fd93
Author: Luka Ilić <[email protected]>
Date:   Wed Nov 20 16:08:55 2024 +0100

    willPresentInForegroundHandler presentationOptions instead of MMUserNotificationType

commit 0a361ae4dc12fe4e5ee3fa7c1653df2cc2511b78
Author: Olga Koroleva <[email protected]>
Date:   Wed Nov 20 15:47:19 2024 +0100

    in the UNCenterDelegate willPresent changed the NotificationOptions to the PresentationOptions to support new type .list
  • Loading branch information
Luka Ilić authored and riskpp committed Nov 21, 2024
1 parent f6f83b7 commit 2d04fcb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Classes/MobileMessaging/Core/MessageHandlingDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import UserNotifications

/// Called when a notification is delivered to a foreground app.
/// If your app is in the foreground when a notification arrives, the MobileMessaging SDK calls this method to deliver the notification directly to your app. If you implement this method, you can take whatever actions are necessary to process the notification and update your app. When you finish, execute the completionHandler block and specify how you want the system to alert the user, if at all.
@objc optional func willPresentInForeground(message: MM_MTMessage?, notification: UNNotification, withCompletionHandler completionHandler: @escaping (MMUserNotificationType) -> Void)
@objc optional func willPresentInForeground(message: MM_MTMessage?, notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)

/// Called when a local notification scheduled for a message. Apart from push messages that are pushed to the device by APNs and displayed by iOS automatically, MobileMessaging SDK delivers messages by pulling them from the server and generating them locally. These messages are displayed via Local Notifications.
@objc optional func willScheduleLocalNotification(for message: MM_MTMessage)
Expand Down
30 changes: 17 additions & 13 deletions Classes/MobileMessaging/Core/UserNotificationCenterDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ extension MM_MTMessage {

public extension UNNotificationPresentationOptions {
static func make(with userNotificationType: MMUserNotificationType) -> UNNotificationPresentationOptions {
var ret: UNNotificationPresentationOptions = []
if userNotificationType.contains(options: .alert) {
ret.insert(.alert)
}
if userNotificationType.contains(options: .badge) {
ret.insert(.badge)
}
if userNotificationType.contains(options: .sound) {
ret.insert(.sound)
}
return ret
}
var ret: UNNotificationPresentationOptions = []
if userNotificationType.contains(options: .alert) {
if #available(iOS 14.0, *) {
ret.insert([.banner, .list])
} else {
ret.insert(.alert)
}
}
if userNotificationType.contains(options: .badge) {
ret.insert(.badge)
}
if userNotificationType.contains(options: .sound) {
ret.insert(.sound)
}
return ret
}
}

class UserNotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate, NamedLogger {
Expand All @@ -44,7 +48,7 @@ class UserNotificationCenterDelegate: NSObject, UNUserNotificationCenterDelegate

MobileMessaging.messageHandlingDelegate?.willPresentInForeground?(message: mtMessage, notification: notification, withCompletionHandler: { notificationType in
DispatchQueue.main.async {
completionHandler(UNNotificationPresentationOptions.make(with: notificationType))
completionHandler(notificationType)
}
})
??
Expand Down
6 changes: 3 additions & 3 deletions Example/Tests/MobileMessagingTests/Base/MMTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ApnsRegistrationManagerStub: ApnsRegistrationManager {

class MessageHandlingDelegateMock : MMMessageHandlingDelegate {
var didReceiveNewMessageHandler: ((MM_MTMessage) -> Void)?
var willPresentInForegroundHandler: ((MM_MTMessage?) -> MMUserNotificationType)?
var willPresentInForegroundHandler: ((MM_MTMessage?) -> UNNotificationPresentationOptions)?
var canPresentInForeground: ((MM_MTMessage) -> Void)?
var didPerformActionHandler: ((MMNotificationAction, MM_MTMessage?, () -> Void) -> Void)?
var didReceiveNewMessageInForegroundHandler: ((MM_MTMessage) -> Void)?
Expand All @@ -62,8 +62,8 @@ class MessageHandlingDelegateMock : MMMessageHandlingDelegate {
didReceiveNewMessageHandler?(message)
}

func willPresentInForeground(message: MM_MTMessage?, withCompletionHandler completionHandler: @escaping (MMUserNotificationType) -> Void) {
completionHandler(willPresentInForegroundHandler?(message) ?? MMUserNotificationType.none)
func willPresentInForeground(message: MM_MTMessage?, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler(willPresentInForegroundHandler?(message) ?? UNNotificationPresentationOptions.alert)
}

func canPresentInForeground(message: MM_MTMessage) {
Expand Down

0 comments on commit 2d04fcb

Please sign in to comment.