1.download map.put(id,task) && map.get(id); id from database.JS MAP “{}”;check if exist!
2.create a database,id—downloadTask.
Step:
-
Create database when init,Create a map in JS .
-
Create download object,then store it to map which can be getted from rd.downloader (JS Engine) and store it to database.Last return the object through getting object from map.
-
When execute callback function,get object from map,then set properties of the object,and the same time store it to database.Then execute callback.
-
When enumerate downloads,get downloads from database,if the js map does not contain download,then store it.
-
When clear downloads,clear local map, clear map and clear database,
-
GetTaskById a new API.First get task from js map. Get task through database,then store it to js map if js map does not contain it //wait to modify!
-
Background Configuration
Proplem:
-
getTask I think getTask from map collection first,if not,from database
-
about enumerate, from database;
-
getTaskById,need to modify,it should be object,not just json simply!
-
restrict the speed of download,kb/s(限速 )! setSpeed!
-
remember add a column plugin.m_id!(do not do that,plugin.m_id is used in runtime.Create a download task,then get plugin.m_id)
-
get object from collection,not create a new one
-
In system callback function,download tasks are from local collection!Not sure if turn to JS MAP.
-
How to judge object is nil in JS in IOS?
-
about m_id ,in runtime map?
-
enumerate and startAll store download task from database!
-
JS MAP does not equal the local array?why?
-
Why use a database to store download?
-
getTaskById if the local array does not contain m_id,then create a new download ,then modify the properties of download.
-
Enumerate,enumerate from database,then enumerate the local array to check if the m_id of download exist in the local array,If not ,create a new download!
-
StartAll,start all the tasks from local array?
-
How the JS Map bind the local array?
-
store resume data to a file where in sandbox!
-
According URL to check where to store the info to id(taskDescription store id from database,then get the id to store info)
-
When you create a new one ,then start, sometimes it will crash.
-
getTaskById first time return NULL,second time return a task! *****
-
getTaskById and enumerate use a common method which will do get task from JS Map first,then local array,last database.
-
remove task,remove each JS MAP of web view.
-
downloadTaskID from 1. getMaxID!
-
Above 9,can resume task directly,create a new one,then resume.In 8.0 ,move file to TMP,in 7.0,setting the correct path to key.
-
CreateDownload URL and Path same,
-
插入数据失败: column dradeId is not unique
Complete:
-
same task.Test in callback function
-
database store the download info.
-
getTaskById need to write int RDUnility.m
Test:
-
First ,createDownload. Create a download,JS Map add a new download,Database add a new one.
-
Enumerate func:Enumerate from database,the same time,JS MAP contain download tasks.
-
StartAll how to define all?From database,or JS MAP,or local collection?
-
Clear func:Clear local,clear JS MAP,clear database.
-
Remove : remove local,JS MAP,database
-
getTaskById:First from JS MAP,If not exist,get from database,then store it to JS MAP.
-
When download start,pause,resume and so on,the download in JS MAP change,database change too!
//Check if the resumeData is valid to use
//The data argument is passed by the method as below
//-(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)downloadCompletedTask didCompleteWithError:(NSError *)error
- (NSData *)turnValidResumeData:(NSData *)data
{
if (!data || [data length] < 1) return nil;
NSError *error;
NSDictionary *resumeDictionary = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListMutableContainers format:NULL error:&error];
if (!resumeDictionary || error) return nil;
NSString *localTmpFilePath;
int download_version = [[resumeDictionary objectForKey:@"NSURLSessionResumeInfoVersion"] intValue];
if(download_version==1)
{
localTmpFilePath = [resumeDictionary objectForKey:@"NSURLSessionResumeInfoLocalPath"];
if ([localTmpFilePath length] < 1) return nil;
}
else if(download_version==2)
{
localTmpFilePath = [resumeDictionary objectForKey:@"NSURLSessionResumeInfoTempFileName"];
if ([localTmpFilePath length] < 1) return nil;
}
NSString *localCachePath;
NSString *localLastName = [localTmpFilePath lastPathComponent];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [paths objectAtIndex:0];
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if(version>=9.0)
{
return data;
}
else if(version>=8.0&&version<9.0)
{
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
NSString * _localCachePath = [[[cachesDir stringByAppendingPathComponent:@"com.apple.nsurlsessiond/Downloads"]stringByAppendingPathComponent:bundleIdentifier]stringByAppendingPathComponent:localLastName];
if([[NSFileManager defaultManager] fileExistsAtPath:_localCachePath])
localCachePath = _localCachePath;
NSString *temp = NSTemporaryDirectory();
temp = [temp stringByAppendingPathComponent:localLastName];
if([[NSFileManager defaultManager] fileExistsAtPath:temp])
localCachePath = localLastName;
}
else
{
localCachePath = [[cachesDir stringByAppendingPathComponent:@"com.apple.nsnetworkd"]stringByAppendingPathComponent:localLastName];
}
[resumeDictionary setValue:localCachePath forKey:@"NSURLSessionResumeInfoLocalPath"];
data = [NSPropertyListSerialization dataWithPropertyList:resumeDictionary format:NSPropertyListXMLFormat_v1_0 options:0 error:NULL];
return data;
}
网友评论