Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mono0926/apns
APNs(Apple Push Notification Service) SDK
https://github.com/mono0926/apns
apns apns-http apns-http2 apns-sender apns2 codable macos notification notification-service notifications push-notifications remote-notifications swift4 swiftpm
Last synced: 12 days ago
JSON representation
APNs(Apple Push Notification Service) SDK
- Host: GitHub
- URL: https://github.com/mono0926/apns
- Owner: mono0926
- License: mit
- Created: 2017-08-07T10:19:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-11-02T11:30:21.000Z (about 2 months ago)
- Last Synced: 2024-11-30T18:51:53.577Z (22 days ago)
- Topics: apns, apns-http, apns-http2, apns-sender, apns2, codable, macos, notification, notification-service, notifications, push-notifications, remote-notifications, swift4, swiftpm
- Language: Swift
- Homepage: https://medium.com/swift-column/apns-fbd547c5919
- Size: 20.5 KB
- Stars: 27
- Watchers: 3
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# APNS
## `APNS` initialization
There are two ways to initialize `APNS` instance.
- By code.
- Locate [Config.plist](https://github.com/mono0926/apns/blob/master/Config.plist).## Example
```swift
class APNSTests: XCTestCase {
var target: APNS!
private let deviceToken: DeviceToken = "0c34a62170c1c0be603780e6458b20dc902730094805b87bef896e6f5ed9bbcb"func testSend_Code() throws {
// Initialize from the config file
target = try APNS(configPath: "/Users/mono/Documents/Config.plist")// Or from each argument
// target = try APNS(keyPath: "YOUR_p8_KEY_PATH",
// keyId: "YOUR_KEY_ID",
// teamId: "YOUR_TEAM_ID",
// environment: .sandbox, .production or .all) // environmentは省略可能// All fields can be omitted
let alert = Alert(title: "title",
subtitle: "subtitle",
body: "body",
titleLocalizationKey: nil,
titleLocalizationArguments: nil,
actionLocalizationKey: nil,
bodyLocalizationKey: nil,
bodyLocalizationArguments: nil,
launchImage: nil)
let aps = Aps(alert: alert,
badge: nil, // Can be omitted below
sound: "Default",
contentAvailable: nil,
category: nil,
threadId: nil)
let payload = Payload(aps: aps,
custom: Custom(test: "custom-value")) // Can be omitted
let request = APNSRequest(topic: "com.mono0926.notification.example",
payload: payload,
apnsIdentifier: UUID(), // Can be omitted below
priority: .immediately,
expiration: Date().addingTimeInterval(3600),
collapseIdentifier: "collapse-identifier")
let results = try target.send(request: request,
deviceTokens: [deviceToken])
results.forEach { print($0) }
}func testSend_JSON() throws {
target = try APNS(configPath: "/Users/mono/Documents/Config.plist")let payload = Payload(aps: try Aps(jsonPath: "/Users/mono/Documents/aps.json"),
custom: try Custom(jsonPath: "/Users/mono/Documents/custom.json"))let request = APNSRequest(topic: "com.mono0926.notification.example",
payload: payload)let results = try target.send(request: request,
deviceTokens: [deviceToken])
results.forEach { print($0) }
}
}struct Custom: Codable, CustomPayload {
let test: String
}
```