1

このエラーのデバッグが困難です。選択したアプリとして 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のものに非常に慣れていません。

EDIT : 後でこれにアクセスしてコメントを読まない人にとって、答えは UIDocumentInteractionController がローカルではなくインスタンス変数でなければならないということです。

4

1 に答える 1