我有以下代码来下载PDF文件:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if(connection != theConnection) return;
NSFileManager * FM = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
saveDownLoad = documentsDirectory;
NSString * bookNameInfo = [NSString stringWithFormat:@"%@.%@",@"BookName",@"pdf"];
NSString *downloadPath = [documentsDirectory stringByAppendingPathComponent:bookNameInfo];
[[Utility sharedSingleton] setBookDirectURL:downloadPath];
if([FM createFileAtPath:downloadPath contents:downLoadData attributes:nil])
{
[downLoadView close];
UIAlertView * saveAlert = [[UIAlertView alloc] initWithTitle:@"DownLoad Success"
message:@"DownLoad The end ."
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK",@"open PDF",nil];
[saveAlert show];
[saveAlert release];
[self.view removeFromSuperview];
}
if(downLoadData)
{
[downLoadData release];
}
}
and if(click button) => open PDF File (use other app)
-(void)showSelectMenu
{
NSString * stringText = [[NSBundle mainBundle] pathForResource:@"BookName" ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:stringText];
UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:url];
docController.delegate = self;
[docController retain];
[docController presentOpenInMenuFromRect:CGRectMake(0.0, 144.0, 100.0, 200.0) inView:self.view animated:YES];
}
但该程序无法显示 PDF文件。
如果播放showSelectMenu关闭程序;;
为什么关机程序?我不知道;;