Skip to content

Commit

Permalink
InteractiveCategories: renamed to align api with other platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
riskpp committed Jul 26, 2017
1 parent c47d186 commit e873895
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<MMInteractiveCategory>()
let category = MMNotificationCategory(identifier: categoryId, actions: [action!])
var set = Set<MMNotificationCategory>()
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) {
Expand Down
12 changes: 6 additions & 6 deletions Pod/Classes/Core/MobileMessaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<MMInteractiveCategory>) -> MobileMessaging {
self.interactiveCategories = categories
public func withInteractiveNotificationCategories(_ categories: Set<MMNotificationCategory>) -> MobileMessaging {
self.interactiveNotificationCategories = categories
return self
}

Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -460,13 +460,13 @@ public final class MobileMessaging: NSObject {
static var date: MMDate = MMDate() // testability

var sharedNotificationExtensionStorage: AppGroupMessageStorage?
var interactiveCategories: Set<MMInteractiveCategory>?
var interactiveNotificationCategories: Set<MMNotificationCategory>?

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()
Expand Down
6 changes: 3 additions & 3 deletions Pod/Classes/Core/MobileMessagingAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<MMInteractiveCategory>? {
open var interactiveNotificationCategories: Set<MMNotificationCategory>? {
return nil
}

Expand All @@ -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()
Expand Down
26 changes: 13 additions & 13 deletions Pod/Classes/InteractiveNotifications/MMInteractiveCategory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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<UIUserNotificationCategory>? {
return Set<UIUserNotificationCategory>(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
}
Expand All @@ -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
}
Expand All @@ -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)
}


Expand Down

0 comments on commit e873895

Please sign in to comment.