From 55bc04b40283db195e6d066aecc42ff240fc94a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Corr=C3=AAa?= Date: Thu, 28 Jul 2022 18:20:47 +0100 Subject: [PATCH] fix: classes renamed to avoid incompatibility issues (#33) --- CHANGELOG.md | 3 +++ plugin.xml | 4 ++-- .../.xccurrentversion | 8 ++++++++ .../NotificationsModel 2.xcdatamodel/contents | 18 ++++++++++++++++++ .../FirebaseMessagingApplicationDelegate.swift | 8 ++++---- src/ios/Managers/NotificationManager.swift | 12 ++++++------ ...{OSExtraData.swift => OSFCMExtraData.swift} | 6 +++--- ...ification.swift => OSFCMNotification.swift} | 12 ++++++------ 8 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 src/ios/CoreDataManager/NotificationsModel.xcdatamodeld/.xccurrentversion create mode 100644 src/ios/CoreDataManager/NotificationsModel.xcdatamodeld/NotificationsModel 2.xcdatamodel/contents rename src/ios/Model/{OSExtraData.swift => OSFCMExtraData.swift} (94%) rename src/ios/Model/{OSNotification.swift => OSFCMNotification.swift} (88%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01fe0598..3a1ca514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The changes documented here do not include those from the original repository. ## [Released] +## 28-07-2022 +- Renamed classes to avoid incompatibility. (https://outsystemsrd.atlassian.net/browse/RMET-1743) + ## 26-07-2022 - Added dependency on external libs. Changed methods to sync. (https://outsystemsrd.atlassian.net/browse/RMET-1480) diff --git a/plugin.xml b/plugin.xml index e5160b2d..3cbd1d78 100644 --- a/plugin.xml +++ b/plugin.xml @@ -43,8 +43,8 @@ - - + + diff --git a/src/ios/CoreDataManager/NotificationsModel.xcdatamodeld/.xccurrentversion b/src/ios/CoreDataManager/NotificationsModel.xcdatamodeld/.xccurrentversion new file mode 100644 index 00000000..23e2f331 --- /dev/null +++ b/src/ios/CoreDataManager/NotificationsModel.xcdatamodeld/.xccurrentversion @@ -0,0 +1,8 @@ + + + + + _XCCurrentVersionName + NotificationsModel 2.xcdatamodel + + diff --git a/src/ios/CoreDataManager/NotificationsModel.xcdatamodeld/NotificationsModel 2.xcdatamodel/contents b/src/ios/CoreDataManager/NotificationsModel.xcdatamodeld/NotificationsModel 2.xcdatamodel/contents new file mode 100644 index 00000000..d8aa0f24 --- /dev/null +++ b/src/ios/CoreDataManager/NotificationsModel.xcdatamodeld/NotificationsModel 2.xcdatamodel/contents @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ios/FirebaseMessagingApplicationDelegate.swift b/src/ios/FirebaseMessagingApplicationDelegate.swift index 4c1907ce..3e3e4786 100644 --- a/src/ios/FirebaseMessagingApplicationDelegate.swift +++ b/src/ios/FirebaseMessagingApplicationDelegate.swift @@ -250,10 +250,10 @@ extension FirebaseMessagingApplicationDelegate { let extraData = userInfo[JSONKeys.extraDataList] as? [NotificationDictionary] { let notificationDict: [String: Any] = [ - OSNotification.CodingKeys.messageID.rawValue: messageID, - OSNotification.CodingKeys.timeToLive.rawValue: timeToLive, - OSNotification.CodingKeys.extraDataList.rawValue: extraData, - OSNotification.CodingKeys.timeStamp.rawValue: Date().millisecondsSince1970 + OSFCMNotification.CodingKeys.messageID.rawValue: messageID, + OSFCMNotification.CodingKeys.timeToLive.rawValue: timeToLive, + OSFCMNotification.CodingKeys.extraDataList.rawValue: extraData, + OSFCMNotification.CodingKeys.timeStamp.rawValue: Date().millisecondsSince1970 ] _ = notificationManager.insertNotification(notificationDict: notificationDict) } diff --git a/src/ios/Managers/NotificationManager.swift b/src/ios/Managers/NotificationManager.swift index c793969d..427536cc 100644 --- a/src/ios/Managers/NotificationManager.swift +++ b/src/ios/Managers/NotificationManager.swift @@ -11,7 +11,7 @@ public protocol NotificationManagerProtocol { /// Fetches the store notifications on Core Data. /// - Returns: An array of notifications or an error, in case of failure. - func fetchNotifications() -> Result<[OSNotification], Error> + func fetchNotifications() -> Result<[OSFCMNotification], Error> /// Sends a local notification on to the Notification Center. /// - Parameters: @@ -65,8 +65,8 @@ public final class NotificationManager: NSObject { /// Deletes all notifications provided by input from Core Data manager. /// - Parameter notifications: Notifications to remove. /// - Returns: A boolean indicating the success of the operation or an error, in case of failure. - public func deletePendingNotifications(_ notifications: [OSNotification]) -> Result { - let fetchRequest: NSFetchRequest = OSNotification.fetchRequest() + public func deletePendingNotifications(_ notifications: [OSFCMNotification]) -> Result { + let fetchRequest: NSFetchRequest = OSFCMNotification.fetchRequest() do { let fetchRequestResults = try self.coreDataManager.fetch(fetchRequest) let filtered = fetchRequestResults.filter({ notifications.contains($0) }) @@ -119,7 +119,7 @@ extension NotificationManager: NotificationManagerProtocol { decoder.userInfo[CodingUserInfoKey.managedObjectContext] = self.coreDataManager.context() do { let notificationData = try JSONSerialization.data(withJSONObject: notificationDict) - _ = try decoder.decode(OSNotification.self, from: notificationData) + _ = try decoder.decode(OSFCMNotification.self, from: notificationData) try self.coreDataManager.saveContext() } catch { @@ -131,8 +131,8 @@ extension NotificationManager: NotificationManagerProtocol { /// Fetches the store notifications on Core Data. /// - Returns: An array of notifications or an error, in case of failure. - public func fetchNotifications() -> Result<[OSNotification], Error> { - let fetchRequest: NSFetchRequest = OSNotification.fetchRequest() + public func fetchNotifications() -> Result<[OSFCMNotification], Error> { + let fetchRequest: NSFetchRequest = OSFCMNotification.fetchRequest() do { let notifications = try self.coreDataManager.fetch(fetchRequest) return .success(notifications) diff --git a/src/ios/Model/OSExtraData.swift b/src/ios/Model/OSFCMExtraData.swift similarity index 94% rename from src/ios/Model/OSExtraData.swift rename to src/ios/Model/OSFCMExtraData.swift index 399fda9f..b10b7f4a 100644 --- a/src/ios/Model/OSExtraData.swift +++ b/src/ios/Model/OSFCMExtraData.swift @@ -1,8 +1,8 @@ import CoreData /// Core Data Model that stores the dynamic properties associated with a specific Notification. -@objc(OSExtraData) -public class OSExtraData: NSManagedObject, Codable { +@objc(OSFCMExtraData) +public class OSFCMExtraData: NSManagedObject, Codable { /// Constructor method inherited from `NSManagedObject`. /// - Parameters: @@ -20,7 +20,7 @@ public class OSExtraData: NSManagedObject, Codable { init(key: String, value: String, context: NSManagedObjectContext) { - super.init(entity: NSEntityDescription.entity(forEntityName: "OSExtraData", in: context)!, insertInto: context) + super.init(entity: NSEntityDescription.entity(forEntityName: "OSFCMExtraData", in: context)!, insertInto: context) self.key = key self.value = value } diff --git a/src/ios/Model/OSNotification.swift b/src/ios/Model/OSFCMNotification.swift similarity index 88% rename from src/ios/Model/OSNotification.swift rename to src/ios/Model/OSFCMNotification.swift index 537d3883..73f99616 100644 --- a/src/ios/Model/OSNotification.swift +++ b/src/ios/Model/OSFCMNotification.swift @@ -1,8 +1,8 @@ import CoreData /// Core Data Model that stores the properties associated with a Notification. -@objc(OSNotification) -public class OSNotification: NSManagedObject, Codable { +@objc(OSFCMNotification) +public class OSFCMNotification: NSManagedObject, Codable { /// Constructor method inherited from `NSManagedObject`. /// - Parameters: @@ -20,11 +20,11 @@ public class OSNotification: NSManagedObject, Codable { /// - timeStamp: Numeric representation of the creation datetime, /// - context: An object space to manipulate and track changes to managed objects. init(messageID: String, - extraDataList: [OSExtraData], + extraDataList: [OSFCMExtraData], timeToLive: String, timeStamp: Double, context: NSManagedObjectContext) { - super.init(entity: NSEntityDescription.entity(forEntityName: "OSNotification", in: context)!, insertInto: context) + super.init(entity: NSEntityDescription.entity(forEntityName: "OSFCMNotification", in: context)!, insertInto: context) self.messageID = messageID self.extraDataList = NSSet(array: extraDataList) self.timeToLive = timeToLive @@ -41,7 +41,7 @@ public class OSNotification: NSManagedObject, Codable { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(messageID, forKey: .messageID) - try container.encode(extraDataList?.allObjects as? [OSExtraData], forKey: .extraDataList) + try container.encode(extraDataList?.allObjects as? [OSFCMExtraData], forKey: .extraDataList) try container.encode(timeToLive, forKey: .timeToLive) try container.encode(timeStamp, forKey: .timeStamp) } @@ -55,7 +55,7 @@ public class OSNotification: NSManagedObject, Codable { let container = try decoder.container(keyedBy: CodingKeys.self) let messageID = try container.decode(String.self, forKey: .messageID) - let extraDataList = try container.decode([OSExtraData].self, forKey: .extraDataList) + let extraDataList = try container.decode([OSFCMExtraData].self, forKey: .extraDataList) let timeToLive = try container.decode(String.self, forKey: .timeToLive) let timeStamp = try container.decode(Double.self, forKey: .timeStamp) self.init(messageID: messageID, extraDataList: extraDataList, timeToLive: timeToLive, timeStamp: timeStamp, context: context)