0

サーバーからpdfファイルがあります。

次に、ファイルを NSDocument ディレクトリ パスにロードして正常に動作させる必要がありますが、各バイトを保存するために UIProgressView を表示したいと考えています。これを行う方法、私を助けてください

前もって感謝します

こんな感じで収納してみました。

            NSError *error;
            NSArray *ipaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *idocumentsDir = [ipaths objectAtIndex:0];
            NSString *idataPath = [idocumentsDir stringByAppendingPathComponent:@"File"];
            NSLog(@"idataPath:%@",idataPath);

            //Create folder here
            if (![[NSFileManager defaultManager] fileExistsAtPath:idataPath])
            {
                [[NSFileManager defaultManager] createDirectoryAtPath:idataPath withIntermediateDirectories:NO attributes:nil error:&error];
            }
  // Image Download here
            NSString *fileName = [idataPath stringByAppendingFormat:@"/image.jpg"];
            NSLog(@"imagePathDOWNLOAD:%@",fileName);

            NSData *pdfData1 = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[URLArray objectAtIndex:a]]];
            [pdfData1 writeToFile:fileName atomically:YES];
4

1 に答える 1

0

NSURLConnection クラスを使用して進行状況バーを実装できます。

.h:
NSMutableData *responseData;
NSString *originalFileSize;
NSString *downloadedFileSize;

.m:
- (void)load {
    NSURL *myURL = [NSURL URLWithString:@""];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL
                                                cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
                                         timeoutInterval:60];

[[NSURLConnection alloc] initWithRequest:request delegate:self];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
responseData = [[NSMutableData alloc] init];
originalFileSize = [response expectedContentLength];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];

downloadedFileSize = [responseData length];
progressBar.progress = ([originalFileSize floatValue] / [downloadedFileSize floatValue]);
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[responseData release];
[connection release];

}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
NSLog(@"Succeeded! Received %d bytes of data",[responseData lengtn]);

}

ご不明な点がございましたらお知らせください。

于 2013-03-28T06:32:13.380 に答える