pull/74/head
Niels Andriesse 5 years ago
parent f15fdcd128
commit 86a9e6534e

@ -518,7 +518,6 @@
768A1A2B17FC9CD300E00ED8 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 768A1A2A17FC9CD300E00ED8 /* libz.dylib */; };
76C87F19181EFCE600C4ACAB /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 76C87F18181EFCE600C4ACAB /* MediaPlayer.framework */; };
76EB054018170B33006006FC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB03C318170B33006006FC /* AppDelegate.m */; };
7B53C4F0239E038C008DF635 /* PushNotificationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B53C4EF239E038C008DF635 /* PushNotificationManager.swift */; };
954AEE6A1DF33E01002E5410 /* ContactsPickerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954AEE681DF33D32002E5410 /* ContactsPickerTest.swift */; };
A10FDF79184FB4BB007FF963 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 76C87F18181EFCE600C4ACAB /* MediaPlayer.framework */; };
A11CD70D17FA230600A2D1B1 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A11CD70C17FA230600A2D1B1 /* QuartzCore.framework */; };
@ -1334,7 +1333,6 @@
76C87F18181EFCE600C4ACAB /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; };
76EB03C218170B33006006FC /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
76EB03C318170B33006006FC /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
7B53C4EF239E038C008DF635 /* PushNotificationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PushNotificationManager.swift; sourceTree = "<group>"; };
8981C8F64D94D3C52EB67A2C /* Pods-SignalTests.test.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalTests.test.xcconfig"; path = "Pods/Target Support Files/Pods-SignalTests/Pods-SignalTests.test.xcconfig"; sourceTree = "<group>"; };
8EEE74B0753448C085B48721 /* Pods-SignalMessaging.app store release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalMessaging.app store release.xcconfig"; path = "Pods/Target Support Files/Pods-SignalMessaging/Pods-SignalMessaging.app store release.xcconfig"; sourceTree = "<group>"; };
948239851C08032C842937CC /* Pods-SignalMessaging.test.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalMessaging.test.xcconfig"; path = "Pods/Target Support Files/Pods-SignalMessaging/Pods-SignalMessaging.test.xcconfig"; sourceTree = "<group>"; };
@ -2578,14 +2576,6 @@
path = views;
sourceTree = "<group>";
};
7B53C4EE239E0343008DF635 /* PushNotification */ = {
isa = PBXGroup;
children = (
7B53C4EF239E038C008DF635 /* PushNotificationManager.swift */,
);
path = PushNotification;
sourceTree = "<group>";
};
9404664EC513585B05DF1350 /* Pods */ = {
isa = PBXGroup;
children = (
@ -2713,7 +2703,6 @@
B8439518228510E9000563FE /* Loki */ = {
isa = PBXGroup;
children = (
7B53C4EE239E0343008DF635 /* PushNotification */,
B8CCF63B239757C10091D419 /* Components */,
B8BFFF392355426100102A27 /* Messaging */,
B8BB82A3238F356800BA5194 /* Style Guide */,
@ -4020,7 +4009,6 @@
34277A5E20751BDC006049F2 /* OWSQuotedMessageView.m in Sources */,
458DE9D61DEE3FD00071BB03 /* PeerConnectionClient.swift in Sources */,
45DDA6242090CEB500DE97F8 /* ConversationHeaderView.swift in Sources */,
7B53C4F0239E038C008DF635 /* PushNotificationManager.swift in Sources */,
B82B4090239DD75000A248E7 /* RestoreVC.swift in Sources */,
3488F9362191CC4000E524CC /* ConversationMediaView.swift in Sources */,
45F32C242057297A00A300D5 /* MessageDetailViewController.swift in Sources */,

@ -592,7 +592,7 @@ static NSTimeInterval launchStartedAt;
}
OWSLogInfo(@"registered vanilla push token");
[[LKPushNotificationManager sharedInstance] registerNotificationWithToken:deviceToken];
[LKPushNotificationManager.shared registerWithToken:deviceToken];
[self.pushRegistrationManager didReceiveVanillaPushToken:deviceToken];
}
@ -1096,16 +1096,13 @@ static NSTimeInterval launchStartedAt;
return;
}
//deal with remote notification
//fetch data
NSLog(@"Receive remote notification!");
[LKLogger print:@"[Loki] Silent push notification received; fetching messages."];
__block AnyPromise *job = [AppEnvironment.shared.messageFetcherJob run].then(^{
job = nil;
}).catch(^{
job = nil;
});
[job retainUntilComplete];
}
- (void)application:(UIApplication *)application
@ -1122,9 +1119,7 @@ static NSTimeInterval launchStartedAt;
return;
}
//deal with remote notification
//fetch data
NSLog(@"Receive remote notification!");
[LKLogger print:@"[Loki] Silent push notification received; fetching messages."];
__block AnyPromise *job = [AppEnvironment.shared.messageFetcherJob run].then(^{
completionHandler(UIBackgroundFetchResultNewData);
job = nil;
@ -1133,7 +1128,6 @@ static NSTimeInterval launchStartedAt;
job = nil;
});
[job retainUntilComplete];
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {

@ -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?
}

@ -172,7 +172,7 @@ NS_ASSUME_NONNULL_BEGIN
[AppEnvironment.shared.notificationPresenter clearAllNotifications];
[DebugLogger.sharedLogger wipeLogs];
if(onReset != nil) { onReset(); }
if (onReset != nil) { onReset(); }
exit(0);
}

@ -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…
Cancel
Save