2013-08-13 9 views
5

tôi gửi một email với tập tin đính kèm PDF, trong khi sử dụng UIDocumentInteractionController, như thế này:Làm cách nào tôi có thể đặt trường Tới và Chủ đề trong E-Mail được gửi bởi UIDocumentInteractionController?

tôi bắt đầu bằng cách hiển thị các tập tin PDF

-(void)showPDFFile 
{  
    NSURL *url = [NSURL fileURLWithPath:_filePath]; 

    if (url) { 
     _documentInteractionController = 
      [UIDocumentInteractionController interactionControllerWithURL:url]; 

     [_documentInteractionController setDelegate: self]; 
     [_documentInteractionController presentPreviewAnimated:YES]; 
    } 
} 


- (UIDocumentInteractionController *)setupControllerWithURL:(NSURL *)fileURL 
               usingDelegate:(id <UIDocumentInteractionControllerDelegate>)interactionDelegate { 

    UIDocumentInteractionController *interactionController = 
     [UIDocumentInteractionController interactionControllerWithURL: fileURL]; 

    [interactionController setDelegate: interactionDelegate]; 
    return interactionController; 
} 

Khi các tập tin PDF được hiển thị, người dùng nhấp vào Tùy chọn "Xuất" và chế độ xem "Mở bằng" của iOS sẽ xuất hiện.

Nhấp vào email ngay bây giờ sẽ mở Trình điều khiển chế độ xem sẵn sàng để gửi email.

Làm cách nào để đặt trường Tới: CC/BCC và Chủ đề theo chương trình?

Cảm ơn bạn!

+0

là bạn MFMailComposeViewController sử dụng để trình bày quan điểm email ?? – Suryakant

+0

Tôi không. UIDocumentInteractionController đang làm việc cho tôi! Tôi đoán UIDocumentInteractionController là đại biểu cho MFMailComposeViewController. Trong bất kỳ kịch bản nào khác, tôi sẽ được ủy quyền cho MFMailComposeViewController và xử lý mọi thứ từ đó. – nmdias

+3

Rất tiếc, API không hỗ trợ những gì bạn muốn. Lý tưởng nhất là bạn sẽ có thể sử dụng thuộc tính 'annotation' của' UIDocumentInteractionController' nhưng dường như nhà soạn thư không sử dụng thuộc tính (ít nhất là không có tài liệu nào cho biết có thể thực hiện được). – rmaddy

Trả lời

2

Bạn có thể gán chủ đề của email bằng cách sử dụng tài sản UIDocumentInteractionControllername:

_documentInteractionController.name = @"My custom mail subject"; 

Thật không may này là thuộc tính duy nhất mà tôi đã tìm ra rằng có thể được cấu hình thông qua UIDocumentInteractionController.

+0

Thật không may, điều này không hoạt động .. – GenieWanted

+0

@GenieWanted hoạt động cho tôi. –

0

Thật không may, câu trả lời của Florians không có tác dụng đối với tôi. Tôi đã phải sao chép các tập tin tại địa phương và sau đó thiết lập URL vào tập tin địa phương. Đặt tên chỉ thay đổi tiêu đề trên bản xem trước, không phải tên tệp hoặc chủ đề trong email.

ví dụ:

NSFileManager* fileManager = [NSFileManager defaultManager]; 

NSError* err = nil; 

NSString* newPath = [appDocumentsFolder stringByAppendingPathComponent:name]; 
if (![fileManager copyItemAtPath:[[NSURL URLWithString:path] path] toPath:newPath error:&err]) { 
    // handle error 
} 

NSURL *fileURL = [NSURL fileURLWithPath:newPath]; 

_controller = [UIDocumentInteractionController interactionControllerWithURL:fileURL];