Check if entities is nil (#2930)

This commit is contained in:
Miguel Alatzar 2019-06-26 11:50:44 -07:00 committed by Elias Nahum
parent f338279444
commit 749f8a50b3
No known key found for this signature in database
GPG key ID: E038DB71E0B61702
2 changed files with 29 additions and 22 deletions

View file

@ -32,8 +32,13 @@
if(![fileManager fileExistsAtPath:filePath]) {
return nil;
}
NSData *data = [NSData dataWithContentsOfFile:filePath];
return [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
if (data != nil) {
return [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
}
return nil;
}
-(void)removeFile:(NSString *)fileName {

View file

@ -126,28 +126,30 @@ import os.log
public func notificationReceipt(notificationId: Any?, receivedAt: Int, type: Any?) {
let store = StoreManager.shared() as StoreManager
let _ = store.getEntities(true)
let serverURL = store.getServerUrl()
let sessionToken = store.getToken()
let urlString = "\(serverURL!)/api/v4/notifications/ack"
if (notificationId != nil) {
let jsonObject: [String: Any] = [
"id": notificationId as Any,
"received_at": receivedAt,
"platform": "ios",
"type": type as Any
]
let entities = store.getEntities(true)
if (entities != nil) {
let serverURL = store.getServerUrl()
let sessionToken = store.getToken()
let urlString = "\(serverURL!)/api/v4/notifications/ack"
if !JSONSerialization.isValidJSONObject(jsonObject) {return}
guard let url = URL(string: urlString) else {return}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer \(sessionToken!)", forHTTPHeaderField: "Authorization")
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted)
URLSession(configuration: .ephemeral).dataTask(with: request).resume()
if (notificationId != nil) {
let jsonObject: [String: Any] = [
"id": notificationId as Any,
"received_at": receivedAt,
"platform": "ios",
"type": type as Any
]
if !JSONSerialization.isValidJSONObject(jsonObject) {return}
guard let url = URL(string: urlString) else {return}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer \(sessionToken!)", forHTTPHeaderField: "Authorization")
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted)
URLSession(configuration: .ephemeral).dataTask(with: request).resume()
}
}
}
}