我无法调试此错误。单击Adobe或Nook作为所选应用程序以打开下载PDF后,我收到EXC_BAD_ACCESS错误。我已经完成了调试器,它在我编写的方法之外的地方打破了。这是有问题的代码。
//download protocol
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *storedEmail = [defaults stringForKey:@"email"];
NSString *storedPassword = [defaults stringForKey:@"password"];
NSString *projectID = self.study.ProjectID;
NSString *urlString = [NSString stringWithFormat:@"http://service.pharmatech.com/Document/projectprotocol/%@/%@/%@", storedEmail, storedPassword, projectID];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
if (data) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, [NSString stringWithFormat:@"Protocol_%@.pdf", projectID]];
[data writeToFile:filePath atomically:YES];
UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
docController.delegate = self;
docController.UTI = @"com.adobe.pdf";
self.navigationController.toolbarHidden = NO;
BOOL isValid = [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
NSLog([NSString stringWithFormat:@"DISPLAYED? %d", isValid]);
NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:NULL];
for (int count = 0; count < (int)[directoryContent count]; count++) {
NSLog(@"File %d: %@", (count + 1), [directoryContent objectAtIndex:count]);
}
[self.navigationController setToolbarHidden:YES animated:YES];
弹出窗口显示应用程序能够显示pdfs。单击一个后,出现Bad Access错误,但直到离开方法后才会调用,这只是一个按钮点击操作。
如果我运行应用程序没有调试器只是关闭我的应用程序并且什么都不打开。任何人都有任何提示。我对这个ios的东西还很新。
编辑:对于那些稍后访问并且不阅读评论的人,答案是UIDocumentInteractionController必须是实例变量,而不是本地变量。
答案 0 :(得分:2)
“docController”似乎是一个问题,是一个局部变量,我认为必须是一个实例变量。
更改
UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
的
docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
并在你的.h声明
UIDocumentInteractionController *docController;