Skip to content

Commit

Permalink
[MOB-9233] Updated code according to the new discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
sumeruchat committed Jan 8, 2025
1 parent df6a01d commit cc760f3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions swift-sdk.xcodeproj/xcshareddata/xcschemes/swift-sdk.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES"
onlyGenerateCoverageForSpecifiedTargets = "YES">
Expand Down
6 changes: 5 additions & 1 deletion swift-sdk/Internal/in-app/InAppMessageParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 2 additions & 8 deletions swift-sdk/Internal/in-app/InAppPersistence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-tests/InAppTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit cc760f3

Please sign in to comment.