The iOS SDK for ChatSecure-Push-Server.
pod 'ChatSecure-Push-iOS', :git => 'https://github.com/ChatSecure/ChatSecure-Push-iOS'
If it's the first launch and there is no account.
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.
let client = Client(baseUrl: NSURL(string: urlString)!, urlSessionConfiguration: NSURLSessionConfiguration.defaultSessionConfiguration(), account: account)
client.registerNewUser(username, password: password, email: nil, completion: { (account, error) -> Void in
//Save account here
})
In order to register a new device first get an APNS token.
var settings = UIUserNotificationSettings(forTypes: (UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert), categories: nil)
application.registerUserNotificationSettings(settings)
Once you've recieved the token in the AppDelegate
.
self.client.registerDevice(apnsToken, name: "New device name", deviceID: nil, completion: { (device, error) -> Void in
//Save device here
})
self.client.createToken(apnsToken, name: "New token", completion: { (token, error) -> Void in
//Save and send to 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.
var message = Message(token: token, data: nil)
self.client.sendMessage(message, completion: { (msg, error) -> Void in
println("Message: \(msg)")
})