Skip to content

Commit 71230ac

Browse files
authored
Merge pull request #370 from Iterable/6.2.10
6.2.10
2 parents 5868252 + 21593b3 commit 71230ac

15 files changed

+891
-113
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 6.2.10
6+
#### Added
7+
- An option to pause automatic in-app displaying has been added. To pause, set `IterableAPI.inAppManager.isAutoDisplayPaused` to `true` (default: `false`).
8+
59
## 6.2.9
610
#### Fixed
711
- In rare instances `regiserDeviceToken` API can cause crash. This should fix it.

Iterable-iOS-AppExtensions.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "Iterable-iOS-AppExtensions"
33
s.module_name = "IterableAppExtensions"
4-
s.version = "6.2.9"
4+
s.version = "6.2.10"
55
s.summary = "App Extensions for Iterable SDK"
66

77
s.description = <<-DESC

Iterable-iOS-SDK.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "Iterable-iOS-SDK"
33
s.module_name = "IterableSDK"
4-
s.version = "6.2.9"
4+
s.version = "6.2.10"
55
s.summary = "Iterable's official SDK for iOS"
66

77
s.description = <<-DESC

swift-sdk/Internal/EmptyInAppManager.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ class EmptyInAppManager: IterableInternalInAppManagerProtocol {
1616
return nil
1717
}
1818

19+
var isAutoDisplayPaused: Bool {
20+
get {
21+
false
22+
}
23+
24+
set {}
25+
}
26+
1927
func getMessages() -> [IterableInAppMessage] {
2028
return []
2129
}

swift-sdk/Internal/InAppInternal.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import Foundation
77

88
protocol InAppFetcherProtocol {
9-
// Fetch from server and sync
109
func fetch() -> Future<[IterableInAppMessage], Error>
1110
}
1211

@@ -33,6 +32,10 @@ class InAppFetcher: InAppFetcherProtocol {
3332
self.apiClient = apiClient
3433
}
3534

35+
deinit {
36+
ITBInfo()
37+
}
38+
3639
func fetch() -> Future<[IterableInAppMessage], Error> {
3740
ITBInfo()
3841

@@ -44,13 +47,10 @@ class InAppFetcher: InAppFetcherProtocol {
4447
return InAppHelper.getInAppMessagesFromServer(apiClient: apiClient, number: numMessages).mapFailure { $0 }
4548
}
4649

47-
private weak var apiClient: ApiClientProtocol?
50+
// MARK: - Private/Internal
4851

49-
deinit {
50-
ITBInfo()
51-
}
52+
private weak var apiClient: ApiClientProtocol?
5253

53-
// how many messages to fetch
5454
private let numMessages = 100
5555
}
5656

@@ -71,7 +71,7 @@ struct InAppMessageContext {
7171
inboxSessionId: inboxSessionId)
7272
}
7373

