How to download an epub file locally to our iPhone?

青春壹個敷衍的年華 提交于 2019-12-01 11:05:49

问题


I want to download an epub file in to my app locally by passing the url of the file:

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

Clicking this url should download an epub. How can I get it to download to my app?

I tried using NSData but it didn't work. I also tried copying the file to my document directory but it also didn't work. Can anybody tell me how can I do this in Objective-C?

Any help code would be appreciated!

Thanks for any help.


回答1:


EPUB is a ZIP format, you can use any Binary Stream Downloading method and save the file first as a binary file on iPhone.




回答2:


AS arcon Mentioned EPUB is a ZIP format, You have to Unzip the file to unzip the file & save the documents directory to ur machine: 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];


来源:https://stackoverflow.com/questions/1534756/how-to-download-an-epub-file-locally-to-our-iphone

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!