|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the APNSwift open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2020 the APNSwift project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of APNSwift project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +/// This structure provides the data structure for an APNS Alert |
| 16 | +public struct APNSwiftAlert: Codable { |
| 17 | + public let title: String? |
| 18 | + public let subtitle: String? |
| 19 | + public let body: String? |
| 20 | + public let titleLocKey: String? |
| 21 | + public let titleLocArgs: [String]? |
| 22 | + public let actionLocKey: String? |
| 23 | + public let locKey: String? |
| 24 | + public let locArgs: [String]? |
| 25 | + public let launchImage: String? |
| 26 | + |
| 27 | + /** |
| 28 | + This structure provides the data structure for an APNS Alert |
| 29 | + - Parameter title: The title to be displayed to the user. |
| 30 | + - Parameter subtitle: The subtitle to be displayed to the user. |
| 31 | + - Parameter body: The body of the push notification. |
| 32 | + - Parameter titleLocKey: The key to a title string in the Localizable.strings file for the current |
| 33 | + localization. |
| 34 | + - Parameter titleLocArgs: Variable string values to appear in place of the format specifiers in |
| 35 | + title-loc-key. |
| 36 | + - Parameter actionLocKey: The string is used as a key to get a localized string in the current localization |
| 37 | + to use for the right button’s title instead of “View”. |
| 38 | + - Parameter locKey: A key to an alert-message string in a Localizable.strings file for the current |
| 39 | + localization (which is set by the user’s language preference). |
| 40 | + - Parameter locArgs: Variable string values to appear in place of the format specifiers in loc-key. |
| 41 | + - Parameter launchImage: The filename of an image file in the app bundle, with or without the filename |
| 42 | + extension. |
| 43 | + |
| 44 | + For more information see: |
| 45 | + [Payload Key Reference](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#) |
| 46 | + ### Usage Example: ### |
| 47 | + ```` |
| 48 | + let alert = Alert(title: "Hey There", subtitle: "Subtitle", body: "Body") |
| 49 | + ```` |
| 50 | + */ |
| 51 | + public init(title: String? = nil, subtitle: String? = nil, body: String? = nil, |
| 52 | + titleLocKey: String? = nil, titleLocArgs: [String]? = nil, actionLocKey: String? = nil, |
| 53 | + locKey: String? = nil, locArgs: [String]? = nil, launchImage: String? = nil) { |
| 54 | + self.title = title |
| 55 | + self.subtitle = subtitle |
| 56 | + self.body = body |
| 57 | + self.titleLocKey = titleLocKey |
| 58 | + self.titleLocArgs = titleLocArgs |
| 59 | + self.actionLocKey = actionLocKey |
| 60 | + self.locKey = locKey |
| 61 | + self.locArgs = locArgs |
| 62 | + self.launchImage = launchImage |
| 63 | + } |
| 64 | + |
| 65 | + enum CodingKeys: String, CodingKey { |
| 66 | + case title |
| 67 | + case subtitle |
| 68 | + case body |
| 69 | + case titleLocKey = "title-loc-key" |
| 70 | + case titleLocArgs = "title-loc-args" |
| 71 | + case actionLocKey = "action-loc-key" |
| 72 | + case locKey = "loc-key" |
| 73 | + case locArgs = "loc-args" |
| 74 | + case launchImage = "launch-image" |
| 75 | + } |
| 76 | +} |
0 commit comments