Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeffctown/apns
An APNS Model Library
https://github.com/jeffctown/apns
apns apple ios notifications push spm swift swift-package-manager watchos
Last synced: about 18 hours ago
JSON representation
An APNS Model Library
- Host: GitHub
- URL: https://github.com/jeffctown/apns
- Owner: jeffctown
- Created: 2020-01-10T10:09:14.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-13T12:26:41.000Z (about 4 years ago)
- Last Synced: 2025-01-15T19:49:42.276Z (13 days ago)
- Topics: apns, apple, ios, notifications, push, spm, swift, swift-package-manager, watchos
- Language: Swift
- Homepage:
- Size: 48.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# APNS
APNS is a simple Package to represent Apple Push Notification Service model objects.
![Platform](https://img.shields.io/badge/platforms-iOS%2013.0%20%7C%20macOS%2010.15%20%7C%20tvOS%2013.0%20%7C%20watchOS%206.0-blue.svg)
| Build Status
| --------------|
[![Travis CI](https://travis-ci.org/jeffctown/APNS.svg?branch=master)](https://travis-ci.org/jeffctown/APNS)## Integration
#### Swift Package Manager
You can use [The Swift Package Manager](https://swift.org/package-manager) to install `APNS` by adding the proper description to your `Package.swift` file:
```swift
// swift-tools-version:5.1
import PackageDescriptionlet package = Package(
name: "YOUR_PROJECT_NAME",
dependencies: [
.package(url: "https://github.com/jeffctown/APNS.git", from: "1.0.0"),
]
)
```## Usage
#### Encoding APNS Payloads
```swift
let payload = PayloadBuilder { builder in
builder.title = "APNS Title!"
builder.body = "Something Exciting Just Happened!"
}.build()
let data = try JSONEncoder().encode(payload)
```#### Decoding APNS Payloads
```swift
let payloadString = """
{
"aps" : {
"category" : "NEW_MESSAGE_CATEGORY",
"alert" : {
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY",
},
"content-available" : 1,
"badge" : 5,
"sound" : "bingbong.aiff",
"mutable-content": 1
}
}
"""
let payloadData = payloadString.data(using: .utf8)!
let payload = try JSONDecoder().decode(Payload.self, from: payloadData)
```