Skip to content

Commit

Permalink
Fix crash when using AnyEncodable payload for alert and background no…
Browse files Browse the repository at this point in the history
…tifications (#200)

fix: encoder issue
  • Loading branch information
grighakobian authored Jul 4, 2024
1 parent c84a4c7 commit c5b6aaf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Sources/APNSCore/Alert/APNSAlertNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,10 @@ public struct APNSAlertNotification<Payload: Encodable & Sendable>: APNSMessage,
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

// First we encode the user payload since this might use the `aps` key
// and we override it afterward.
try self.payload.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.aps, forKey: .aps)
}
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/APNSCore/Background/APNSBackgroundNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ public struct APNSBackgroundNotification<Payload: Encodable & Sendable>: APNSMes

@inlinable
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

// First we encode the user payload since this might use the `aps` key
// and we override it afterward.
try self.payload.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.aps, forKey: .aps)
}
}
Expand Down

0 comments on commit c5b6aaf

Please sign in to comment.