Skip to content

Commit

Permalink
Merge branch 'bugfix/0.9.3-increase-misconfiguration-resilience' into…
Browse files Browse the repository at this point in the history
… development
  • Loading branch information
rafaelsetragni committed Oct 14, 2024
2 parents 6e14267 + e05ec88 commit d2bb79d
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use_frameworks!

platform :ios, '11.0'
platform :ios, '12.0'

target 'IosAwnCore_Example' do
pod 'IosAwnCore', :path => '../'
Expand All @@ -18,7 +18,7 @@ post_install do |installer|
if target.name == 'IosAwnCore'
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
end
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
end
end
end
4 changes: 2 additions & 2 deletions IosAwnCore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'IosAwnCore'
s.version = '0.9.3'
s.version = '0.10.0'
s.summary = 'Awesome Notifications iOS Core'

s.description = <<-DESC
Expand All @@ -24,7 +24,7 @@ Awesome Notifications Ios Core (Only iOS devices).

s.static_framework = true
s.platform = :ios
s.ios.deployment_target = '11.0'
s.ios.deployment_target = '12.0'
s.swift_version = '5.3'

s.source_files = 'IosAwnCore/Classes/**/*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ class DismissedNotificationReceiver {
detailedCode: ExceptionCode.DETAILED_INVALID_ARGUMENTS + ".addNewDismissEvent.dismissedReceived")
}

dismissedReceived.registerDismissedEvent(
withLifeCycle:
LifeCycleManager
.shared
.currentLifeCycle)

