gpt4 book ai didi

IOS 在另一个应用程序中从我的应用程序打开 PDF EXC_BAD_ACCESS

转载 作者:行者123 更新时间:2023-11-29 10:59:21 26 4
gpt4 key购买 nike

我很难调试这个错误。在我单击 Adob​​e 或 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];

弹出窗口显示能够显示 pdf 的应用程序。在我单击其中一个后,出现了 Bad Access 错误,但直到离开调用它的方法后才发生,这只是一个按钮单击操作。

如果我在没有调试器的情况下运行应用程序,则只会关闭我的应用程序并且不会打开任何内容。任何人都有任何提示。我对这个 ios 的东西还是很陌生。

编辑:对于那些稍后访问它但不阅读评论的人来说,答案是 UIDocumentInteractionController 必须是一个实例变量,而不是本地变量。

最佳答案

这似乎是“docController”的问题,它是一个局部变量,我认为它必须是一个实例变量。

改变

UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];

对于

docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];

在你的 .h 中声明

UIDocumentInteractionController *docController;

关于IOS 在另一个应用程序中从我的应用程序打开 PDF EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16697581/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com