Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #6 Make tasks more configurable #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

-(void) configure:(NSTimeInterval)delay callback:(void(^)(UIBackgroundRefreshStatus status))callback;

-(NSError*) scheduleProcessingTaskWithIdentifier:(NSString*)identifier delay:(NSTimeInterval)delay periodic:(BOOL)periodic callback:(void (^)(NSString* taskId))callback;
-(NSError*) scheduleProcessingTaskWithIdentifier:(NSString*)identifier delay:(NSTimeInterval)delay periodic:(BOOL)periodic requiresExternalPower:(BOOL)requiresExternalPower requiresNetworkConnectivity:(BOOL)requiresNetworkConnectivity callback:(void (^)(NSString* taskId))callback;

-(void) addListener:(NSString*)componentName callback:(void (^)(NSString* componentName))callback;
-(void) removeListener:(NSString*)componentName;
Expand Down
Binary file modified ios/TSBackgroundFetch/TSBackgroundFetch.framework/Info.plist
Binary file not shown.
Binary file modified ios/TSBackgroundFetch/TSBackgroundFetch.framework/TSBackgroundFetch
100755 → 100644
Binary file not shown.
6 changes: 4 additions & 2 deletions ios/TSBackgroundFetch/TSBackgroundFetch/TSBGTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
@property (nonatomic) BOOL periodic;
@property (nonatomic) BOOL enabled;
@property (nonatomic, readonly) BOOL finished;
@property (nonatomic) BOOL stopOnTerminate;
@property (nonatomic) BOOL stopOnTerminate;
@property (nonatomic) BOOL requiresExternalPower;
@property (nonatomic) BOOL requiresNetworkConnectivity;

+(void)load;
+(NSMutableArray *)tasks;
Expand All @@ -32,7 +34,7 @@
+(void)registerForTaskWithIdentifier:(NSString*)identifier;
+(BOOL)useProcessingTaskScheduler;

-(instancetype) initWithIdentifier:(NSString*)identifier delay:(NSTimeInterval)delay periodic:(BOOL)periodic callback:(void (^)(NSString* taskId))callback;
-(instancetype) initWithIdentifier:(NSString*)identifier delay:(NSTimeInterval)delay periodic:(BOOL)periodic requiresExternalPower:(BOOL)requiresExternalPower requiresNetworkConnectivity:(BOOL)requiresNetworkConnectivity callback:(void (^)(NSString* taskId))callback;
-(instancetype) initWithDictionary:(NSDictionary*)config;

-(BOOL) execute;
Expand Down
17 changes: 11 additions & 6 deletions ios/TSBackgroundFetch/TSBackgroundFetch/TSBGTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ -(instancetype)init {
return self;
}

-(instancetype) initWithIdentifier:(NSString*)identifier delay:(NSTimeInterval)delay periodic:(BOOL)periodic callback:(void (^)(NSString* taskId))callback {
-(instancetype) initWithIdentifier:(NSString*)identifier delay:(NSTimeInterval)delay periodic:(BOOL)periodic requiresExternalPower:(BOOL)requiresExternalPower requiresNetworkConnectivity:(BOOL)requiresNetworkConnectivity callback:(void (^)(NSString* taskId))callback {
self = [self init];

if (self) {
_identifier = identifier;
_delay = delay;
_periodic = periodic;
_requiresExternalPower = requiresExternalPower;
_requiresNetworkConnectivity = requiresNetworkConnectivity;
[TSBGTask add:self];
}
return self;
Expand All @@ -127,6 +129,8 @@ -(instancetype) initWithDictionary:(NSDictionary*)config {
_delay = [[config objectForKey:@"delay"] longValue];
_periodic = [[config objectForKey:@"periodic"] boolValue];
_enabled = [[config objectForKey:@"enabled"] boolValue];
_requiresExternalPower = [[config objectForKey:@"_requiresExternalPower"] boolValue];
_requiresNetworkConnectivity = [[config objectForKey:@"_requiresNetworkConnectivity"] boolValue];
}
return self;
}
Expand All @@ -146,9 +150,8 @@ - (NSError*) schedule {
}

BGProcessingTaskRequest *request = [[BGProcessingTaskRequest alloc] initWithIdentifier:_identifier];
// TODO Configurable.
request.requiresExternalPower = NO;
request.requiresNetworkConnectivity = NO;
request.requiresExternalPower = _requiresExternalPower;
request.requiresNetworkConnectivity = _requiresNetworkConnectivity;
request.earliestBeginDate = [NSDate dateWithTimeIntervalSinceNow:_delay];

NSError *error = nil;
Expand Down Expand Up @@ -258,12 +261,14 @@ -(NSDictionary*) toDictionary {
@"identifier": _identifier,
@"delay": @(_delay),
@"periodic": @(_periodic),
@"enabled": @(_enabled)
@"enabled": @(_enabled),
@"requiresExternalPower": @(_requiresExternalPower),
@"requiresNetworkConnectivity": @(_requiresNetworkConnectivity)
};
}

