如何在本地下载epub文件到你的iPhone?

时间:2009-10-07 23:22:54

标签: iphone epub

我想通过传递文件的网址将epub文件下载到我的应用程序中:

http://www.jedisaber.com/eBooks/books/sample.epub

点击此网址应下载一个epub。如何将其下载到我的应用程序?

我尝试使用NSData,但它没有用。我也尝试将文件复制到我的文档目录,但它也没有用。谁能告诉我怎么能在Objective-C中做到这一点?

任何帮助代码都将不胜感激!

感谢您的帮助。

2 个答案:

答案 0 :(得分:2)

EPUB是一种ZIP格式,您可以使用任何二进制流下载方法,并将该文件首先保存为iPhone上的二进制文件。

答案 1 :(得分:0)

AS arcon提到EPUB是一种ZIP格式,您必须解压缩该文件 解压缩文件&将文档目录保存到ur机器: ZipArchive * za = [[ZipArchive alloc] init];     if([za UnzipOpenFile:[[NSBundle mainBundle] pathForResource:@“Help”ofType:@“epub”]]){

    NSString *strPath = [NSString stringWithFormat:@"%@/UnzippedEpub",[self applicationDocumentsDirectory]];

    //Delete all the previous files
    NSFileManager *filemanager = [[NSFileManager alloc] init];
    if ([filemanager fileExistsAtPath:strPath]) {
        NSError *error;
        [filemanager removeItemAtPath:strPath error:&error];
    }
    [filemanager release];
    filemanager = nil;

    //start unzip
    [za UnzipFileTo:strPath overWrite:YES];
    NSLog(@"path : %@",strPath);
}                   
[za release];
相关问题