UIDocumentInteractionController not working in iPad Simulator (XCode 3.2.3)

限于喜欢 提交于 2019-11-29 11:32:35

Confirming the same behaviour over here: calling - (BOOL)presentPreviewAnimated: returns NO on the simulator but works on the device. Thanks for pointing this out, I just spent two hours going over my code again and again. Got no solution so far.

hatunike

I actually had this issue on iOS versions higher than iOS 4.2, even though this was a known bug back in the day.

The issue being that the UIDocumentInteractionController would act fine on the device, but in the simulator it would crash. What I discovered was that the problem went away when I managed the memory slightly differently. The difference being, autoreleasing in the DidEndPreview delegate method. Here's the core of my code :

-(void)createPDF
{
    UIDocumentInteractionController *dc;
    //....other code to generate pdf document
    dc = [[UIDocumentInteractionController interactionControllerWithURL:loadURL] retain];
    dc.delegate = self;

    [dc retain];

    [dc presentPreviewAnimated:YES];
}

//Delegate Methods
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
    [controller autorelease];
}

Previously I had handled simply created the document controller like a regular modal view and released it after I presented it.

NOTE : The autorelease is important, you will crash with just a regular release call.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!