UIActivityViewController & UIDocumentInteractionController not showing options

后端 未结 4 2230
青春惊慌失措
青春惊慌失措 2021-02-08 09:01

I am new to UIActivityViewController and perhaps I am missing a basic understanding. What I am trying to do is attached a csv, xml and vcard file to activity controller and show

4条回答
  •  萌比男神i
    2021-02-08 09:40

    For anyone interested in future, here's the code all in one place. Do rate it up if this helps.

    In your *.h file add this

    @interface v1BackupComplete : UIViewController 
    {
    
        UIDocumentInteractionController *docController;
    
    }
    

    In your *.m file add this

    /************************
     * Dropbox ACTION
     ************************/
    -(IBAction) dropBoxAction2
    {
        NSLog(@"dropBoxAction2 ...");
    
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ,YES);
        NSString* documentsPath = [paths objectAtIndex:0];
        NSMutableString *fileNameStr3 = [NSMutableString stringWithFormat:@"test_VCARD_Backup.vcf"];
        NSString* vcardDataFileStr = [documentsPath stringByAppendingPathComponent:fileNameStr3];
    
    
        NSURL *fileURL = [NSURL fileURLWithPath:vcardDataFileStr];
        docController = [self setupControllerWithURL:fileURL
                                       usingDelegate:self];
    
        bool didShow = [docController presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];
    
        NSLog(@"didShow %d ...", didShow);
    
        if (!didShow)
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR"
                                                            message:@"Sorry. The appropriate apps are not found on this device."
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles: nil];
            [alert show];
        }
    }
    
    
    #pragma mark - UIDocumentInteractionControllerDelegate
    - (UIDocumentInteractionController *) setupControllerWithURL:(NSURL *)fileURL
                                                   usingDelegate:(id )         interactionDelegate {
    
        UIDocumentInteractionController *interactionController =
        [UIDocumentInteractionController interactionControllerWithURL:fileURL];
        interactionController.delegate = interactionDelegate;
    
        return interactionController;
    }
    
    - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller
    {
        return self;
    }
    
    - (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller
    {
        return self.view;
    }
    
    - (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller
    {
        return self.view.frame;
    }
    

提交回复
热议问题