Skip to content

Commit

Permalink
fix fluttercommunity#69, upgrade Android dependencies, release v1.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
hnvn committed Jul 16, 2019
1 parent ee28e41 commit 686cde3
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.1.8 - 16.07.2019

* Fix bug in iOS: from iOS 8, absolute path to app's sandbox changes every time you relaunch the app, hence `savedDir` path is needed to truncate the changing part before saving it to DB and recreate the absolute path every time it loaded from DB. Currently, the plugin only supports save files in `NSDocumentDirectory`.
* Fix bug is iOS: setting wrong status of task in case that the application is terminated
* Android: upgrade dependencies

## 1.1.7 - 24.03.2019

* Android: upgrade `WorkManager` to version 2.0.0 (AndroidX)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="https://img.shields.io/badge/Flutter%20Community-flutter__downloader-blue.svg?style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAA5CAYAAABwDahPAAAAB3RJTUUH4gYTFygnu4qzzAAAAAlwSFlzAAAewgAAHsIBbtB1PgAAAARnQU1BAACxjwv8YQUAAAjVSURBVHjazZp5UJTnHcddWO5rd9ndd99llUMUUVhOYTnEaNAFYbk0cXJZlTRNWyqHlRtzNE0yJURFzkUSBUSjMZkYoqTT6B/SeDSYtBoOj1i1TpNpZ/yjje2MwK/P8+zhArv7vu++u05/M88Ms7M87+f7u57j3QULXGTuAUulAYuL82QJZT1KTcM4ndL4L88FP4eC/uvw7B8e4PFgy7npH7iNqR9KRwG0XV/+wiXQ3opVsaKoZ6vlieWn6NTau8q0ph9D0nfPKDVNEEiXQ/aeL2HLyLRhnMNjitPYdhFg40d3PpIma72cBu3mG+YXGLlpO5VcNRKS/gqoMl+HkIxXAf+N4IFObYQgVQWCPw9bz4MRnhv4I/jbJ5wGLvBUCEVRz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vdxuhD84Cnyciv4ONiNt+obnZrEQIhBJ3lE6fMkYCi1hSCfHNl1HBXoUg9JkceZRAYzA74PNFtBsEWBNBBNTdC4zctJF1PZDCjil9S8XwQw/cnei4GqDWNCOQPiM4M7TNSKTNjgR2IkrrM6gjcf/BBzb/sPwNtKb+nr1o4MUuJLUBaO0eA4gDAixFKC1edIujt9Q/omEoYlvm7r8kQKp+WU8iYatLYc+h4qa1e3mLoPNRGiZXnfWSaaIcArZl3sonEuSJOz7GQqz++Mksgl8k8DoRnPOO697weNOr41B9tKDCuokjQjqWZa1gEevfRSIOsi7k+SL60bZjzymBX6iby4S4eS/08lVlr5Es37obReYLxcrqMWVa430UiSmTCIejYNx2YBFuklg/l4mwNIEn7e67cH2yJKa0BnWOIUVC+RV5TssYWokn5Lp2h4aipPfHwPSdL5qe8T+XgeDXeA98zQAAAABJRU5ErkJggg==" width="600">
[![Flutter Community: flutter_downloader](https://fluttercommunity.dev/_github/header/flutter_downloader)](https://github.com/fluttercommunity/community)

# Flutter Downloader

Expand Down Expand Up @@ -82,6 +82,8 @@ This plugin is based on [`WorkManager`][1] in Android and [`NSURLSessionDownload
<string>All files have been downloaded</string>
````

**Note:**
- This plugin only supports save files in `NSDocumentDirectory`


## Android integration
Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.4.2'
}
}

Expand All @@ -35,7 +35,7 @@ android {

dependencies {
implementation('androidx.work:work-runtime:2.1.0')
implementation 'androidx.annotation:annotation:1.0.2'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.core:core:1.1.0-rc02'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'

Expand Down
12 changes: 6 additions & 6 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PODS:
- Flutter
- path_provider (0.0.1):
- Flutter
- permission_handler (2.1.2):
- permission_handler (3.0.0):
- Flutter

DEPENDENCIES:
Expand All @@ -24,11 +24,11 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/permission_handler/ios"

SPEC CHECKSUMS:
Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296
flutter_downloader: ff8f392c1b9d2a35f7c7578508e64504335fdab0
path_provider: 09407919825bfe3c2deae39453b7a5b44f467873
permission_handler: ccfc62fb39274a876cb21737e72a746f4c7efa94
Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a
flutter_downloader: 058b9c41564a90500f67f3e432e3524613a7fd83
path_provider: f96fff6166a8867510d2c25fdcc346327cc4b259
permission_handler: 047f11d44db785922214783da5f7a3cc8874c843

PODFILE CHECKSUM: 1b9df8d859f07d47cc6f43477c116e72a973c68f

COCOAPODS: 1.5.3
COCOAPODS: 1.7.0
13 changes: 7 additions & 6 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -43,9 +42,10 @@
/* Begin PBXFileReference section */
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
5A9AECB944365DA89A4BC314 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
62052E9DF95B469031D71905 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -80,7 +80,6 @@
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
3B80C3931E831B6300D905FE /* App.framework */,
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
9740EEBA1CF902C7004384FC /* Flutter.framework */,
Expand Down Expand Up @@ -137,6 +136,8 @@
B6C8F339E2DCD14BD62D3EE0 /* Pods */ = {
isa = PBXGroup;
children = (
62052E9DF95B469031D71905 /* Pods-Runner.debug.xcconfig */,
5A9AECB944365DA89A4BC314 /* Pods-Runner.release.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
Expand Down Expand Up @@ -200,6 +201,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand All @@ -223,7 +225,6 @@
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -255,7 +256,7 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
"${BUILT_PRODUCTS_DIR}/flutter_downloader/flutter_downloader.framework",
"${BUILT_PRODUCTS_DIR}/path_provider/path_provider.framework",
Expand All @@ -270,7 +271,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
Expand Down
6 changes: 6 additions & 0 deletions flutter_downloader.iml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_downloader/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_downloader/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_downloader/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_downloader/example/ios/Flutter/App.framework/flutter_assets/packages" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/flutter_downloader/example/ios/Flutter/flutter_assets/packages" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/permission_handler/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/permission_handler/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/permission_handler/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/App.framework/flutter_assets/packages" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/flutter_assets/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
39 changes: 32 additions & 7 deletions ios/Classes/FlutterDownloaderPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,32 @@ - (NSURL*)fileUrlFromDict:(NSDictionary*)dict
NSString *url = dict[KEY_URL];
NSString *savedDir = dict[KEY_SAVED_DIR];
NSString *filename = dict[KEY_FILE_NAME];
NSLog(@"savedDir: %@", savedDir);
NSLog(@"filename: %@", filename);
// if (filename == (NSString*) [NSNull null] || [NULL_VALUE isEqualToString: filename]) {
// filename = [NSURL URLWithString:url].lastPathComponent;
// }
NSURL *savedDirURL = [NSURL fileURLWithPath:savedDir];
return [savedDirURL URLByAppendingPathComponent:filename];
}

- (NSString*)absoluteSavedDirPath:(NSString*)savedDir {
return [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:savedDir];
}

- (NSString*)shortenSavedDirPath:(NSString*)absolutePath {
NSLog(@"Absolute savedDir path: %@", absolutePath);
if (absolutePath) {
NSString* documentDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSRange foundRank = [absolutePath rangeOfString:documentDirPath];
if (foundRank.length > 0) {
// we increase the location of range by one because we want to remove the file separator as well.
return [absolutePath substringWithRange:NSMakeRange(foundRank.length + 1, absolutePath.length - documentDirPath.length - 1)];
}
}
return absolutePath;
}

- (long)currentTimeInMilliseconds
{
return [[NSDate date] timeIntervalSince1970]*1000;
Expand Down Expand Up @@ -331,7 +350,9 @@ - (NSArray*)loadAllTasks
NSLog(@"Load tasks successfully");
NSMutableArray *results = [NSMutableArray new];
for(NSArray *record in records) {
[results addObject:[self taskDictFromRecordArray:record]];
NSDictionary *task = [self taskDictFromRecordArray:record];
NSLog(@"%@", task);
[results addObject:task];
}
return results;
}
Expand Down Expand Up @@ -359,7 +380,9 @@ - (NSDictionary*)loadTaskWithId:(NSString*)taskId
if (records != nil && [records count] > 0) {
NSArray *record = [records firstObject];
NSDictionary *task = [self taskDictFromRecordArray:record];
[_runningTaskById setObject:[NSMutableDictionary dictionaryWithDictionary:task] forKey:taskId];
if ([task[KEY_STATUS] intValue] < STATUS_COMPLETE) {
[_runningTaskById setObject:[NSMutableDictionary dictionaryWithDictionary:task] forKey:taskId];
}
return task;
}
return nil;
Expand All @@ -373,7 +396,7 @@ - (NSDictionary*) taskDictFromRecordArray:(NSArray*)record
int progress = [[record objectAtIndex:[_dbManager.arrColumnNames indexOfObject:@"progress"]] intValue];
NSString *url = [record objectAtIndex:[_dbManager.arrColumnNames indexOfObject:@"url"]];
NSString *filename = [record objectAtIndex:[_dbManager.arrColumnNames indexOfObject:@"file_name"]];
NSString *savedDir = [record objectAtIndex:[_dbManager.arrColumnNames indexOfObject:@"saved_dir"]];
NSString *savedDir = [self absoluteSavedDirPath:[record objectAtIndex:[_dbManager.arrColumnNames indexOfObject:@"saved_dir"]]];
NSString *headers = [record objectAtIndex:[_dbManager.arrColumnNames indexOfObject:@"headers"]];
headers = [self escape:headers revert:true];
int resumable = [[record objectAtIndex:[_dbManager.arrColumnNames indexOfObject:@"resumable"]] intValue];
Expand All @@ -388,11 +411,12 @@ - (NSDictionary*) taskDictFromRecordArray:(NSArray*)record
- (void)enqueueMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
NSString *urlString = call.arguments[KEY_URL];
NSString *savedDir = call.arguments[KEY_SAVED_DIR];
NSString *shortSavedDir = [self shortenSavedDirPath:savedDir];
NSString *fileName = call.arguments[KEY_FILE_NAME];
NSString *headers = call.arguments[KEY_HEADERS];
NSNumber *showNotification = call.arguments[KEY_SHOW_NOTIFICATION];
NSNumber *openFileFromNotification = call.arguments[KEY_OPEN_FILE_FROM_NOTIFICATION];

NSURLSessionDownloadTask *task = [self downloadTaskWithURL:[NSURL URLWithString:urlString] fileName:fileName andSavedDir:savedDir andHeaders:headers];

NSString *taskId = [self identifierForTask:task];
Expand All @@ -419,7 +443,7 @@ - (void)enqueueMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result

__typeof__(self) __weak weakSelf = self;
dispatch_sync(databaseQueue, ^{
[weakSelf addNewTask:taskId url:urlString status:STATUS_ENQUEUED progress:0 filename:fileName savedDir:savedDir headers:headers resumable:NO showNotification: [showNotification boolValue] openFileFromNotification: [openFileFromNotification boolValue]];
[weakSelf addNewTask:taskId url:urlString status:STATUS_ENQUEUED progress:0 filename:fileName savedDir:shortSavedDir headers:headers resumable:NO showNotification: [showNotification boolValue] openFileFromNotification: [openFileFromNotification boolValue]];
});
result(taskId);
[self sendUpdateProgressForTaskId:taskId inStatus:@(STATUS_ENQUEUED) andProgress:@0];
Expand Down Expand Up @@ -656,7 +680,9 @@ - (void)applicationWillTerminate:(nonnull UIApplication *)application
{
NSLog(@"applicationWillTerminate:");
for (NSString* key in _runningTaskById) {
[self updateTask:key status:STATUS_CANCELED progress:-1];
if ([_runningTaskById[key][KEY_STATUS] intValue] < STATUS_COMPLETE) {
[self updateTask:key status:STATUS_CANCELED progress:-1];
}
}
_session = nil;
_flutterChannel = nil;
Expand Down Expand Up @@ -687,7 +713,6 @@ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTas
NSString *taskId = [self identifierForTask:downloadTask ofSession:session];
NSDictionary *task = [self loadTaskWithId:taskId];
NSURL *destinationURL = [self fileUrlFromDict:task];

[_runningTaskById removeObjectForKey:taskId];

NSError *error;
Expand Down
11 changes: 7 additions & 4 deletions lib/flutter_downloader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
library flutter_downloader;

import 'dart:io';
import 'dart:async';
import 'package:meta/meta.dart';
import 'package:flutter/services.dart';
Expand All @@ -27,8 +28,7 @@ import 'package:flutter/services.dart';
/// * `progress`: current progress value of a download task, the value is in
/// range of 0 and 100
///
typedef void DownloadCallback(
String id, DownloadTaskStatus status, int progress);
typedef void DownloadCallback(String id, DownloadTaskStatus status, int progress);

///
/// A class defines a set of possible statuses of a download task
Expand Down Expand Up @@ -127,6 +127,9 @@ class FlutterDownloader {
bool showNotification = true,
bool openFileFromNotification = true,
bool requiresStorageNotLow = true}) async {

assert(Directory(savedDir).existsSync());

StringBuffer headerBuilder = StringBuffer();
if (headers != null) {
headerBuilder.write('{');
Expand Down Expand Up @@ -329,8 +332,7 @@ class FlutterDownloader {
/// * `shouldDeleteContent`: if the task is completed, set `true` to let the
/// plugin remove the downloaded file. The default value is `false`.
///
static Future<Null> remove(
{@required String taskId, bool shouldDeleteContent = false}) async {
static Future<Null> remove({@required String taskId, bool shouldDeleteContent = false}) async {
try {
return await platform.invokeMethod('remove',
{'task_id': taskId, 'should_delete_content': shouldDeleteContent});
Expand Down Expand Up @@ -394,6 +396,7 @@ class FlutterDownloader {
int process = call.arguments['progress'];
callback(id, DownloadTaskStatus._internal(status), process);
}
return null;
});
} else {
platform.setMethodCallHandler(null);
Expand Down

0 comments on commit 686cde3

Please sign in to comment.