diff --git a/swift-sdk.xcodeproj/xcshareddata/xcschemes/swift-sdk.xcscheme b/swift-sdk.xcodeproj/xcshareddata/xcschemes/swift-sdk.xcscheme index a1714130..f990bb92 100644 --- a/swift-sdk.xcodeproj/xcshareddata/xcschemes/swift-sdk.xcscheme +++ b/swift-sdk.xcodeproj/xcshareddata/xcschemes/swift-sdk.xcscheme @@ -80,8 +80,8 @@ diff --git a/swift-sdk/Internal/in-app/InAppMessageParser.swift b/swift-sdk/Internal/in-app/InAppMessageParser.swift index 220f2cff..3ae6194c 100644 --- a/swift-sdk/Internal/in-app/InAppMessageParser.swift +++ b/swift-sdk/Internal/in-app/InAppMessageParser.swift @@ -82,7 +82,11 @@ struct InAppMessageParser { } let jsonOnly = (json[JsonKey.InApp.jsonOnly] as? Int ?? 0) == 1 - let customPayload = parseCustomPayload(fromPayload: json) + var customPayload = parseCustomPayload(fromPayload: json) + + if jsonOnly && customPayload == nil { + customPayload = [:] + } // For non-JSON-only messages, we require content if !jsonOnly { diff --git a/swift-sdk/Internal/in-app/InAppPersistence.swift b/swift-sdk/Internal/in-app/InAppPersistence.swift index 9d42e973..1222cfd7 100644 --- a/swift-sdk/Internal/in-app/InAppPersistence.swift +++ b/swift-sdk/Internal/in-app/InAppPersistence.swift @@ -255,16 +255,10 @@ extension IterableInAppMessage: Codable { let jsonOnly = (try? container.decode(Int.self, forKey: .jsonOnly)) ?? 0 let customPayloadData = try? container.decode(Data.self, forKey: .customPayload) - let customPayload = IterableInAppMessage.deserializeCustomPayload(withData: customPayloadData) + var customPayload = IterableInAppMessage.deserializeCustomPayload(withData: customPayloadData) - // For JSON-only messages, require customPayload if jsonOnly == 1 && customPayload == nil { - ITBError("JSON-only message requires customPayload") - self.init(messageId: "", - campaignId: 0, - content: IterableInAppMessage.createDefaultContent(), - jsonOnly: false) - return + customPayload = [:] } let saveToInbox = (try? container.decode(Bool.self, forKey: .saveToInbox)) ?? false diff --git a/tests/unit-tests/InAppTests.swift b/tests/unit-tests/InAppTests.swift index 318ea6a1..1bd2f310 100644 --- a/tests/unit-tests/InAppTests.swift +++ b/tests/unit-tests/InAppTests.swift @@ -1671,7 +1671,7 @@ class InAppTests: XCTestCase { XCTAssertEqual(messages.count, 1) let message = messages[0] - XCTAssertTrue(message.customPayload == nil) + XCTAssertTrue(message.customPayload?.isEmpty ?? false) expectation1.fulfill() }