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

Added configurable requiresExternalPower and requiresNetworkConnectivity params #96

Open
wants to merge 7 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ ios/.generated
pubspec.lock
doc/
build/
example/.flutter-plugins-dependencies
example/ios/Flutter/flutter_export_environment.sh
1 change: 0 additions & 1 deletion example/.flutter-plugins-dependencies

This file was deleted.

11 changes: 0 additions & 11 deletions example/ios/Flutter/flutter_export_environment.sh

This file was deleted.

4 changes: 4 additions & 0 deletions ios/Classes/BackgroundFetchPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,14 @@ - (void) scheduleTask:(NSDictionary*)config result:(FlutterResult)result {
long delayMS = [[config objectForKey:@"delay"] longValue];
NSTimeInterval delay = delayMS / 1000;
BOOL periodic = [[config objectForKey:@"periodic"] boolValue];
BOOL requiresExternalPower = [[config objectForKey:@"requiresCharging"] boolValue];
BOOL requiresNetworkConnectivity = [[config objectForKey:@"requiresNetworkConnectivity"] boolValue];

NSError *error = [[TSBackgroundFetch sharedInstance] scheduleProcessingTaskWithIdentifier:taskId
delay:delay
periodic:periodic
requiresExternalPower:requiresExternalPower
requiresNetworkConnectivity:requiresNetworkConnectivity
callback:[self createCallback]];
if (!error) {
result(@(YES));
Expand Down
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.framework/Info.plist
Binary file not shown.
Binary file modified ios/TSBackgroundFetch.framework/TSBackgroundFetch
100755 → 100644
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
151 changes: 0 additions & 151 deletions ios/TSBackgroundFetch.framework/_CodeSignature/CodeResources

This file was deleted.

Binary file not shown.
21 changes: 18 additions & 3 deletions lib/background_fetch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ class _AbstractTaskConfig {
bool requiresStorageNotLow;

///
/// [Android only] Specify that to run this job, the device must be charging (or be a non-battery-powered device connected to permanent power, such as Android TV devices). This defaults to false.
/// Specify that to run this job, the device must be charging (or be a non-battery-powered device connected to permanent power, such as Android TV devices). This defaults to [false].
///
/// This will use the [requiresCharging] param on Android and [requiresExternalPower] param on iOS.
///
bool requiresCharging;

Expand All @@ -118,6 +120,12 @@ class _AbstractTaskConfig {
///
bool requiresDeviceIdle;

///
/// [iOS only] When set true, ensure that this job will run only when device is has network connectivity.
///
/// The default state is false: that is, the job can run even if device does not have network connectivity.
bool requiresNetworkConnectivity;

_AbstractTaskConfig(
{this.stopOnTerminate,
this.startOnBoot,
Expand All @@ -127,7 +135,8 @@ class _AbstractTaskConfig {
this.requiresBatteryNotLow,
this.requiresStorageNotLow,
this.requiresCharging,
this.requiresDeviceIdle});
this.requiresDeviceIdle,
this.requiresNetworkConnectivity = false});

Map<String, dynamic> toMap() {
Map<String, dynamic> config = {};
Expand All @@ -145,6 +154,7 @@ class _AbstractTaskConfig {
if (requiresCharging != null) config['requiresCharging'] = requiresCharging;
if (requiresDeviceIdle != null)
config['requiresDeviceIdle'] = requiresDeviceIdle;
config['requiresNetworkConnectivity'] = requiresNetworkConnectivity ?? false;
return config;
}
}
Expand Down Expand Up @@ -225,6 +235,8 @@ class TaskConfig extends _AbstractTaskConfig {
bool requiresStorageNotLow,
bool requiresCharging,
bool requiresDeviceIdle,
bool requiresExternalPower,
bool requiresNetworkConnectivity,
}) : super(
stopOnTerminate: stopOnTerminate,
startOnBoot: startOnBoot,
Expand All @@ -234,13 +246,16 @@ class TaskConfig extends _AbstractTaskConfig {
requiresBatteryNotLow: requiresBatteryNotLow,
requiresStorageNotLow: requiresStorageNotLow,
requiresCharging: requiresCharging,
requiresDeviceIdle: requiresDeviceIdle);
requiresDeviceIdle: requiresDeviceIdle,
requiresNetworkConnectivity: requiresNetworkConnectivity);

Map<String, dynamic> toMap() {
Map<String, dynamic> config = super.toMap();
config['taskId'] = this.taskId;
config['delay'] = this.delay;
config['periodic'] = this.periodic;
config['requiresCharging'] = this.requiresCharging ?? false;
config['requiresNetworkConnectivity'] = this.requiresNetworkConnectivity ?? false;
return config;
}
}
Expand Down