Skip to content

Commit 3215ac4

Browse files
Merge pull request #93 from Iterable/feature/mob-380-iterable-namespace-master
[MOB-380] iterable namespace fix for master
2 parents 1e06cb6 + b14b53f commit 3215ac4

File tree

2 files changed

+72
-7
lines changed

2 files changed

+72
-7
lines changed

Tests/swift-sdk-swift-tests/InAppTests.swift

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,26 @@ class InAppTests: XCTestCase {
362362

363363
wait(for: [expectation1, expectation2], timeout: testExpectationTimeout)
364364
}
365+
366+
func testShowInAppWithCustomActionBackwardCompatibility() {
367+
let customActionScheme = "itbl"
368+
let customActionName = "my_custom_action"
369+
let expectation1 = expectation(description: "verify custom action is called, customActionScheme: \(customActionScheme), customActionName: \(customActionName)")
370+
verifyCustomActionIsCalled(expectation: expectation1,
371+
customActionScheme: customActionScheme,
372+
customActionName: customActionName)
373+
wait(for: [expectation1], timeout: testExpectationTimeout)
374+
}
375+
376+
func testShowInAppWithCustomAction1() {
377+
let customActionScheme = "action"
378+
let customActionName = "my_custom_action"
379+
let expectation1 = expectation(description: "verify custom action is called, customActionScheme: \(customActionScheme), customActionName: \(customActionName)")
380+
verifyCustomActionIsCalled(expectation: expectation1,
381+
customActionScheme: customActionScheme,
382+
customActionName: customActionName)
383+
wait(for: [expectation1], timeout: testExpectationTimeout)
384+
}
365385

366386
// Check that onNew is called just once if the messageId is same.
367387
func testOnNewNotCalledMultipleTimes() {
@@ -1005,6 +1025,50 @@ class InAppTests: XCTestCase {
10051025

10061026
XCTAssertEqual(IterableAPI.inAppManager.getMessages().count, 0)
10071027
}
1028+
1029+
fileprivate func verifyCustomActionIsCalled(expectation: XCTestExpectation, customActionScheme: String, customActionName: String) {
1030+
let mockInAppSynchronizer = MockInAppSynchronizer()
1031+
1032+
let customActionUrl = "\(customActionScheme)://\(customActionName)"
1033+
let mockInAppDisplayer = MockInAppDisplayer()
1034+
mockInAppDisplayer.onShowCallback = {(_, _) in
1035+
mockInAppDisplayer.click(url: URL(string: customActionUrl)!)
1036+
}
1037+
1038+
let mockCustomActionDelegate = MockCustomActionDelegate(returnValue: true)
1039+
mockCustomActionDelegate.callback = {(actionName, context) in
1040+
XCTAssertEqual(actionName, customActionName)
1041+
expectation.fulfill()
1042+
}
1043+
1044+
let config = IterableConfig()
1045+
config.inAppDelegate = MockInAppDelegate(showInApp: .show)
1046+
config.customActionDelegate = mockCustomActionDelegate
1047+
1048+
IterableAPI.initializeForTesting(
1049+
config: config,
1050+
inAppSynchronizer: mockInAppSynchronizer,
1051+
inAppDisplayer: mockInAppDisplayer
1052+
)
1053+
1054+
let payload = """
1055+
{"inAppMessages":
1056+
[
1057+
{
1058+
"saveToInbox": true,
1059+
"content": {"contentType": "html", "inAppDisplaySettings": {"bottom": {"displayOption": "AutoExpand"}, "backgroundAlpha": 0.5, "left": {"percentage": 60}, "right": {"percentage": 60}, "top": {"displayOption": "AutoExpand"}}, "html": "<a href=\'\(customActionUrl)'>Click Here</a>"},
1060+
"trigger": {"type": "immediate"},
1061+
"messageId": "message0",
1062+
"campaignId": "campaign1",
1063+
"customPayload": {"title": "Product 1 Available", "date": "2018-11-14T14:00:00:00.32Z"}
1064+
},
1065+
]
1066+
}
1067+
""".toJsonDict()
1068+
1069+
mockInAppSynchronizer.mockInAppPayloadFromServer(payload)
1070+
}
1071+
10081072
}
10091073

10101074
extension IterableInAppTrigger {

swift-sdk/Internal/InAppHelper.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ struct InAppHelper {
254254

255255
enum InAppClickedUrl {
256256
case localResource(name: String) // applewebdata://abc-def/something => something
257-
case iterableCustomAction(name: String) // itbl://something => something
258-
case customAction(name: String) // action://something => something
257+
case iterableCustomAction(name: String) // iterable://something => something
258+
case customAction(name: String) // action:something => something or itbl://something => something
259259
case regularUrl(URL) // https://something => https://something
260260
}
261261

@@ -272,10 +272,10 @@ struct InAppHelper {
272272
return nil
273273
}
274274
return .localResource(name: urlPath)
275-
case .itbl:
276-
return .iterableCustomAction(name: dropScheme(urlString: url.absoluteString, scheme: UrlScheme.itbl.rawValue))
277-
case .action:
278-
return .customAction(name: dropScheme(urlString: url.absoluteString, scheme: UrlScheme.action.rawValue))
275+
case .iterable:
276+
return .iterableCustomAction(name: dropScheme(urlString: url.absoluteString, scheme: scheme.rawValue))
277+
case .action, .itbl:
278+
return .customAction(name: dropScheme(urlString: url.absoluteString, scheme: scheme.rawValue))
279279
case .other:
280280
return .regularUrl(url)
281281
}
@@ -472,8 +472,9 @@ struct InAppHelper {
472472

473473
private enum UrlScheme : String {
474474
case applewebdata = "applewebdata"
475-
case itbl = "itbl"
475+
case iterable = "iterable"
476476
case action = "action"
477+
case itbl = "itbl" // this is for backward compatibility and should be handled just like action://
477478
case other
478479

479480
fileprivate static func from(url: URL) -> UrlScheme? {

0 commit comments

Comments
 (0)