2

Hy,

iCloud Drive is absent while open any type(xls,doc,ppt) of file written on a path at document directory. iCloud services and containers have valid identifier at Targets>Capabilities>iCloud. I am using UIDocumentInteractionController to open the file.

-(NSString *)getFilePath
 {
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];

  NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,messageobj.attachments.displayName];
  return filePath;
}

 -(void)rightButtonPressedInChatPreview:(id)sender
  {
    NSURL *fileURL = [NSURL fileURLWithPath:[self getFilePath]];
    docController = [self setupControllerWithURL:fileURL
                                   usingDelegate:self];

    bool didShow = [docController presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];
    if (!didShow)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                        message:@"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 <UIDocumentInteractionControllerDelegate>)         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;
}

enter image description here

Ketan Shinde
  • 1,847
  • 4
  • 18
  • 38

0 Answers0