当我使用此代码时,它会无限次下载。它不会停止下载。有谁知道这是为什么?
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *URL = [NSURL URLWithString:@"http://gps.com/2.js"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
// Save this following url to load the file
return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
NSLog(@"File downloaded to: %@", filePath);
}];
[downloadTask resume];
NSString *javaScript = [NSString stringWithContentsOfURL:URL encoding:NSUTF8StringEncoding error: nil];
[webView stringByEvaluatingJavaScriptFromString:javaScript];
使用此代码时也遇到同样的问题:
NSString *jsString = [NSString stringWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"PrivacyView" withExtension:@"js"] encoding:NSUTF8StringEncoding error:nil];
[_viewWeb stringByEvaluatingJavaScriptFromString:jsString];
NSLog(@"Way out of whack :(");
我发誓,这是我尝试加载javascript文件时的样子:
2017-05-28 00:03:23.724 App[81886:26511084] File downloaded to: file:///Users/App/Library/Developer/CoreSimulator/Devices/08B20943-5664-415C-87A6-1A6461C6338D/data/Containers/Data/Application/A31516E9-EDE2-4475-84AC-7AD12DE3558F/Documents/App.js
2017-05-28 00:03:25.197 App App[81886:26511084] Logged In?: Yes
2017-05-28 00:03:25.280 App App[81886:26511084] File downloaded to: file:///Users/App/Library/Developer/CoreSimulator/Devices/08B20943-5664-415C-87A6-1A6461C6338D/data/Containers/Data/Application/A31516E9-EDE2-4475-84AC-7AD12DE3558F/Documents/App.js
2017-05-28 00:03:26.188 App App[81886:26511084] Logged In?: Yes
2017-05-28 00:03:26.267 App App[81886:26511084] File downloaded to: file:///Users/App/Library/Developer/CoreSimulator/Devices/08B20943-5664-415C-87A6-1A6461C6338D/data/Containers/Data/Application/A31516E9-EDE2-4475-84AC-7AD12DE3558F/Documents/App.js
2017-05-28 00:03:27.570 App App[81886:26511084] Logged In?: Yes
2017-05-28 00:03:27.635 App App[81886:26511084] File downloaded to: file:///Users/App/Library/Developer/CoreSimulator/Devices/08B20943-5664-415C-87A6-1A6461C6338D/data/Containers/Data/Application/A31516E9-EDE2-4475-84AC-7AD12DE3558F/Documents/App.js
2017-05-28 00:03:28.885 App App[81886:26511084] Logged In?: Yes
2017-05-28 00:03:28.957 App App[81886:26511084] File downloaded to: file:///Users/App/Library/Developer/CoreSimulator/Devices/08B20943-5664-415C-87A6-1A6461C6338D/data/Containers/Data/Application/A31516E9-EDE2-4475-84AC-7AD12DE3558F/Documents/App.js
2017-05-28 00:03:30.254 App App[81886:26511084] Logged In?: Yes
我的意思是看它的运行次数。它只是一直被召唤,永远不会停止。