2012-03-01 29 views
7

Tôi không tìm cách thêm ứng dụng của mình vào danh sách "đang mở trong ...", nhưng để tự lấy danh sách. Và gửi tệp đến ứng dụng khác.Cách sử dụng tính năng "mở trong ..." cho ứng dụng iOS?

Tôi đang làm việc trên ứng dụng thông tin nội bộ, vì vậy khi người dùng nhận được một tập tin đính kèm tập tin, anh/cô ta có thể mở tập tin với bất cứ điều gì ứng dụng được cài đặt trên mỗi thiết bị ...

Trả lời

11
UIDocumentInteractionController *controller = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:appFile]]; 
     self.controller.delegate = self; 
CGRect navRect = self.view.frame; 
[self.controller presentOptionsMenuFromRect:navRect inView:self.view animated:YES]; 

Thực hiện sau UIDocumentInteractionControllerDelegate phương pháp

#pragma mark - UIDocumentInteractionControllerDelegate 

//=================================================================== 
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller 
{ 
    return self; 
} 

- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller 
{ 
    return self.view; 
} 

- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller 
{ 
    return self.view.frame; 
} 
0

Một tùy chọn khác:

sử dụng UIActivityViewController như sẵn từ iOS 6.0 > phiên bản

//create instance with file URL 
UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:@[fileURLHere] applicationActivities:nil]; 
//present it 
[self presentViewController:activity animated:YES completion:NULL]; 

Note: Có thể có vấn đề sử dụng UIDocumentInteractionController. Kiểm tra uidocumentinteractioncontroller-stopped-working-ios-8

Các vấn đề liên quan