https://github.com/chatsecure/chatsecure-push-ios
The iOS SDK for ChatSecure-Push-Server
https://github.com/chatsecure/chatsecure-push-ios
Last synced: 8 months ago
JSON representation
The iOS SDK for ChatSecure-Push-Server
- Host: GitHub
- URL: https://github.com/chatsecure/chatsecure-push-ios
- Owner: ChatSecure
- License: gpl-3.0
- Created: 2015-07-07T17:24:29.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-10-27T20:25:39.000Z (over 6 years ago)
- Last Synced: 2025-04-23T06:18:13.929Z (11 months ago)
- Language: Swift
- Size: 111 KB
- Stars: 16
- Watchers: 4
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ChatSecure-Push-iOS
The iOS SDK for [ChatSecure-Push-Server](https://github.com/ChatSecure/ChatSecure-Push-Server).
## Getting Started
### Install
```ruby
pod 'ChatSecure-Push-iOS', :git => 'https://github.com/ChatSecure/ChatSecure-Push-iOS'
```
### Usage
### 1. Setup
If it's the first launch and there is no account.
```swift
let client = Client(baseUrl: NSURL(string: urlString)!, urlSessionConfiguration: NSURLSessionConfiguration.defaultSessionConfiguration(), account: nil)
```
Or if you already have an account. You'll need to store the `username` and `token` to make API requests.
```swfit
let client = Client(baseUrl: NSURL(string: urlString)!, urlSessionConfiguration: NSURLSessionConfiguration.defaultSessionConfiguration(), account: account)
```
### 2. Create account
```swift
client.registerNewUser(username, password: password, email: nil, completion: { (account, error) -> Void in
//Save account here
})
```
### 3. Register new device
In order to register a new device first get an APNS token.
```swift
var settings = UIUserNotificationSettings(forTypes: (UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert), categories: nil)
application.registerUserNotificationSettings(settings)
```
Once you've recieved the token in the `AppDelegate`.
```swift
self.client.registerDevice(apnsToken, name: "New device name", deviceID: nil, completion: { (device, error) -> Void in
//Save device here
})
```
### 4. Get whitelist token to hand out to a friend
```swift
self.client.createToken(apnsToken, name: "New token", completion: { (token, error) -> Void in
//Save and send to friend
})
```
### 5. Send a push message to a friend
Once you receive a `token` from a friend you can send them a push message.
`data` needs to be a dictionary that is serializable to JSON.
```swift
var message = Message(token: token, data: nil)
self.client.sendMessage(message, completion: { (msg, error) -> Void in
println("Message: \(msg)")
})
```