Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when using AnyEncodable payload for alert and background notifications #200

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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