mirror of https://github.com/oxen-io/session-ios
Clean
parent
f15fdcd128
commit
86a9e6534e
@ -1,48 +0,0 @@
|
||||
//
|
||||
// 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?
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
import UIKit
|
||||
|
||||
@objc(LKPushNotificationManager)
|
||||
final class LokiPushNotificationManager : NSObject {
|
||||
|
||||
@objc static let shared = LokiPushNotificationManager()
|
||||
|
||||
private override init() { super.init() }
|
||||
|
||||
@objc(registerWithToken:)
|
||||
func register(with token: Data) {
|
||||
let hexEncodedToken = token.map { String(format: "%02.2hhx", $0) }.joined()
|
||||
print("Registering device token: (\(hexEncodedToken))")
|
||||
// Send token to Loki server
|
||||
let parameters = [ "token" : hexEncodedToken ]
|
||||
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 in
|
||||
guard let json = response as? JSON else { return }
|
||||
guard json["code"] as? Int != 0 else {
|
||||
return print("[Loki] An error occured during device token registration: \(json["message"] as? String ?? "nil").")
|
||||
}
|
||||
}, failure: { _, error in
|
||||
print("[Loki] Couldn't register device token.")
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue