Skip to content

Commit

Permalink
[fix] Fix The startup time interval being ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
engali94 committed Jun 18, 2021
1 parent cb5a0de commit 49437a0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion HeraSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'HeraSDK'
s.version = '2.0.1'
s.version = '2.0.2'
s.summary = 'An abstraction layer used to manage Ads.'

s.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion Sources/Ads/Banner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ final class Banner: HeraAd {

// NOTE: The banner always refreshes itself based on specific
// time intervals so we need to take this into considration.
var lastShowingDate = Date()
var lastShowingDate: Date?
}
2 changes: 1 addition & 1 deletion Sources/Ads/HeraAd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ protocol HeraAd {
var lastLoadingDate: Date? { get set }

/// The date represents when the ad is last showed.
var lastShowingDate: Date { get set }
var lastShowingDate: Date? { get set }
}
2 changes: 1 addition & 1 deletion Sources/Ads/Interstitial.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import Foundation
final class Interstitial: HeraAd {
var state: AdState = .hidden
var lastLoadingDate: Date?
var lastShowingDate = Date()
var lastShowingDate: Date?
}
8 changes: 5 additions & 3 deletions Sources/Core/Hera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ public final class Hera {
Logger.log(.debug, "Will show ad of type \(type) and action \(action)")

guard let adType = config.actions[action]?.type, type == adType else {
self.notifiyObserver { $0?.heraDidFailToShowAd(for: action, adType: type, error: HeraError.actionDoesNotMatch) }
let avaliableActions = config.actions.map({ $0.key }).joined(separator: ", ")
self.notifiyObserver { $0?.heraDidFailToShowAd(for: action, adType: type, error: HeraError.actionDoesNotMatch(action: action, availableActions: avaliableActions)) }
return
}

Expand Down Expand Up @@ -306,7 +307,7 @@ private extension Hera {
throw HeraError.outOfTimeInterval
}

let date = adContainer.ad(ofType: type).lastShowingDate
guard let date = adContainer.ad(ofType: type).lastShowingDate else { return }
if Date().timeIntervalSince(date) <= config.adInterval {
throw HeraError.betweenTwoAdsInterval
}
Expand All @@ -322,7 +323,8 @@ private extension Hera {
}

guard let adId = config.actions[action]?.unitID else {
throw HeraError.actionDoesNotMatch
let avaliableActions = config.actions.map({ $0.key }).joined(separator: ", ")
throw HeraError.actionDoesNotMatch(action: action, availableActions: avaliableActions)
}

try self.checkTimeInterval(from: config, andAction: action, type: adType)
Expand Down
54 changes: 27 additions & 27 deletions Sources/Core/HeraError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,58 @@ import Foundation

/// A type encloses all the possible errors thrown by the SDK.
public enum HeraError: Swift.Error {
case falidToLoad
case falidToLoad(action: String)
case invalidData
case outOfTimeInterval
case outOfTimeInterval
case betweenTwoAdsInterval
case actionDoesNotMatch
case anotherOperationInProgress
case notCongiguredProperly
case actionDoesNotMatch(action: String, availableActions: String)
case anotherOperationInProgress
case notCongiguredProperly
case wrongAppID
case anotherAdIsBeingShown
case anotherAdIsBeingShown
case wrongPresenterType
case viewDoesNotHaveVisibleUIWindow
case viewDoesNotHaveVisibleUIWindow
case nilBanner
}

extension HeraError: CustomStringConvertible, LocalizedError {
public var description: String {
switch self {
case .falidToLoad:
return "Failed to load the add"
public var description: String {
switch self {
case .falidToLoad(let action):
return "Failed to load the add for action: \(action)"

case .invalidData:
return "Invalid data, can;t be decoded!"
return "Invalid data, can't be decoded!"

case .outOfTimeInterval:
return "Cant show the add at the moment because the time interval since startup is less than the configured."
case .outOfTimeInterval:
return "Cant show the add at the moment because the time interval since the app startup is less than the configured. Please wait"

case .actionDoesNotMatch:
return "The provided action doesn't any of the fetched actions. Please make sure you provided the right action name (case-sensetive)."
case .actionDoesNotMatch(let action, let fethcedActions):
return "The provided action: (\(action) doesn't any of the fetched actions \(fethcedActions). Please make sure you provided the right action name (case-sensetive)."

case .anotherOperationInProgress:
case .anotherOperationInProgress:
return "Trying to load ad while another load operation is in progress. Please wait!"

case .notCongiguredProperly: return "The Manager is misconfigured, make sure you have called both initialize(apiKey: environment:) and setUserProperties(_:) with the right parameters consequently."
case .notCongiguredProperly: return "The fetched configs are invalid."

case .betweenTwoAdsInterval:
return "Cant show the add at the moment because the time interval since the last shown ad is less than the configured."

case .wrongAppID:
return "The provider ID is incorrect."
case .anotherAdIsBeingShown:
return "Can show add for now because another ad is being shown 🔫"
case .anotherAdIsBeingShown:
return "Can show add for now because another ad is being shown 🔫"
case .wrongPresenterType:
return "You are either trying to present interstial on a UIView or presenting banner on UIViewController. Make sure you have used the right presenter type"
case .viewDoesNotHaveVisibleUIWindow:
return "View does not have visible UIWindow"
case .viewDoesNotHaveVisibleUIWindow:
return "View does not have visible UIWindow"
case .nilBanner:
return "Banner is deallocated. Please load the banner before trying to show it."
}
}
}

public var errorDescription: String? {
description
}
public var errorDescription: String? {
description
}
}

0 comments on commit 49437a0

Please sign in to comment.