-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add support for push trigger deep links
- Loading branch information
Showing
5 changed files
with
112 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// PushRequest.swift | ||
// AppcuesKit | ||
// | ||
// Created by Matt on 2024-03-18. | ||
// Copyright © 2024 Appcues. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
internal struct PushRequest { | ||
let deviceID: String | ||
let additionalData: [String: Any] | ||
|
||
init(deviceID: String, queryItems: [URLQueryItem] = []) { | ||
self.deviceID = deviceID | ||
self.additionalData = queryItems.reduce(into: [:]) { result, item in | ||
if let value = item.value { | ||
result[item.name] = value | ||
} | ||
} | ||
} | ||
} | ||
|
||
extension PushRequest: Encodable { | ||
enum CodingKeys: String, CodingKey { | ||
case deviceID = "device_id" | ||
} | ||
|
||
func encode(to encoder: Encoder) throws { | ||
var dynamicContainer = encoder.container(keyedBy: DynamicCodingKeys.self) | ||
try dynamicContainer.encodeSkippingInvalid(additionalData) | ||
|
||
// Encode device_id last just to ensure it wins in case the query items have the same key | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(self.deviceID, forKey: .deviceID) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters