IOS version is 9, Xcode 7 and following code is not working. But it works with IOS version 8, Xcode 6.
I'm using codes below to download a file from server :
 NSURLSessionConfiguration *configuration;
if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] != NSOrderedAscending) {
    configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"Test"];
} else {
    configuration = [NSURLSessionConfiguration backgroundSessionConfiguration:@"Test"];
}
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://hw13.asset.aparat.com/aparat-video/e361693675a47fa4ae758756b40a11653215108-360p__71758.mp4"]];
NSProgress *progress;
NSURLSessionDownloadTask *downloadTask =   [manager downloadTaskWithRequest:request progress:&progress destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
    AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
    NSString *fileAddress = [[appDelegate GetDocumentDirectory] stringByAppendingPathComponent:@"Myfile.mp4"];
    return [NSURL fileURLWithPath:fileAddress];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
    if(error != nil){
        //ERROR
        [[NSFileManager defaultManager] removeItemAtPath:[filePath absoluteString]
                                                   error:nil];
        [progress removeObserver:self forKeyPath:@"fractionCompleted" context:NULL];
        [downloadTask cancel];
        return ;
    }
    //SUCCESS
    [progress removeObserver:self forKeyPath:@"fractionCompleted" context:NULL];
}];
[downloadTask resume];
[progress addObserver:self
           forKeyPath:@"fractionCompleted"
              options:NSKeyValueObservingOptionNew
              context:NULL];
keeps giving the error:
Error Domain=NSURLErrorDomain Code=-1 "unknown error" UserInfo={NSErrorFailingURLKey=http://hw13.asset.aparat.com/aparat-video/e361693675a47fa4ae758756b40a11653215108-360p__71758.mp4, NSLocalizedDescription=unknown error, NSErrorFailingURLStringKey=http://hw13.asset.aparat.com/aparat-video/e361693675a47fa4ae758756b40a11653215108-360p__71758.mp4}
here is GetDocuemntsD
-(NSString *)GetDocumentDirectory{
self.fileMgr = [NSFileManager defaultManager];
self.homeDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
return self.homeDir;
}
*** i can save images to the document directory, but i want to download video files in background and show the progress to the user but it keeps failing.
and my info.plist has:
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
 
     
     
    