mirror of https://github.com/oxen-io/session-ios
Add function to send the device token to our server.
Fetch data when receiving a silent notification.pull/72/head
parent
e1373b7fd9
commit
268d3018c2
@ -0,0 +1,48 @@
|
||||
//
|
||||
// Copyright (c) 2018 Loki Messenger. All rights reserved.
|
||||
// This file is for silent push notification
|
||||
// Created by Ryan Zhao
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
@objc(LKPushNotificationManager)
|
||||
class PushNotificationManager: NSObject {
|
||||
|
||||
static let shared = PushNotificationManager()
|
||||
|
||||
private override init() {
|
||||
super.init()
|
||||
}
|
||||
|
||||
@objc
|
||||
class func sharedInstance() -> PushNotificationManager {
|
||||
return PushNotificationManager.shared
|
||||
}
|
||||
|
||||
@objc
|
||||
func registerNotification(token: Data) {
|
||||
let deviceToken = token.map { String(format: "%02.2hhx", $0) }.joined()
|
||||
print("Device Token: (\(deviceToken))")
|
||||
/** send token to Loki centralized server **/
|
||||
let parameters = [ "token" : deviceToken ]
|
||||
let url = URL(string: "http://88.99.14.72:5000/register")!
|
||||
let request = TSRequest(url: url, method: "POST", parameters: parameters)
|
||||
request.allHTTPHeaderFields = [ "Content-Type" : "application/json"]
|
||||
TSNetworkManager.shared().makeRequest(
|
||||
request,
|
||||
success: { (_, response: Any?) -> Void in
|
||||
if let responseDictionary = response as? [String: Any] {
|
||||
if responseDictionary["code"] as? Int == 0 {
|
||||
print("[Loki] error occured during sending device token \(String(describing: responseDictionary["message"] as? String))")
|
||||
}
|
||||
}
|
||||
},
|
||||
failure: { (_, error: Error?) -> Void in
|
||||
print("[Loki] Couldn't send the device token to the centralized server")
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: Move the fetch message fucntion here?
|
||||
|
||||
}
|
Loading…
Reference in New Issue