Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
daf8e39813 | ||
|
7764f5dd34 | ||
|
588ccc4ac0 | ||
|
86f9ee4ff8 | ||
|
4eb1e7f398 | ||
|
33a1a8ebe7 |
@ -1,12 +1,12 @@
|
|||||||
// swift-tools-version: 5.5
|
// swift-tools-version: 5.6
|
||||||
|
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "PushMessageDefinitions",
|
name: "PushMessageDefinitions",
|
||||||
platforms: [
|
platforms: [
|
||||||
.macOS(.v10_15),
|
.macOS(.v12),
|
||||||
.iOS(.v13)
|
.iOS(.v15)
|
||||||
],
|
],
|
||||||
products: [
|
products: [
|
||||||
.library(
|
.library(
|
||||||
@ -14,11 +14,15 @@ let package = Package(
|
|||||||
targets: ["PushMessageDefinitions"]),
|
targets: ["PushMessageDefinitions"]),
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/swift-server-community/APNSwift.git", from: "4.0.0"),
|
.package(url: "https://github.com/swift-server-community/APNSwift.git", from: "5.0.0-alpha.4"),
|
||||||
|
.package(url: "https://github.com/christophhagen/BinaryCodable.git", from: "1.0.0"),
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
.target(
|
.target(
|
||||||
name: "PushMessageDefinitions",
|
name: "PushMessageDefinitions",
|
||||||
dependencies: [.product(name: "APNSwift", package: "APNSwift")])
|
dependencies: [
|
||||||
|
.product(name: "APNSwift", package: "APNSwift"),
|
||||||
|
.product(name: "BinaryCodable", package: "BinaryCodable"),
|
||||||
|
])
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -15,7 +15,7 @@ public struct PushMessage: Codable {
|
|||||||
/**
|
/**
|
||||||
The notification content.
|
The notification content.
|
||||||
*/
|
*/
|
||||||
public let payload: APNSwiftPayload
|
public let payload: APNSPayload
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The value of this header must accurately reflect the contents of your notification’s payload.
|
The value of this header must accurately reflect the contents of your notification’s payload.
|
||||||
@ -23,7 +23,7 @@ public struct PushMessage: Codable {
|
|||||||
If there’s a mismatch, or if the header is missing on required systems, APNs may return an error, delay the delivery of the notification, or drop it altogether.
|
If there’s a mismatch, or if the header is missing on required systems, APNs may return an error, delay the delivery of the notification, or drop it altogether.
|
||||||
- Note: Required for watchOS 6 and later; recommended for macOS, iOS, tvOS, and iPadOS
|
- Note: Required for watchOS 6 and later; recommended for macOS, iOS, tvOS, and iPadOS
|
||||||
*/
|
*/
|
||||||
public let pushType: APNSwiftConnection.PushType
|
public let pushType: APNSClient.PushType
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The date at which the notification is no longer valid.
|
The date at which the notification is no longer valid.
|
||||||
@ -61,8 +61,8 @@ public struct PushMessage: Codable {
|
|||||||
- Parameter collapseIdentifier: An optional identifier to group push notifications
|
- Parameter collapseIdentifier: An optional identifier to group push notifications
|
||||||
*/
|
*/
|
||||||
public init(recipients: [PushToken],
|
public init(recipients: [PushToken],
|
||||||
payload: APNSwiftPayload,
|
payload: APNSPayload,
|
||||||
pushType: APNSwiftConnection.PushType,
|
pushType: APNSClient.PushType,
|
||||||
expiration: Date? = nil,
|
expiration: Date? = nil,
|
||||||
lowPriority: Bool = false,
|
lowPriority: Bool = false,
|
||||||
collapseIdentifier: String? = nil) {
|
collapseIdentifier: String? = nil) {
|
||||||
@ -75,11 +75,63 @@ public struct PushMessage: Codable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension APNSwiftConnection.PushType: Codable {
|
extension APNSClient.PushType: Codable {
|
||||||
|
|
||||||
|
struct PushTypeDecodingError: Error {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension APNSwiftConnection.PushType {
|
|
||||||
|
public func encode(to encoder: Encoder) throws {
|
||||||
|
var container = encoder.singleValueContainer()
|
||||||
|
try container.encode(rawValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
public init(from decoder: Decoder) throws {
|
||||||
|
let container = try decoder.singleValueContainer()
|
||||||
|
let raw = try container.decode(UInt8.self)
|
||||||
|
|
||||||
|
switch raw {
|
||||||
|
case 1:
|
||||||
|
self = .alert
|
||||||
|
case 2:
|
||||||
|
self = .background
|
||||||
|
case 3:
|
||||||
|
self = .mdm
|
||||||
|
case 4:
|
||||||
|
self = .voip
|
||||||
|
case 5:
|
||||||
|
self = .fileprovider
|
||||||
|
case 6:
|
||||||
|
self = .complication
|
||||||
|
default:
|
||||||
|
throw PushTypeDecodingError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var rawValue: UInt8 {
|
||||||
|
switch self {
|
||||||
|
case .alert:
|
||||||
|
return 1
|
||||||
|
case .background:
|
||||||
|
return 2
|
||||||
|
case .mdm:
|
||||||
|
return 3
|
||||||
|
case .voip:
|
||||||
|
return 4
|
||||||
|
case .fileprovider:
|
||||||
|
return 5
|
||||||
|
case .complication:
|
||||||
|
return 6
|
||||||
|
//case .location:
|
||||||
|
// return ".location-query"
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension APNSClient.PushType {
|
||||||
|
|
||||||
/// The extension to add to the push topic depending on the notification type
|
/// The extension to add to the push topic depending on the notification type
|
||||||
public var topicExtension: String {
|
public var topicExtension: String {
|
||||||
@ -94,8 +146,11 @@ extension APNSwiftConnection.PushType {
|
|||||||
return ".pushkit.fileprovider"
|
return ".pushkit.fileprovider"
|
||||||
//case .location:
|
//case .location:
|
||||||
// return ".location-query"
|
// return ".location-query"
|
||||||
//case .complication:
|
case .complication:
|
||||||
// return ".complication"
|
return ".complication"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user