How do I add a menu item to the share menu in iOS

2019-06-25 09:22发布

问题:

I'm just getting into iOS development, but something I'm going to have to do early on is add a button to the system menus like how Dropbox has added its button when interacting with email attachments.

This application will be for video so adding a button on the share menu for quicktime players would be ideal.

I've scoured the documentation and have only found the UIMenuItem class. Is this what I want or is there another way to implement this functionality?

回答1:

  1. Set project-info.plist -> add new item (UTExportedTypeDeclarations)

    <key>UTExportedTypeDeclarations</key>
    <array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>com.apple.quicktime-movie</string>
        </array>
        <key>UTTypeIdentifier</key>
        <string>com.company.project</string>
        <key>UTTypeTagSpecification</key>
        <dict/>
    </dict>
    </array>
    
  2. Coding your ButtonClick event in .m file

    -(IBAction)actionClick:(id)sender{
    
        UIDocumentInteractionController *documentController = 
              [UIDocumentInteractionController interactionControllerWithURL:
                                      [NSURL fileURLWithPath:MOVIE_FILE_PATH]];
        documentController.delegate = self;
        documentController.UTI = @"com.apple.quicktime-movie";
        [documentController presentOpenInMenuFromRect:CGRectZero 
                                               inView:self.view 
                                             animated:YES];
    }