Skip to content

Commit 7b5f68c

Browse files
Merge pull request #49 from Iterable/feature/mob-166-remove-spawn
[MOB-166] - Remove spawnInApp
2 parents 50e7cfc + 5826993 commit 7b5f68c

File tree

4 files changed

+44
-83
lines changed

4 files changed

+44
-83
lines changed

host-app/ViewController.swift

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -73,51 +73,54 @@ class ViewController: UIViewController {
7373
@IBAction func showInApp2Tap(_ sender: UIButton) {
7474
ITBInfo()
7575

76-
let networkSession = MockNetworkSession(
77-
statusCode: 200,
78-
json: ["inAppMessages" : [[
79-
"content" : ["html" : "<a href='https://www.google.com/q=something'>Click Here</a>"],
80-
"messageId" : "messageId",
81-
"campaignId" : "campaignId"] ]])
76+
let mockInAppSynchronizer = MockInAppSynchronizer()
77+
let mockInAppDelegate = MockInAppDelegate(showInApp: .skip)
78+
let config = IterableConfig()
79+
config.inAppDelegate = mockInAppDelegate
80+
let payload = ["inAppMessages" : [[
81+
"content" : ["html" : "<a href='https://www.google.com/q=something'>Click Here</a>"],
82+
"messageId" : "messageId",
83+
"campaignId" : "campaignId"]]
84+
]
8285
IterableAPI.initializeForTesting(apiKey: "apiKey",
83-
networkSession: networkSession)
84-
85-
networkSession.callback = {(_, _, _) in
86-
networkSession.data = [:].toData()
87-
}
86+
config: config,
87+
inAppSynchronizer: mockInAppSynchronizer,
88+
inAppDisplayer: InAppDisplayer())
8889

89-
IterableAPI.spawnInAppNotification { (str) in
90-
ITBInfo("callback: \(str ?? "<nil>")")
90+
mockInAppSynchronizer.mockInAppPayloadFromServer(payload)
91+
let message = IterableAPI.inAppManager.getMessages()[0]
92+
93+
IterableAPI.inAppManager.show(message: message, consume: true) { (str) in
9194
self.statusLbl.text = str
9295
}
9396
}
9497

9598
// Center
9699
@IBAction func showInApp3Tap(_ sender: UIButton) {
97100
ITBInfo()
98-
99-
// In app with Center display
100-
// with left and right padding > 100
101-
let networkSession = MockNetworkSession(
102-
statusCode: 200,
103-
json: ["inAppMessages" : [[
104-
"content" : [
105-
"html" : "<a href='https://www.google.com/q=something'>Click Here</a>",
106-
"inAppDisplaySettings" : ["backgroundAlpha" : 0.5, "left" : ["percentage" : 60], "right" : ["percentage" : 60], "bottom" : ["displayOption" : "AutoExpand"], "top" : ["displayOption" : "AutoExpand"]]
107-
],
108-
"messageId" : "messageId",
109-
"campaignId" : "campaignId",
110-
]
111-
]])
101+
102+
let mockInAppSynchronizer = MockInAppSynchronizer()
103+
let mockInAppDelegate = MockInAppDelegate(showInApp: .skip)
104+
let config = IterableConfig()
105+
config.inAppDelegate = mockInAppDelegate
106+
let payload = ["inAppMessages" : [[
107+
"content" : [
108+
"html" : "<a href='https://www.google.com/q=something'>Click Here</a>",
109+
"inAppDisplaySettings" : ["backgroundAlpha" : 0.5, "left" : ["percentage" : 60], "right" : ["percentage" : 60], "bottom" : ["displayOption" : "AutoExpand"], "top" : ["displayOption" : "AutoExpand"]]
110+
],
111+
"messageId" : "messageId",
112+
"campaignId" : "campaignId",
113+
]]
114+
]
112115
IterableAPI.initializeForTesting(apiKey: "apiKey",
113-
networkSession: networkSession)
116+
config: config,
117+
inAppSynchronizer: mockInAppSynchronizer,
118+
inAppDisplayer: InAppDisplayer())
114119

115-
networkSession.callback = {(_, _, _) in
116-
networkSession.data = [:].toData()
117-
}
120+
mockInAppSynchronizer.mockInAppPayloadFromServer(payload)
121+
let message = IterableAPI.inAppManager.getMessages()[0]
118122

119-
IterableAPI.spawnInAppNotification { (str) in
120-
ITBInfo("callback: \(str ?? "<nil>")")
123+
IterableAPI.inAppManager.show(message: message, consume: true) { (str) in
121124
self.statusLbl.text = str
122125
}
123126
}

swift-sdk/Internal/InAppHelper.swift

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -317,25 +317,6 @@ struct InAppHelper {
317317
return payload[.ITBL_IN_APP_MESSAGE] as? [[AnyHashable : Any]] ?? []
318318
}
319319

320-
/// Gets the first message from the payload, if one esists or nil if the payload is empty
321-
static func spawn(inAppNotification callbackBlock: ITEActionBlock?, internalApi: IterableAPIInternal) -> Future<Bool> {
322-
return internalApi.getInAppMessages(1).map {
323-
getFirstInAppMessage(fromPayload: $0, internalApi: internalApi).map { showInApp(message: $0, callback: callbackBlock) }
324-
?? false
325-
}
326-
}
327-
328-
private static func getFirstMessageDict(fromPayload payload: [AnyHashable : Any]) -> [AnyHashable : Any]? {
329-
let messages = getInAppDicts(fromPayload: payload)
330-
return messages.count > 0 ? messages[0] : nil
331-
}
332-
333-
private static func getFirstInAppMessage(fromPayload payload: [AnyHashable : Any], internalApi: IterableAPIInternal) -> IterableInAppMessage? {
334-
return getFirstMessageDict(fromPayload: payload)
335-
.map { parseInApp(fromDict: $0) }
336-
.flatMap { toMessage(fromInAppParseResult: $0, internalApi: internalApi) }
337-
}
338-
339320
private static func parseInApps(fromPayload payload: [AnyHashable : Any]) -> [InAppParseResult] {
340321
return getInAppDicts(fromPayload: payload).map {
341322
parseInApp(fromDict: $0)

swift-sdk/Internal/IterableAPIInternal.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -392,18 +392,6 @@ final class IterableAPIInternal : NSObject, PushTrackerProtocol {
392392
}
393393
}
394394

395-
@discardableResult func spawn(inAppNotification callbackBlock:ITEActionBlock?) -> Future<Bool> {
396-
let promise = Promise<Bool>()
397-
398-
DispatchQueue.main.async {
399-
InAppHelper.spawn(inAppNotification: callbackBlock, internalApi: self).onSuccess {
400-
promise.resolve(with: $0)
401-
}
402-
}
403-
404-
return promise
405-
}
406-
407395
@discardableResult func getInAppMessages(_ count: NSNumber) -> Future<SendRequestValue> {
408396
return getInAppMessages(count, onSuccess: IterableAPIInternal.defaultOnSucess(identifier: "getMessages"), onFailure: IterableAPIInternal.defaultOnFailure(identifier: "getMessages"))
409397
}

swift-sdk/IterableAPI.swift

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -358,40 +358,29 @@ public final class IterableAPI : NSObject {
358358
}
359359

360360
//MARK: In-App Notifications
361-
362-
/**
363-
Deprecated. Gets the list of InAppNotification and displays the next notification.
364-
365-
This is deprecated in SDK version 6.0.4.
366-
InApp notifications are automatically shown via `IterableInAppDelegate` methods.
367-
368-
- parameter callbackBlock: Callback ITEActionBlock
369-
370-
*/
371-
@available(*, deprecated: 6.0.4, message: "InApp messages are automatically shown via IterableInAppDelegate methods.")
361+
@available(*, unavailable, message: "In-app messages are automatically shown by SDK now. Please check our migration guide here https://github.com/iterable/swift-sdk/#migrating-in-app-messages-from-the-previous-version-of-the-sdk.")
372362
public static func spawnInAppNotification(_ callbackBlock:ITEActionBlock?) {
373-
internalImplementation?.spawn(inAppNotification: callbackBlock)
374363
}
375-
364+
376365
/**
377366
Deprecated. Gets the list of InAppMessages from the server.
378367

379-
This is deprecated in SDK version 6.0.4.
380-
InApp notifications are automatically shown via `IterableInAppDelegate` methods. The SDK takes care of getting messages automatically.
368+
This is deprecated in SDK version 6.1.0.
369+
In-App notifications are automatically shown via `IterableInAppDelegate` methods. The SDK takes care of getting messages automatically.
381370
See `IterableAPI.inAppManager.getMessages()` method to get messages already fetched from the server.
382371

383372
- parameter count: the number of messages to fetch
384373
*/
385-
@available(*, deprecated: 6.0.4, message: "Use IterableAPI.inAppManager.getMessages() method instead.")
374+
@available(*, deprecated: 6.1.0, message: "Use IterableAPI.inAppManager.getMessages() method instead.")
386375
@objc(getInAppMessages:) public static func get(inAppMessages count: NSNumber) {
387376
internalImplementation?.getInAppMessages(count)
388377
}
389378

390379
/**
391380
Deprecated. Gets the list of InAppMessages with optional additional fields and custom completion blocks
392381

393-
This is deprecated in SDK version 6.0.4.
394-
InApp notifications are automatically shown via `IterableInAppDelegate` methods. The SDK takes care of getting messages automatically.
382+
This is deprecated in SDK version 6.1.0.
383+
In-App notifications are automatically shown via `IterableInAppDelegate` methods. The SDK takes care of getting messages automatically.
395384
See `IterableAPI.inAppManager.getMessages()` method to get messages already fetched from the server.
396385

397386
- Parameters:
@@ -402,7 +391,7 @@ public final class IterableAPI : NSObject {
402391
- seeAlso: OnSuccessHandler
403392
- seeAlso: OnFailureHandler
404393
*/
405-
@available(*, deprecated: 6.0.4, message: "Use IterableAPI.inAppManager.getMessages() method instead.")
394+
@available(*, deprecated: 6.1.0, message: "Use IterableAPI.inAppManager.getMessages() method instead.")
406395
@objc(getInAppMessages:onSucess:onFailure:) public static func get(inAppMessages count: NSNumber, onSuccess: OnSuccessHandler?, onFailure: OnFailureHandler?) {
407396
internalImplementation?.getInAppMessages(count, onSuccess: onSuccess, onFailure: onFailure)
408397
}

0 commit comments

Comments
 (0)