UIDocumentInteractionController not working in iPad Simulator (XCode 3.2.3)

随声附和 提交于 2019-11-28 05:16:50

问题


The UIDocumentInteractionController appears to be non-functional in iPad Simulator ("iPhone Simulator" version 4.0, shipping with XCode 3.2.3, using iOS Version 3.2).

I have a simple sample code presenting a PDF preview using UIDocumentInteractionController. It works on the device. On iPad presentPreview just returns NO, the UIDocumentInteractionController's delegate methods are not invoked.

Any hint how to make it work?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3616981/uidocumentinteractioncontroller-not-working-in-ipad-simulator-xcode-3-2-3

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