UIDocumentInteractionController prevent Airdrop in the 'Open in' sheet

社会主义新天地 提交于 2019-12-08 16:09:53

问题


In my app, I'm allowing users to share photos via Instagram, which requires the use of UIDocumentInteractionController. Airdrop is automatically detected if the phone supports it. How do I remove it from this ‘Open in’ action sheet?

Even if I begin the sharing process with a UIActivityViewController and call setExcludedActivityTypes:, eventually I must use a UIDocumentInteractionController, and when I do, Airdrop appears again. Here is the code when the share button gets tapped:

NSURL *instagramURL = [NSURL URLWithString:@"instagram://location?id=1"];

if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
    NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"Image.igo"];

    NSData *imageData = UIImagePNGRepresentation(imageToShare);
    [imageData writeToFile:savedImagePath atomically:YES];
    NSURL *imageUrl = [NSURL fileURLWithPath:savedImagePath];
    docController = [[UIDocumentInteractionController alloc] init];
    docController.UTI = @"com.instagram.exclusivegram";
    docController.URL = imageUrl;
    [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];

}
else
{
    NSLog(@"no insta");
}

回答1:


As far as I can tell you can't. I need to disable this option also. But on UIDocumentInteractionController it is completely inaccessible. Pretty bad API experience in my book.

If the user selects an App in the list your App gets the callbacks

-(void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application

-(void)documentInteractionController: (UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application

If the user selects AirDrop you don't get notified at all.




回答2:


This cannot be removed and apple is still trying to make airdrop accessible everywhere, so we might have to see that in few more places in future. From 7.1 update, it will for sure come in UIDocumentInteractionController irrespective of airdrop status(on or off on device)

And one more bad things is there is no callback for airdrop sharing, which means your app never knows about the sharing status. The below 2 delegate will not work for share.

-(void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application

-(void)documentInteractionController: (UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application

I hope apple will expose some delegate method to make this possible in future versions.



来源:https://stackoverflow.com/questions/19146924/uidocumentinteractioncontroller-prevent-airdrop-in-the-open-in-sheet

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