This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @interface Sync() | |
| @property (nonatomic) dispatch_queue_t syncQueue; | |
| @end | |
| @implementation Sync | |
| @synthesize syncQueue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; | |
| [request setHTTPMethod:@"GET"]; | |
| NSString *url = @"http://localhost:5000/api/updates/"; | |
| if(checksum){ | |
| url = [NSString stringWithFormat:@"%@?checksum=%@", url, checksum]; | |
| } | |
| [request setURL:[NSURL URLWithString:url]]; | |
| [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *err) { | |
| NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
| NSString *documentsDirectoryPath = [documentPaths objectAtIndex:0]; | |
| NSString *checksum = nil; | |
| BOOL initialSync = YES; | |
| if([this isUpdatePending]){ | |
| NSString *filePath = [documentsDirectoryPath stringByAppendingPathComponent:@"updated.db"]; | |
| NSData *contents = [NSData dataWithContentsOfFile:filePath]; | |
| checksum = [contents MD5HexDigest]; | |
| initialSync = NO; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void) applyOutstandingUpdates { | |
| __weak id this = self; | |
| dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
| if(![this isUpdatePending]){ | |
| return; //no update pending | |
| } | |
| NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
| NSString *documentsDirectoryPath = [documentPaths objectAtIndex:0]; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (BOOL) isUpdatePending { | |
| NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
| NSString *documentsDirectoryPath = [documentPaths objectAtIndex:0]; | |
| NSString *filePath = [documentsDirectoryPath stringByAppendingPathComponent:@"updated.db"]; | |
| NSFileManager *fileManager = [NSFileManager defaultManager]; | |
| return [fileManager fileExistsAtPath:filePath]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "Sync.h" | |
| #import "NSData+MD5Digest.h" | |
| @implementation Sync | |
| + (Sync *) defaultWorker { | |
| //GCD singleton pattern: http://www.galloway.me.uk/tutorials/singleton-classes/ | |
| static Sync *defaultWorker = nil; | |
| static dispatch_once_t onceToken; | |
| dispatch_once(&onceToken, ^{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| @interface Sync : NSObject | |
| + (Sync *) defaultWorker; | |
| - (void) downloadUpdates; | |
| - (void) applyOutstandingUpdates; | |
| - (BOOL) isUpdatePending; | |
| - (BOOL) hasPerformedInitialSync; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //... | |
| app.get('/api/updates/:model', function (req, res) { | |
| var filter = {}; | |
| if(req.query.timestamp){ | |
| filter['updated_at'] = onionrm.gte(req.query.timestamp); | |
| } | |
| //... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [{ | |
| "id": 1, | |
| "name": "Oaklake Trails Naturist Park", | |
| "latitude": 35.8082099, | |
| "longitude": -96.5649402, | |
| "rating": 4, | |
| "address": "24601 Milfay Rd", | |
| "city": "Depew", | |
| "state": "OK", | |
| "zip_code": "74028", |