Skip to content

Commit c5b6aaf

Browse files
authored
Fix crash when using AnyEncodable payload for alert and background notifications (#200)
fix: encoder issue
1 parent c84a4c7 commit c5b6aaf

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

Sources/APNSCore/Alert/APNSAlertNotification.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,10 @@ public struct APNSAlertNotification<Payload: Encodable & Sendable>: APNSMessage,
212212
}
213213

214214
public func encode(to encoder: Encoder) throws {
215-
var container = encoder.container(keyedBy: CodingKeys.self)
216-
217215
// First we encode the user payload since this might use the `aps` key
218216
// and we override it afterward.
219217
try self.payload.encode(to: encoder)
218+
var container = encoder.container(keyedBy: CodingKeys.self)
220219
try container.encode(self.aps, forKey: .aps)
221220
}
222221
}

Sources/APNSCore/Background/APNSBackgroundNotification.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ public struct APNSBackgroundNotification<Payload: Encodable & Sendable>: APNSMes
8686

8787
@inlinable
8888
public func encode(to encoder: Encoder) throws {
89-
var container = encoder.container(keyedBy: CodingKeys.self)
90-
9189
// First we encode the user payload since this might use the `aps` key
9290
// and we override it afterward.
9391
try self.payload.encode(to: encoder)
92+
var container = encoder.container(keyedBy: CodingKeys.self)
9493
try container.encode(self.aps, forKey: .aps)
9594
}
9695
}

0 commit comments

Comments
 (0)