BroadcastSender
.shared
.sendBroadcast(
Expand Down
50 changes: 50 additions & 0 deletions IosAwnCore/Classes/broadcasters/senders/BroadcastSender.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class BroadcastSender {
notificationCreated notificationReceived: NotificationReceived,
whenFinished completionHandler: @escaping (Bool) -> Void
){
_ = notificationReceived.registerCreateEvent(
withLifeCycle:
LifeCycleManager
.shared
.currentLifeCycle,
fromSource: notificationReceived.createdSource ?? .Local
)

if SwiftUtils.isRunningOnExtension() || LifeCycleManager.shared.currentLifeCycle == .AppKilled {
_ = CreatedManager.shared.saveCreated(
received: notificationReceived,
Expand All @@ -51,6 +59,12 @@ class BroadcastSender {
notificationDisplayed notificationReceived: NotificationReceived,
whenFinished completionHandler: @escaping (Bool) -> Void
){
notificationReceived.registerDisplayedEvent(
withLifeCycle:
LifeCycleManager
.shared
.currentLifeCycle)

if SwiftUtils.isRunningOnExtension() || LifeCycleManager.shared.currentLifeCycle == .AppKilled {
_ = DisplayedManager.shared.saveDisplayed(received: notificationReceived)
}
Expand All @@ -73,6 +87,12 @@ class BroadcastSender {
actionReceived: ActionReceived,
whenFinished completionHandler: @escaping (Bool, Error?) -> Void
){
actionReceived.registerActionEvent(
withLifeCycle:
LifeCycleManager
.shared
.currentLifeCycle)

if !ActionManager.shared.recovered { //LifeCycleManager.shared.currentLifeCycle == .AppKilled
ActionManager.shared.saveAction(received: actionReceived)
Logger.shared.d(TAG, "action saved")
Expand All @@ -93,6 +113,12 @@ class BroadcastSender {
notificationDismissed actionReceived: ActionReceived,
whenFinished completionHandler: @escaping (Bool, Error?) -> Void
){
actionReceived.registerDismissedEvent(
withLifeCycle:
LifeCycleManager
.shared
.currentLifeCycle)

if LifeCycleManager.shared.currentLifeCycle == .AppKilled {
DismissedManager.shared.saveDismissed(received: actionReceived)
}
Expand All @@ -111,6 +137,12 @@ class BroadcastSender {
silentAction: ActionReceived,
whenFinished completionHandler: @escaping (Bool, Error?) -> Void
){
silentAction.registerActionEvent(
withLifeCycle:
LifeCycleManager
.shared
.currentLifeCycle)

AwesomeEventsReceiver
.shared
.addActionEvent(
Expand All @@ -124,6 +156,12 @@ class BroadcastSender {
backgroundAction: ActionReceived,
whenFinished completionHandler: @escaping (Bool, Error?) -> Void
){
backgroundAction.registerActionEvent(
withLifeCycle:
LifeCycleManager
.shared
.currentLifeCycle)

AwesomeEventsReceiver
.shared
.addActionEvent(
Expand All @@ -137,6 +175,12 @@ class BroadcastSender {
silentAction actionReceived: ActionReceived,
whenFinished completionHandler: @escaping (Bool, Error?) -> Void
){
actionReceived.registerActionEvent(
withLifeCycle:
LifeCycleManager
.shared
.currentLifeCycle)

BackgroundService
.shared
.enqueue(
Expand All @@ -148,6 +192,12 @@ class BroadcastSender {
silentBackgroundAction actionReceived: ActionReceived,
whenFinished completionHandler: @escaping (Bool, Error?) -> Void
){
actionReceived.registerActionEvent(
withLifeCycle:
LifeCycleManager
.shared
.currentLifeCycle)

BackgroundService
.shared
.enqueue(
Expand Down
6 changes: 3 additions & 3 deletions IosAwnCore/Classes/managers/CreatedManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class CreatedManager : EventManager {
else { return false }
if received.createdDate == nil {
if !received.registerCreateEvent(
inLifeCycle: lifeCycle,
withLifeCycle: lifeCycle,
fromSource: source
) { return false }
}
Expand All @@ -62,7 +62,7 @@ public class CreatedManager : EventManager {
else { continue }
if received.createdDate == nil {
_ = received.registerCreateEvent(
inLifeCycle: .Terminated,
withLifeCycle: .Terminated,
fromSource: .Local
)
}
Expand All @@ -82,7 +82,7 @@ public class CreatedManager : EventManager {
if received.id != id { continue }
if received.createdDate == nil {
_ = received.registerCreateEvent(
inLifeCycle: .Terminated,
withLifeCycle: .Terminated,
fromSource: .Local
)
}
Expand Down
2 changes: 1 addition & 1 deletion IosAwnCore/Classes/managers/DisplayedManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class DisplayedManager : EventManager {
let receivedNotification = NotificationReceived(notificationScheduled.content)
receivedNotification.registerDisplayedEvent(
withDisplayedDate: displayedDate,
inLifeCycle: displayedDate == limitDate
withLifeCycle: displayedDate == limitDate
? .Foreground
: lastLifeCycle
)
Expand Down
29 changes: 21 additions & 8 deletions IosAwnCore/Classes/managers/LostEventsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ public class LostEventsManager {
try createdNotification.validate()
if (createdNotification.createdDate == nil){
_ = createdNotification.registerCreateEvent(
inLifeCycle: createdNotification.createdLifeCycle ?? .Terminated,
withLifeCycle: createdNotification.createdLifeCycle ?? .Terminated,
fromSource: createdNotification.createdSource ?? .Local
)
}
guard let id:Int = createdNotification.id
else { continue }
guard let createdDate:RealDateTime = createdNotification.createdDate
else { continue }
let createdDate:RealDateTime = createdNotification.createdDate ?? RealDateTime.init(
fromTimeZone: TimeZone(identifier: "UTC")
)

lostEvents.append(EventRegister(
eventName: Definitions.EVENT_NOTIFICATION_CREATED,
Expand Down Expand Up @@ -172,9 +173,11 @@ public class LostEventsManager {

guard let id:Int = displayedNotification.id
else { continue }
guard let displayedDate:RealDateTime =
displayedNotification.displayedDate ?? displayedNotification.createdDate
else { continue }
let displayedDate:RealDateTime =
displayedNotification.displayedDate ?? RealDateTime.init(
fromTimeZone: TimeZone(identifier: "UTC")
)
displayedNotification.displayedDate = displayedDate

if currentDate >= displayedDate && lastDisplayedDate <= displayedDate {
do {
Expand Down Expand Up @@ -233,12 +236,17 @@ public class LostEventsManager {
.listDismissed()

for dismissedNotification in lostDismissed {
let dismissedDate:RealDateTime =
dismissedNotification.dismissedDate ?? RealDateTime.init(
fromTimeZone: TimeZone(identifier: "UTC")
)
dismissedNotification.dismissedDate = dismissedDate
do {
try dismissedNotification.validate()

lostEvents.append(EventRegister(
eventName: Definitions.EVENT_NOTIFICATION_DISMISSED,
eventDate: dismissedNotification.dismissedDate!,
eventDate: dismissedDate,
notificationContent: dismissedNotification
))

Expand Down Expand Up @@ -277,12 +285,17 @@ public class LostEventsManager {
.recoverActions()

for notificationAction in lostActions {
let actionDate:RealDateTime =
notificationAction.actionDate ?? RealDateTime.init(
fromTimeZone: TimeZone(identifier: "UTC")
)
notificationAction.actionDate = actionDate
do {
try notificationAction.validate()

lostEvents.append(EventRegister(
eventName: Definitions.EVENT_DEFAULT_ACTION,
eventDate: notificationAction.actionDate!,
eventDate: actionDate,
notificationContent: notificationAction
))

Expand Down
20 changes: 9 additions & 11 deletions IosAwnCore/Classes/models/NotificationContentModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,23 @@ public class NotificationContentModel : AbstractModel {
withDisplayedDate createdDate: RealDateTime = RealDateTime.init(
fromTimeZone: TimeZone(identifier: "UTC")
),
inLifeCycle lifeCycle: NotificationLifeCycle,
withLifeCycle lifeCycle: NotificationLifeCycle,
fromSource createdSource: NotificationSource
) -> Bool {
if(self.createdDate == nil){
self.createdSource = createdSource
self.createdLifeCycle = lifeCycle
self.createdDate = createdDate

return true
}
return false
if self.createdDate != nil { return false }
self.createdSource = createdSource
self.createdLifeCycle = lifeCycle
self.createdDate = createdDate
return true
}

public func registerDisplayedEvent(
withDisplayedDate displayedDate: RealDateTime = RealDateTime.init(
fromTimeZone: TimeZone(identifier: "UTC")
),
inLifeCycle lifeCycle: NotificationLifeCycle
withLifeCycle lifeCycle: NotificationLifeCycle
){
if self.displayedDate != nil { return }
self.displayedLifeCycle = lifeCycle
self.displayedDate = displayedDate
}
Expand All @@ -100,7 +98,7 @@ public class NotificationContentModel : AbstractModel {

if schedule == nil {
registerDisplayedEvent(
inLifeCycle: lifeCycle
withLifeCycle: lifeCycle
)
}
else {
Expand Down
2 changes: 2 additions & 0 deletions IosAwnCore/Classes/models/returnedData/ActionReceived.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ public class ActionReceived : NotificationReceived {
}

public func registerActionEvent(withLifeCycle lifeCycle: NotificationLifeCycle){
if self.actionDate != nil { return }
actionDate = RealDateTime.init(fromTimeZone: RealDateTime.utcTimeZone)
actionLifeCycle = lifeCycle
}

public func registerDismissedEvent(withLifeCycle lifeCycle: NotificationLifeCycle){
if self.dismissedDate != nil { return }
dismissedDate = RealDateTime.init(fromTimeZone: RealDateTime.utcTimeZone)
dismissedLifeCycle = lifeCycle
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public class NotificationSenderAndScheduler {
notificationModel
.content!
.registerCreateEvent(
inLifeCycle: self.appLifeCycle,
withLifeCycle: self.appLifeCycle,
fromSource: self.createdSource)

if notificationModel.schedule != nil {
Expand Down Expand Up @@ -193,7 +193,7 @@ public class NotificationSenderAndScheduler {
}

receivedNotification = NotificationReceived(notificationModel.content)
receivedNotification?.registerDisplayedEvent(inLifeCycle: self.appLifeCycle)
receivedNotification?.registerDisplayedEvent(withLifeCycle: self.appLifeCycle)

receivedNotification!.displayedLifeCycle =
receivedNotification!.displayedLifeCycle ?? self.appLifeCycle
Expand Down

0 comments on commit d2bb79d

Please sign in to comment.