-(NSString*) description {
return [NSString stringWithFormat:@"<TSBGTask identifier=%@, delay=%ld, periodic=%d enabled=%d>", _identifier, (long)_delay, _periodic, _enabled];
return [NSString stringWithFormat:@"<TSBGTask identifier=%@, delay=%ld, periodic=%d enabled=%d requiresExternalPower=%d requiresNetworkConnectivity=%d>", _identifier, (long)_delay, _periodic, _enabled, _requiresExternalPower, _requiresNetworkConnectivity];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

-(void) configure:(NSTimeInterval)delay callback:(void(^)(UIBackgroundRefreshStatus status))callback;

-(NSError*) scheduleProcessingTaskWithIdentifier:(NSString*)identifier delay:(NSTimeInterval)delay periodic:(BOOL)periodic callback:(void (^)(NSString* taskId))callback;
-(NSError*) scheduleProcessingTaskWithIdentifier:(NSString*)identifier delay:(NSTimeInterval)delay periodic:(BOOL)periodic requiresExternalPower:(BOOL)requiresExternalPower requiresNetworkConnectivity:(BOOL)requiresNetworkConnectivity callback:(void (^)(NSString* taskId))callback;

-(void) addListener:(NSString*)componentName callback:(void (^)(NSString* componentName))callback;
-(void) removeListener:(NSString*)componentName;
Expand Down
4 changes: 2 additions & 2 deletions ios/TSBackgroundFetch/TSBackgroundFetch/TSBackgroundFetch.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ -(void) configure:(NSTimeInterval)delay callback:(void(^)(UIBackgroundRefreshSta
}];
}

-(NSError*) scheduleProcessingTaskWithIdentifier:(NSString*)identifier delay:(NSTimeInterval)delay periodic:(BOOL)periodic callback:(void (^)(NSString* taskId))callback {
-(NSError*) scheduleProcessingTaskWithIdentifier:(NSString*)identifier delay:(NSTimeInterval)delay periodic:(BOOL)periodic requiresExternalPower:(BOOL)requiresExternalPower requiresNetworkConnectivity:(BOOL)requiresNetworkConnectivity callback:(void (^)(NSString* taskId))callback {
TSBGTask *tsTask = [TSBGTask get:identifier];
if (tsTask) {
tsTask.delay = delay;
Expand All @@ -187,7 +187,7 @@ -(NSError*) scheduleProcessingTaskWithIdentifier:(NSString*)identifier delay:(NS
}
}
} else {
tsTask = [[TSBGTask alloc] initWithIdentifier:identifier delay:delay periodic:periodic callback:callback];
tsTask = [[TSBGTask alloc] initWithIdentifier:identifier delay:delay periodic:periodic requiresExternalPower:requiresExternalPower requiresNetworkConnectivity:requiresNetworkConnectivity callback:callback];
tsTask.callback = callback;
}

Expand Down