https://github.com/hagmas/apnskit
A framework to send Apple Notifications
https://github.com/hagmas/apnskit
apns notification-service playground swift
Last synced: 7 months ago
JSON representation
A framework to send Apple Notifications
- Host: GitHub
- URL: https://github.com/hagmas/apnskit
- Owner: hagmas
- License: mit
- Created: 2017-03-20T08:21:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-19T02:23:36.000Z (about 8 years ago)
- Last Synced: 2025-02-28T05:56:05.016Z (7 months ago)
- Topics: apns, notification-service, playground, swift
- Language: Swift
- Homepage:
- Size: 21.5 KB
- Stars: 23
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# APNsKit
A framework to send Apple notifications.[](https://github.com/Carthage/Carthage)
## About APNsKit
APNsKit is a swift framework to send Apple notifications to iOS devices. Especially, with Playground it lets you to create interactive tool to send push notifications for debugging purposes. Check out the Playground `PushViewController.playground` bundled with the Workspace.
## Usage
```swift
import APNsKit// Setting header fields is optional. Refer (#1) for configurable header fields of APNs request.
let header = APNsRequest.Header(priority: .p10, topic: "<#The topic of the remote notification#>")// Create a APNs payload. See Apple's Payload Key Reference (#2) for its specifications.
let payload = APNsPayload(title: "Hello World!", body: "This is APNsKit.", contentAvailable: 1)
let request = APNsRequest(port: .p2197,
server: .development,
deviceToken: "<#The target device token#>",
header: header,
payload: payload)// Create a connection that wraps up URLSession and its authentication challenges.
if let connection = try? Connection(p12FileName: "<#Your p12 file name#>", passPhrase: "<#The pass phrase for the file#>") {
// Send the request to the APNs server. The connection has to be retained until the server responses.
connection.send(request: request, resultHandler: { result in
switch result {
case .success:
print("Succeeded!")
case .failure(let code, let message):
print("Failed to send: \(code), \(message)")
}
})
}
```
#1 [HTTP/2 Request to APNs](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html#//apple_ref/doc/uid/TP40008194-CH11-SW11)#2 [Apple's Payload Key Reference](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW1)
## Requirements
* Xcode 8.2.1
* Swift 3.0## Installation
* APNsKit doesn't include any external depenancies.
* APNsKit currently supports only Carthage.
### [Carthage](https://github.com/Carthage/Carthage)**Tested with `carthage version`: `0.20.1`**
Add this to `Cartfile`
```
github "hagmas/APNsKit"
``````bash
$ carthage update
```