HY,
在打开文档目录路径上的任何类型(xls,doc,ppt)文件时,iCloud Drive不存在。 iCloud服务和容器在Targets> Capabilities> iCloud中具有有效标识符。我正在使用UIDocumentInteractionController
打开文件。
-(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;
}