diff --git a/Example/Tests/MobileMessagingTests/InteractiveNotificationsTests.swift b/Example/Tests/MobileMessagingTests/InteractiveNotificationsTests.swift index f07c1634..89d6cded 100644 --- a/Example/Tests/MobileMessagingTests/InteractiveNotificationsTests.swift +++ b/Example/Tests/MobileMessagingTests/InteractiveNotificationsTests.swift @@ -16,18 +16,18 @@ class InteractiveNotificationsTests: MMTestCase { func testActionHandlerCalled() { weak var actionHandlerCalled = expectation(description: "action handler called") weak var testCompleted = expectation(description: "testCompleted") - let action = MMCategoryAction(identifier: actionId, title: "Action", options: nil) { (message, completion) in + let action = MMNotificationAction(identifier: actionId, title: "Action", options: nil) { (message, completion) in actionHandlerCalled?.fulfill() completion() } - let category = MMInteractiveCategory(identifier: categoryId, actions: [action!]) - var set = Set() + let category = MMNotificationCategory(identifier: categoryId, actions: [action!]) + var set = Set() set.insert(category!) cleanUpAndStop() var mm = mockedMMInstanceWithApplicationCode(MMTestConstants.kTestCorrectApplicationCode) - mm = mm?.withInteractiveCategories(set) + mm = mm?.withInteractiveNotificationCategories(set) mm?.start() MobileMessaging.handleActionWithIdentifier(identifier: actionId, forRemoteNotification: ["messageId": "1", "aps": ["alert": ["body": "text"], "category": categoryId]], responseInfo: nil) { diff --git a/Pod/Classes/Core/MobileMessaging.swift b/Pod/Classes/Core/MobileMessaging.swift index 08861815..c82338c2 100644 --- a/Pod/Classes/Core/MobileMessaging.swift +++ b/Pod/Classes/Core/MobileMessaging.swift @@ -68,8 +68,8 @@ public final class MobileMessaging: NSObject { ///- parameter categories: Set of categories that indicating which buttons will be displayed and behavour of these buttons when a push notification arrives. ///- remark: Mobile Messaging SDK reserves category Ids and action Ids with "mm_" prefix. Custom actions and categories with this prefix will be discarded. - public func withInteractiveCategories(_ categories: Set) -> MobileMessaging { - self.interactiveCategories = categories + public func withInteractiveNotificationCategories(_ categories: Set) -> MobileMessaging { + self.interactiveNotificationCategories = categories return self } @@ -97,7 +97,7 @@ public final class MobileMessaging: NSObject { self.application.unregisterForRemoteNotifications() } - application.registerUserNotificationSettings(UIUserNotificationSettings(types: userNotificationType, categories: self.interactiveCategories?.uiUserNotificationCategoriesSet)) + application.registerUserNotificationSettings(UIUserNotificationSettings(types: userNotificationType, categories: self.interactiveNotificationCategories?.uiUserNotificationCategoriesSet)) if application.isRegisteredForRemoteNotifications == false { MMLogDebug("Registering for remote notifications...") @@ -170,7 +170,7 @@ public final class MobileMessaging: NSObject { MobileMessaging.sharedInstance?.reachabilityManager = nil MobileMessaging.sharedInstance?.keychain = nil MobileMessaging.sharedInstance?.sharedNotificationExtensionStorage = nil - MobileMessaging.sharedInstance?.interactiveCategories = nil + MobileMessaging.sharedInstance?.interactiveNotificationCategories = nil MobileMessaging.sharedInstance = nil } @@ -460,13 +460,13 @@ public final class MobileMessaging: NSObject { static var date: MMDate = MMDate() // testability var sharedNotificationExtensionStorage: AppGroupMessageStorage? - var interactiveCategories: Set? + var interactiveNotificationCategories: Set? private class func handleActionWithIdentifier(identifier: String?, message: MTMessage?, completionHandler: @escaping () -> Void) { guard let identifier = identifier, let message = message, let categoryId = message.aps.categoryId, - let registeredCategories = MobileMessaging.sharedInstance?.interactiveCategories, + let registeredCategories = MobileMessaging.sharedInstance?.interactiveNotificationCategories, let category = registeredCategories.first(where: {return $0.identifier == categoryId}), let action = category.actions.first(where: {return $0.identifier == identifier}) else { completionHandler() diff --git a/Pod/Classes/Core/MobileMessagingAppDelegate.swift b/Pod/Classes/Core/MobileMessagingAppDelegate.swift index 6dd9b763..c247d480 100644 --- a/Pod/Classes/Core/MobileMessagingAppDelegate.swift +++ b/Pod/Classes/Core/MobileMessagingAppDelegate.swift @@ -45,7 +45,7 @@ open class MobileMessagingAppDelegate: UIResponder, UIApplicationDelegate { ///You can override this variable in your application delegate, that you inherit from `MobileMessagingAppDelegate`. ///Once application started, provided categories will be registered. ///- remark: Mobile Messaging SDK reserves category Ids and action Ids with "mm_" prefix. Custom actions and categories with this prefix will be discarded. - open var interactiveCategories: Set? { + open var interactiveNotificationCategories: Set? { return nil } @@ -60,8 +60,8 @@ open class MobileMessagingAppDelegate: UIResponder, UIApplicationDelegate { } } - if let interactiveCategories = interactiveCategories { - session = session?.withInteractiveCategories(interactiveCategories) + if let categories = interactiveNotificationCategories { + session = session?.withInteractiveNotificationCategories(categories) } session?.start() diff --git a/Pod/Classes/InteractiveNotifications/MMInteractiveCategory.swift b/Pod/Classes/InteractiveNotifications/MMInteractiveCategory.swift index 179d0735..c5321248 100644 --- a/Pod/Classes/InteractiveNotifications/MMInteractiveCategory.swift +++ b/Pod/Classes/InteractiveNotifications/MMInteractiveCategory.swift @@ -5,10 +5,10 @@ // // -public final class MMInteractiveCategory: NSObject { +public final class MMNotificationCategory: NSObject { let identifier: String - let actions: [MMCategoryAction] - public init?(identifier: String, actions: [MMCategoryAction]) { + let actions: [MMNotificationAction] + public init?(identifier: String, actions: [MMNotificationAction]) { guard !identifier.hasPrefix("mm_") else { return nil } @@ -29,27 +29,27 @@ public final class MMInteractiveCategory: NSObject { } public override func isEqual(_ object: Any?) -> Bool { - guard let obj = object as? MMInteractiveCategory else { + guard let obj = object as? MMNotificationCategory else { return false } return identifier == obj.identifier } } -extension Set where Element: MMInteractiveCategory { +extension Set where Element: MMNotificationCategory { var uiUserNotificationCategoriesSet: Set? { return Set(self.map{$0.uiUserNotificationCategory}) } } -public final class MMCategoryAction: NSObject { +public final class MMNotificationAction: NSObject { let identifier: String let title: String - let options: [MMCategoryActionOptions]? + let options: [MMNotificationActionOptions]? let handlingBlock: (MTMessage, () -> Void) -> Void - public init?(identifier: String, title: String, options: [MMCategoryActionOptions]?, handlingBlock: @escaping (MTMessage, () -> Void) -> Void) { + public init?(identifier: String, title: String, options: [MMNotificationActionOptions]?, handlingBlock: @escaping (MTMessage, () -> Void) -> Void) { guard !identifier.hasPrefix("mm_") else { return nil } @@ -73,10 +73,10 @@ public final class MMCategoryAction: NSObject { } } -public final class MMCategoryActionOptions : NSObject { +public final class MMNotificationActionOptions : NSObject { let rawValue: Int init(rawValue: Int) { self.rawValue = rawValue } - public init(options: [MMCategoryActionOptions]) { + public init(options: [MMNotificationActionOptions]) { let totalValue = options.reduce(0) { (total, option) -> Int in return total | option.rawValue } @@ -85,9 +85,9 @@ public final class MMCategoryActionOptions : NSObject { public func contains(options: MMLogOutput) -> Bool { return rawValue & options.rawValue != 0 } - public static let foreground = MMCategoryActionOptions(rawValue: 0) //available starting from iOS 9.0 - public static let destructive = MMCategoryActionOptions(rawValue: 1 << 0) - public static let requireAuthentification = MMCategoryActionOptions(rawValue: 1 << 1) + public static let foreground = MMNotificationActionOptions(rawValue: 0) //available starting from iOS 9.0 + public static let destructive = MMNotificationActionOptions(rawValue: 1 << 0) + public static let requireAuthentification = MMNotificationActionOptions(rawValue: 1 << 1) }