|
|
@@ -52,20 +52,20 @@ class Sync{
|
|
|
*/
|
|
|
func sync(url: URL){
|
|
|
|
|
|
- print("SYNC:LOG: Sync started.")
|
|
|
+ NSLog(":SYNC:LOG: Sync started.")
|
|
|
|
|
|
//Synchronously get data
|
|
|
let task = URLSession.shared.dataTask(with: url) { data, response, error in
|
|
|
guard error == nil else {
|
|
|
- print("SYNC:ERROR: Unknown error.")
|
|
|
+ NSLog(":SYNC:ERROR: Unknown error.")
|
|
|
return
|
|
|
}
|
|
|
guard let data = data else {
|
|
|
- print("SYNC:ERROR: Data is empty.")
|
|
|
+ NSLog(":SYNC:ERROR: Data is empty.")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- print("SYNC:LOG: Data received.")
|
|
|
+ NSLog(":SYNC:LOG: Data received.")
|
|
|
|
|
|
var strData = String(data:data, encoding: String.Encoding.utf8)
|
|
|
|
|
|
@@ -96,6 +96,7 @@ class Sync{
|
|
|
let dataPostImage : [String] = self.getTable(data: strData!, table: "post_image")
|
|
|
let dataPostTag : [String] = self.getTable(data: strData!, table: "post_tag")
|
|
|
//let dataSponsor : [String] = self.getTable(data: strData!, table: "sponsor")
|
|
|
+ let dataSettings: [String] = self.getTable(data: strData!, table: "settings")
|
|
|
|
|
|
//One by one, save the received data
|
|
|
self.saveTableActivity(entries : dataActivity)
|
|
|
@@ -115,9 +116,12 @@ class Sync{
|
|
|
self.saveTablePhoto(entries: dataPhoto)
|
|
|
self.saveTablePhotoAlbum(entries: dataPhotoAlbum)
|
|
|
|
|
|
+ self.saveSettings(entries: dataSettings)
|
|
|
+
|
|
|
+
|
|
|
//DEBUG: Tester, Debug only
|
|
|
// Test if a entity has entries
|
|
|
- let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
|
|
|
+ /*let context = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
|
|
|
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
context.persistentStoreCoordinator = appDelegate.persistentStoreCoordinator
|
|
|
let fetchRequest: NSFetchRequest<Post> = Post.fetchRequest() //Entity to debug
|
|
|
@@ -126,13 +130,13 @@ class Sync{
|
|
|
//go get the results
|
|
|
let searchResults = try context.fetch(fetchRequest)
|
|
|
|
|
|
- print("SYNC:DEBUG: Num of results = \(searchResults.count).")
|
|
|
+ NSLog(":SYNC:DEBUG: Num of results = \(searchResults.count).")
|
|
|
for r in searchResults as [NSManagedObject] {
|
|
|
- print("SYNC:DEBUG: id: \(r.value(forKey: "id")).")
|
|
|
+ NSLog(":SYNC:DEBUG: id: \(r.value(forKey: "id")).")
|
|
|
}
|
|
|
} catch {
|
|
|
- print("SYNC:DEBUG: Error with request: \(error).")
|
|
|
- }
|
|
|
+ NSLog(":SYNC:DEBUG: Error with request: \(error).")
|
|
|
+ }*/
|
|
|
//End tester
|
|
|
}
|
|
|
|
|
|
@@ -149,7 +153,7 @@ class Sync{
|
|
|
func getTable(data: String, table: String) -> [String]{
|
|
|
//Does the table exists?
|
|
|
if data.indexOf(target: "\"\(table)\":[") == nil{
|
|
|
- print("SYNC:LOG: Empty table: \(table).")
|
|
|
+ NSLog(":SYNC:LOG: Empty table: \(table).")
|
|
|
return [String]()
|
|
|
}
|
|
|
let iS : Int? = data.indexOf(target: "\"\(table)\":[")
|
|
|
@@ -165,20 +169,19 @@ class Sync{
|
|
|
entries[0] = entries[0].subStr(start: 1, end: entries[0].length - 1)
|
|
|
entries[entries.count - 1] = entries[entries.count - 1].subStr(start: 0, end: entries[entries.count - 1].length - 2)
|
|
|
|
|
|
- print("SYNC:LOG: Table \(table) has \(entries.count) rows.")
|
|
|
+ NSLog(":SYNC:LOG: Table \(table) has \(entries.count) rows.")
|
|
|
|
|
|
//Return the array
|
|
|
return entries
|
|
|
}
|
|
|
|
|
|
- // FIX: ERROR in API.
|
|
|
/**
|
|
|
Saves the data in the table.
|
|
|
:param: entries Array of strings containing the rows of the table, in JSON format.
|
|
|
*/
|
|
|
func saveTablePeople(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table People.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table People.")
|
|
|
|
|
|
//Set up context
|
|
|
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
@@ -195,9 +198,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up People entity: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up People entity: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up People entity")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up People entity")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -258,9 +261,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Place with id \(id): \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Place with id \(id): \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Place with id \(id).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Place with id \(id).")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -271,7 +274,7 @@ class Sync{
|
|
|
*/
|
|
|
func saveTablePlace(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table Place.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table Place.")
|
|
|
|
|
|
//Set up context
|
|
|
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
@@ -288,9 +291,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up Places entity: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Places entity: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up Places entity.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Places entity.")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -351,9 +354,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Place with id \(id): \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Place with id \(id): \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Place with id \(id).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Place with id \(id).")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -364,7 +367,7 @@ class Sync{
|
|
|
*/
|
|
|
func saveTablePost(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table Post.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table Post.")
|
|
|
|
|
|
let dateFormatter = DateFormatter()
|
|
|
dateFormatter.timeZone = TimeZone.ReferenceType.local
|
|
|
@@ -384,9 +387,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up Post entity: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Post entity: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up Post entity.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Post entity.")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -455,9 +458,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Post with id \(id): \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Post with id \(id): \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Post with id \(id).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Post with id \(id).")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -468,7 +471,7 @@ class Sync{
|
|
|
*/
|
|
|
func saveTablePostComment(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table Post_comment.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table Post_comment.")
|
|
|
|
|
|
let dateFormatter = DateFormatter()
|
|
|
dateFormatter.timeZone = TimeZone.ReferenceType.local
|
|
|
@@ -488,9 +491,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up Post_comment entity: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Post_comment entity: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up Post_comment entity.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Post_comment entity.")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -532,9 +535,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Activity_comment with id \(id): \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Activity_comment with id \(id): \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Activity_comment with id \(id).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Activity_comment with id \(id).")
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -546,7 +549,7 @@ class Sync{
|
|
|
*/
|
|
|
func saveTablePostImage(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table Post_image.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table Post_image.")
|
|
|
|
|
|
//Set up context
|
|
|
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
@@ -563,9 +566,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up Post_comment entity: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Post_comment entity: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up Post_comment entity.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Post_comment entity.")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -596,9 +599,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Post_image with id \(id): \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Post_image with id \(id): \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Post_image with id \(id).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Post_image with id \(id).")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -609,7 +612,7 @@ class Sync{
|
|
|
*/
|
|
|
func saveTablePostTag(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table Post_tag.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table Post_tag.")
|
|
|
|
|
|
//Set up context
|
|
|
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
@@ -626,9 +629,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up Post_tag entity: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Post_tag entity: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up Post_tag entity.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Post_tag entity.")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -649,9 +652,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Post_tag for post: \(post), tag: \(tag): \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Post_tag for post: \(post), tag: \(tag): \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Post_tag for post: \(post), tag: \(tag).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Post_tag for post: \(post), tag: \(tag).")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -662,7 +665,7 @@ class Sync{
|
|
|
*/
|
|
|
func saveTableActivity(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table Activity.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table Activity.")
|
|
|
|
|
|
let dateFormatter = DateFormatter()
|
|
|
dateFormatter.timeZone = TimeZone.ReferenceType.local
|
|
|
@@ -682,9 +685,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up Activity entity: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Activity entity: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up Activity entity.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Activity entity.")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -805,9 +808,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Activity with id \(id): \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Activity with id \(id): \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Activity with id \(id).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Activity with id \(id).")
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -819,7 +822,7 @@ class Sync{
|
|
|
*/
|
|
|
func saveTableActivityComment(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table Activity_comment.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table Activity_comment.")
|
|
|
|
|
|
let dateFormatter = DateFormatter()
|
|
|
dateFormatter.timeZone = TimeZone.ReferenceType.local
|
|
|
@@ -839,9 +842,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up Activity_comment entity: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Activity_comment entity: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up Activity_comment entity.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Activity_comment entity.")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -883,9 +886,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Activity_comment with id \(id): \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Activity_comment with id \(id): \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Activity_comment with id \(id).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Activity_comment with id \(id).")
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -897,7 +900,7 @@ class Sync{
|
|
|
*/
|
|
|
func saveTableActivityImage(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table Activity_image.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table Activity_image.")
|
|
|
|
|
|
//Set up context
|
|
|
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
@@ -914,9 +917,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up Activity_comment entity: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Activity_comment entity: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up Activity_comment entity.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Activity_comment entity.")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -947,9 +950,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Activity_image with id \(id): \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Activity_image with id \(id): \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Activity_image with id \(id).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Activity_image with id \(id).")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -960,7 +963,7 @@ class Sync{
|
|
|
*/
|
|
|
func saveTableActivityTag(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table Activity_tag.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table Activity_tag.")
|
|
|
|
|
|
//Set up context
|
|
|
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
@@ -977,9 +980,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up Activity_tag entity: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Activity_tag entity: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up Activity_tag entity.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Activity_tag entity.")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -1000,9 +1003,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Activity_tag for activity \(activity), tag: \(tag): Error: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Activity_tag for activity \(activity), tag: \(tag): Error: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Activity_tag for activity \(activity), tag: \(tag).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Activity_tag for activity \(activity), tag: \(tag).")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1014,7 +1017,7 @@ class Sync{
|
|
|
//CHECK: New (and probably better format than the others.)
|
|
|
func saveTableActivityItinerary(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table Activity_itinerary.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table Activity_itinerary.")
|
|
|
|
|
|
let dateFormatter = DateFormatter()
|
|
|
dateFormatter.timeZone = TimeZone.ReferenceType.local
|
|
|
@@ -1034,9 +1037,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up Activity_itinerary entity: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Activity_itinerary entity: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up Activity_itinerary entity.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Activity_itinerary entity.")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -1112,9 +1115,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Activity_itinerary with id \(id): \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Activity_itinerary with id \(id): \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Activity_itinerary with id \(id).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Activity_itinerary with id \(id).")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1125,7 +1128,7 @@ class Sync{
|
|
|
*/
|
|
|
func saveTableAlbum(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table Album.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table Album.")
|
|
|
|
|
|
//Set up context
|
|
|
let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
@@ -1142,9 +1145,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up Album: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Album: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up Album entity.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Album entity.")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -1207,9 +1210,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Album with id \(id): \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Album with id \(id): \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Album with id \(id).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Album with id \(id).")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1220,7 +1223,7 @@ class Sync{
|
|
|
*/
|
|
|
func saveTablePhoto(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table Photo.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table Photo.")
|
|
|
|
|
|
let dateFormatter = DateFormatter()
|
|
|
dateFormatter.timeZone = TimeZone.ReferenceType.local
|
|
|
@@ -1240,9 +1243,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up Photo: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Photo: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up Photo entity.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Photo entity.")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -1317,9 +1320,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Photo with id \(id): \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Photo with id \(id): \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Photo with id \(id).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Photo with id \(id).")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1330,7 +1333,7 @@ class Sync{
|
|
|
*/
|
|
|
func saveTablePhotoAlbum(entries : [String]){
|
|
|
|
|
|
- print("SYNC:LOG: Saving table Photo_album.")
|
|
|
+ NSLog(":SYNC:LOG: Saving table Photo_album.")
|
|
|
|
|
|
let dateFormatter = DateFormatter()
|
|
|
dateFormatter.timeZone = TimeZone.ReferenceType.local
|
|
|
@@ -1350,9 +1353,9 @@ class Sync{
|
|
|
do {
|
|
|
try context.execute(request)
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not clean up Photo_album: \(error), \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Photo_album: \(error), \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not clean up Photo_album entity.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not clean up Photo_album entity.")
|
|
|
}
|
|
|
|
|
|
//Loop new entries
|
|
|
@@ -1374,10 +1377,39 @@ class Sync{
|
|
|
do {
|
|
|
try context.save()
|
|
|
} catch let error as NSError {
|
|
|
- print("SYNC:ERROR: Could not store Photo_album entry \(error.userInfo).")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Photo_album entry \(error.userInfo).")
|
|
|
} catch {
|
|
|
- print("SYNC:ERROR: Could not store Photo_album entry.")
|
|
|
+ NSLog(":SYNC:ERROR: Could not store Photo_album entry.")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ Saves the received settings.
|
|
|
+ :param: entries Array of strings containing the rows of the table, in JSON format.
|
|
|
+ */
|
|
|
+ func saveSettings(entries : [String]){
|
|
|
+
|
|
|
+ NSLog(":SYNC:LOG: Saving settings.")
|
|
|
+ let defaults = UserDefaults.standard
|
|
|
+
|
|
|
+ // Loop new entries
|
|
|
+ for entry in entries{
|
|
|
+
|
|
|
+ // Get setting name
|
|
|
+ var str = entry
|
|
|
+ let name: String = str.subStr(start : str.indexOf(target : "\"name\":")! + 8, end : str.indexOf(target : ",\"")! - 2)
|
|
|
+
|
|
|
+ // Get setting value
|
|
|
+ str = str.subStr(start : str.indexOf(target : ",\"")! + 1, end : str.length - 1)
|
|
|
+ let value: Int = Int(str.subStr(start : str.indexOf(target : "\"value\":")! + 9, end : str.length - 2))!
|
|
|
+
|
|
|
+ // Save only the needed settings
|
|
|
+ if ["festivals", "comments", "photos"].contains(name){
|
|
|
+ NSLog(":SYNC:LOG: Setting \(name) \(value)")
|
|
|
+ defaults.set(value, forKey: name)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|