mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Merge pull request #87 from RyanRory/push-notification-fix
Fix Push Notifications
This commit is contained in:
commit
d967724348
4 changed files with 10 additions and 3 deletions
|
@ -580,7 +580,7 @@ static NSTimeInterval launchStartedAt;
|
|||
|
||||
OWSLogInfo(@"Registered for push notifications with token: %@.", deviceToken);
|
||||
[LKPushNotificationManager.shared registerWithToken:deviceToken];
|
||||
[self.pushRegistrationManager didReceiveVanillaPushToken:deviceToken];
|
||||
// [self.pushRegistrationManager didReceiveVanillaPushToken:deviceToken];
|
||||
}
|
||||
|
||||
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
|
||||
|
|
|
@ -230,6 +230,8 @@ public class MessageFetcherJob: NSObject {
|
|||
request = OWSRequestFactory.acknowledgeMessageDeliveryRequest(withServerGuid: serverGuid)
|
||||
} else if let source = envelope.source, source.count > 0, envelope.timestamp > 0 {
|
||||
request = OWSRequestFactory.acknowledgeMessageDeliveryRequest(withSource: source, timestamp: envelope.timestamp)
|
||||
} else if envelope.type == .unidentifiedSender, envelope.timestamp > 0 {
|
||||
request = OWSRequestFactory.acknowledgeMessageDeliveryRequest(withSource: envelope.source!, timestamp: envelope.timestamp)
|
||||
} else {
|
||||
owsFailDebug("Cannot ACK message which has neither source, nor server GUID and timestamp.")
|
||||
return
|
||||
|
|
|
@ -12,7 +12,11 @@ final class LokiPushNotificationManager : NSObject {
|
|||
@objc(registerWithToken:)
|
||||
func register(with token: Data) {
|
||||
let hexEncodedToken = token.map { String(format: "%02.2hhx", $0) }.joined()
|
||||
print("Registering device token: (\(hexEncodedToken))")
|
||||
let oldToken = UserDefaults.standard.string(forKey: "deviceToken")
|
||||
if (hexEncodedToken == oldToken) {
|
||||
Logger.info("Token is not changed, no need to upload")
|
||||
return
|
||||
}
|
||||
// Send token to Loki server
|
||||
let parameters = [ "token" : hexEncodedToken ]
|
||||
let url = URL(string: "https://live.apns.getsession.org/register")!
|
||||
|
@ -23,6 +27,7 @@ final class LokiPushNotificationManager : NSObject {
|
|||
guard json["code"] as? Int != 0 else {
|
||||
return print("[Loki] An error occured during device token registration: \(json["message"] as? String ?? "nil").")
|
||||
}
|
||||
UserDefaults.standard.set(hexEncodedToken, forKey: "deviceToken")
|
||||
}, failure: { _, error in
|
||||
print("[Loki] Couldn't register device token.")
|
||||
})
|
||||
|
|
|
@ -64,7 +64,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
+ (TSRequest *)acknowledgeMessageDeliveryRequestWithSource:(NSString *)source timestamp:(UInt64)timestamp
|
||||
{
|
||||
OWSAssertDebug(source.length > 0);
|
||||
// OWSAssertDebug(source.length > 0);
|
||||
OWSAssertDebug(timestamp > 0);
|
||||
|
||||
NSString *path = [NSString stringWithFormat:@"v1/messages/%@/%llu", source, timestamp];
|
||||
|
|
Loading…
Reference in a new issue