尝试这个:
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if (url != nil && [url isFileURL]) {
FileNameStr = [url.lastPathComponent substringWithRange:NSMakeRange(0, url.lastPathComponent.length - url.pathExtension.length - 1)];
}
}
- (void)unzipAndSaveFile{
NSString*EpubFile=[NSString stringWithFormat:@"%@/%@.epub",[self applicationDocumentsDirectory],FileNameStr];
ZipArchive* za = [[ZipArchive alloc] init];
if( [za UnzipOpenFile:EpubFile] ){
NSString *strPath=[NSString stringWithFormat:@"%@/Unzipped/%@",[self applicationDocumentsDirectory],FileNameStr];
//Delete all the previous files
NSFileManager *filemanager=[[NSFileManager alloc] init];
if ([filemanager fileExistsAtPath:strPath]) {
[filemanager removeItemAtPath:strPath error:&error];
}
[filemanager release];
filemanager=nil;
//start unzip
BOOL ret = [za UnzipFileTo:[NSString stringWithFormat:@"%@/",strPath] overWrite:YES];
if( NO==ret ){
// error handler here
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Error"
message:@"An unknown error occured"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
alert=nil;
}
[za UnzipCloseFile];
}
[za release];
}
- (NSString *)applicationDocumentsDirectory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSLog(@"basePath:%@",basePath);
return basePath;}