74-
// For backward compatibility, assume .inApp
74+
/// For backward compatibility, assume .inApp
7575
static func from(messageId: String, deviceMetadata _: DeviceMetadata) -> InAppMessageContext {
7676
return InAppMessageContext(messageId: messageId,
7777
saveToInbox: false,

swift-sdk/Internal/InAppManager.swift

Lines changed: 91 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,20 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
8181
notificationCenter.removeObserver(self)
8282
}
8383

84-
func start() -> Future<Bool, Error> {
85-
ITBInfo()
84+
// MARK: - IterableInAppManagerProtocol
85+
86+
var isAutoDisplayPaused: Bool {
87+
get {
88+
autoDisplayPaused
89+
}
8690

87-
if messagesMap.values.filter({ $0.saveToInbox == true }).count > 0 {
88-
callbackQueue.async {
89-
self.notificationCenter.post(name: .iterableInboxChanged, object: self, userInfo: nil)
91+
set {
92+
autoDisplayPaused = newValue
93+
94+
if !autoDisplayPaused {
95+
_ = scheduleSync()
9096
}
9197
}
92-
93-
return scheduleSync()
9498
}
9599

96100
func getMessages() -> [IterableInAppMessage] {
@@ -109,32 +113,6 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
109113
return getInboxMessages().filter { $0.read == false }.count
110114
}
111115

112-
func createInboxMessageViewController(for message: IterableInAppMessage, withInboxMode inboxMode: IterableInboxViewController.InboxMode, inboxSessionId: String? = nil) -> UIViewController? {
113-
guard let content = message.content as? IterableHtmlInAppContent else {
114-
ITBError("Invalid Content in message")
115-
return nil
116-
}
117-
118-
let parameters = IterableHtmlMessageViewController.Parameters(html: content.html,
119-
padding: content.edgeInsets,
120-
messageMetadata: IterableInAppMessageMetadata(message: message, location: .inbox),
121-
isModal: inboxMode == .popup,
122-
inboxSessionId: inboxSessionId)
123-
let createResult = IterableHtmlMessageViewController.create(parameters: parameters)
124-
let viewController = createResult.viewController
125-
126-
createResult.futureClickedURL.onSuccess { url in
127-
ITBInfo()
128-
129-
// in addition perform action or url delegate task
130-
self.handle(clickedUrl: url, forMessage: message, location: .inbox)
131-
}
132-
133-
viewController.navigationItem.title = message.inboxMetadata?.title
134-
135-
return viewController
136-
}
137-
138116
func show(message: IterableInAppMessage) {
139117
ITBInfo()
140118

@@ -150,12 +128,6 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
150128
}
151129
}
152130

153-
func remove(message: IterableInAppMessage) {
154-
ITBInfo()
155-
156-
removePrivate(message: message)
157-
}
158-
159131
func remove(message: IterableInAppMessage, location: InAppLocation) {
160132
ITBInfo()
161133

@@ -186,25 +158,56 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
186158
return messagesMap[id]
187159
}
188160

189-
func isOkToShowNow(message: IterableInAppMessage) -> Bool {
190-
guard message.didProcessTrigger == false else {
191-
ITBInfo("message with id: \(message.messageId) is already processed")
192-
return false
161+
// MARK: - IterableInternalInAppManagerProtocol
162+
163+
func start() -> Future<Bool, Error> {
164+
ITBInfo()
165+
166+
if messagesMap.values.filter({ $0.saveToInbox }).count > 0 {
167+
callbackQueue.async {
168+
self.notificationCenter.post(name: .iterableInboxChanged, object: self, userInfo: nil)
169+
}
193170
}
194171

195-
guard InAppManager.getWaitTimeInterval(fromLastTime: lastDismissedTime, currentTime: dateProvider.currentDate, gap: retryInterval) <= 0 else {
196-
ITBInfo("can't display within retryInterval window")
197-
return false
172+
return scheduleSync()
173+
}
174+
175+
func createInboxMessageViewController(for message: IterableInAppMessage,
176+
withInboxMode inboxMode: IterableInboxViewController.InboxMode,
177+
inboxSessionId: String? = nil) -> UIViewController? {
178+
guard let content = message.content as? IterableHtmlInAppContent else {
179+
ITBError("Invalid Content in message")
180+
return nil
198181
}
199182

200-
guard InAppManager.getWaitTimeInterval(fromLastTime: lastDisplayTime, currentTime: dateProvider.currentDate, gap: retryInterval) <= 0 else {
201-
ITBInfo("can't display within retryInterval window")
202-
return false
183+
let parameters = IterableHtmlMessageViewController.Parameters(html: content.html,
184+
padding: content.edgeInsets,
185+
messageMetadata: IterableInAppMessageMetadata(message: message, location: .inbox),
186+
isModal: inboxMode == .popup,
187+
inboxSessionId: inboxSessionId)
188+
let createResult = IterableHtmlMessageViewController.create(parameters: parameters)
189+
let viewController = createResult.viewController
190+
191+
createResult.futureClickedURL.onSuccess { url in
192+
ITBInfo()
193+
194+
// in addition perform action or url delegate task
195+
self.handle(clickedUrl: url, forMessage: message, location: .inbox)
203196
}
204197

205-
return true
198+
viewController.navigationItem.title = message.inboxMetadata?.title
199+
200+
return viewController
206201
}
207202

203+
func remove(message: IterableInAppMessage) {
204+
ITBInfo()
205+
206+
removePrivate(message: message)
207+
}
208+
209+
// MARK: - Private/Internal
210+
208211
@objc private func onAppEnteredForeground(notification _: Notification) {
209212
ITBInfo()
210213

@@ -301,14 +304,15 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
301304
case let .notShown(reason):
302305
ITBError("Could not show message: \(reason)")
303306
case let .shown(futureClickedURL):
304-
// set read
305307
ITBDebug("in-app shown")
308+
306309
set(read: true, forMessage: message)
307310

308311
updateMessage(message, didProcessTrigger: true, consumed: consume)
309312

310313
futureClickedURL.onSuccess { url in
311314
ITBDebug("in-app clicked")
315+
312316
// call the client callback, if present
313317
_ = callback?(url)
314318

@@ -350,10 +354,11 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
350354
}
351355
}
352356

353-
@discardableResult private func updateMessage(_ message: IterableInAppMessage,
354-
read: Bool? = nil,
355-
didProcessTrigger: Bool? = nil,
356-
consumed: Bool? = nil) -> Future<Bool, IterableError> {
357+
@discardableResult
358+
private func updateMessage(_ message: IterableInAppMessage,
359+
read: Bool? = nil,
360+
didProcessTrigger: Bool? = nil,
361+
consumed: Bool? = nil) -> Future<Bool, IterableError> {
357362
ITBDebug()
358363

359364
let result = Promise<Bool, IterableError>()
@@ -478,7 +483,10 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
478483
}
479484

480485
// From client side
481-
private func removePrivate(message: IterableInAppMessage, location: InAppLocation = .inApp, source: InAppDeleteSource? = nil, inboxSessionId: String? = nil) {
486+
private func removePrivate(message: IterableInAppMessage,
487+
location: InAppLocation = .inApp,
488+
source: InAppDeleteSource? = nil,
489+
inboxSessionId: String? = nil) {
482490
ITBInfo()
483491

484492
updateMessage(message, didProcessTrigger: true, consumed: true)
@@ -545,6 +553,7 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
545553
private var syncResult: Future<Bool, Error>?
546554
private var lastSyncTime: Date?
547555
private let moveToForegroundSyncInterval: Double = 1.0 * 60.0 // don't sync within sixty seconds
556+
private var autoDisplayPaused = false
548557
}
549558

550559
extension InAppManager: InAppNotifiable {
@@ -613,3 +622,29 @@ extension InAppManager: InAppNotifiable {
613622
return result
614623
}
615624
}
625+
626+
extension InAppManager: InAppDisplayChecker {
627+
func isOkToShowNow(message: IterableInAppMessage) -> Bool {
628+
guard !isAutoDisplayPaused else {
629+
ITBInfo("automatic in-app display has been paused")
630+
return false
631+
}
632+
633+
guard !message.didProcessTrigger else {
634+
ITBInfo("message with id: \(message.messageId) is already processed")
635+
return false
636+
}
637+
638+
guard InAppManager.getWaitTimeInterval(fromLastTime: lastDismissedTime, currentTime: dateProvider.currentDate, gap: retryInterval) <= 0 else {
639+
ITBInfo("can't display within retryInterval window")
640+
return false
641+
}
642+
643+
guard InAppManager.getWaitTimeInterval(fromLastTime: lastDisplayTime, currentTime: dateProvider.currentDate, gap: retryInterval) <= 0 else {
644+
ITBInfo("can't display within retryInterval window")
645+
return false
646+
}
647+
648+
return true
649+
}
650+
}

swift-sdk/Internal/InAppPersistence.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import Foundation
77
import UIKit
88

9-
// This is needed because String(describing: ...) returns wrong
10-
// value for this enum when it is exposed to Objective C
9+
/// This is needed because String(describing: ...) returns the
10+
/// wrong value for this enum when it is exposed to Objective-C
1111
extension IterableInAppContentType: CustomStringConvertible {
1212
public var description: String {
1313
switch self {
@@ -36,8 +36,8 @@ extension IterableInAppContentType {
3636
}
3737
}
3838

39-
// This is needed because String(describing: ...) returns wrong
40-
// value for this enum when it is exposed to Objective C
39+
/// This is needed because String(describing: ...) returns the
40+
/// wrong value for this enum when it is exposed to Objective-C
4141
extension IterableInAppTriggerType: CustomStringConvertible {
4242
public var description: String {
4343
switch self {
@@ -52,7 +52,6 @@ extension IterableInAppTriggerType: CustomStringConvertible {
5252
}
5353

5454
extension IterableInAppTriggerType {
55-
// Internal
5655
static func from(string: String) -> IterableInAppTriggerType {
5756
switch string.lowercased() {
5857
case String(describing: IterableInAppTriggerType.immediate).lowercased():
@@ -366,7 +365,6 @@ class InAppFilePersister: InAppPersistenceProtocol {
366365
private let ext: String
367366
}
368367

369-
// Files Utility class
370368
struct FileHelper {
371369
static func getUrl(filename: String, ext: String) -> URL? {
372370
guard let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else {

swift-sdk/IterableAPI.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import UIKit
99

1010
@objcMembers public final class IterableAPI: NSObject {
1111
// Current SDK Version.
12-
public static let sdkVersion = "6.2.9"
12+
public static let sdkVersion = "6.2.10"
1313

1414
// MARK: Initialization
1515

@@ -27,9 +27,14 @@ import UIKit
2727
initialize(apiKey: apiKey, launchOptions: nil, config: config)
2828
}
2929

30-
/// You should call this method and not call the init method directly.
31-
/// - parameter apiKey: Iterable API Key.
32-
/// - parameter launchOptions: The launchOptions coming from application:didLaunching:withOptions
30+
/// An SDK initializer taking in the Iterable Mobile API key to be utilized and the
31+
/// `launchOptions` passed on from the app delegate, using default SDK settings
32+
///
33+
/// - Parameters:
34+
/// - apiKey: The Iterable Mobile API key to be used with the SDK
35+
/// - launchOptions: The `launchOptions` coming from `application(_:didFinishLaunchingWithOptions:)`
36+
///
37+
/// - SeeAlso: IterableConfig
3338
public static func initialize(apiKey: String,
3439
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
3540
initialize(apiKey: apiKey, launchOptions: launchOptions, config: IterableConfig())

0 commit comments

Comments
 (0)