Skip to content

Commit 6c144cb

Browse files
committed
StorageEngine: use more powerful NSKeyedArchiver (allows to store your NSCoded objects)
1 parent 29f231c commit 6c144cb

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

EDQueue.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Pod::Spec.new do |s|
22
s.name = 'EDQueue'
3-
s.version = '1.0'
3+
s.version = '1.1'
44
s.license = 'MIT'
55
s.summary = 'A persistent background job queue for iOS.'
66
s.homepage = 'https://github.com/gelosi/queue'
77
s.authors = {'Andrew Sliwinski' => '[email protected]', 'Francois Lambert' => '[email protected]', 'Oleg Shanyuk' => '[email protected]'}
8-
s.source = { :git => 'https://github.com/gelosi/queue.git', :tag => 'v1.0' }
8+
s.source = { :git => 'https://github.com/gelosi/queue.git', :tag => 'v1.1' }
99
s.platform = :ios, '7.0'
1010
s.source_files = 'EDQueue'
1111
s.library = 'sqlite3.0'

EDQueue/EDQueueStorageEngine.m

+11-5
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,9 @@ - (void)createJob:(EDQueueJob *)job
125125
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"EDQueueJob.userInfo can not be nil" userInfo:nil];
126126
}
127127

128-
NSData *data = [NSJSONSerialization dataWithJSONObject:job.userInfo
129-
options:NSJSONWritingPrettyPrinted
130-
error:nil];
128+
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:job.userInfo];
131129

132-
NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
130+
NSString *dataString = [data base64EncodedStringWithOptions:0];
133131

134132

135133
[self.queue inDatabase:^(FMDatabase *db) {
@@ -332,7 +330,15 @@ - (NSTimeInterval)fetchNextJobTimeInterval
332330

333331
- (id<EDQueueStorageItem>)_jobFromResultSet:(FMResultSet *)rs
334332
{
335-
NSDictionary *userInfo = [NSJSONSerialization JSONObjectWithData:[[rs stringForColumn:@"data"] dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];
333+
NSString *encodedString = [rs stringForColumn:@"data"];
334+
NSDictionary *userInfo;
335+
@try {
336+
NSData *data = [[NSData alloc] initWithBase64EncodedString:encodedString options:0];
337+
userInfo = [NSKeyedUnarchiver unarchiveObjectWithData:data];
338+
} @catch (NSException *exception) {
339+
/* respect previous JSON serialization [though, good idea to move serializer out of storage] */
340+
userInfo = [NSJSONSerialization JSONObjectWithData:[encodedString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];
341+
}
336342

337343
EDQueueStorageEngineJob *storedItem = [[EDQueueStorageEngineJob alloc] initWithTag:[rs stringForColumn:@"tag"]
338344
userInfo:userInfo

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2012 Andrew Sliwinski
1+
Copyright (c) 2012 Andrew Sliwinski, 2016 Oleg Shanyuk
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
44

0 commit comments

Comments
 (0)