2014-12-18 209 views
3

我正在使用UIDocumentInteractionController與其他應用程序共享在我的應用程序中拍攝的圖像。 當您使用此功能與Instagram分享時,您可以使用包含密鑰@"InstagramCaption"的字典設置註釋屬性,該字典將預先填寫評論。UIDocumentInteractionController註釋屬性使用

我想知道是否有可能與其他應用程序做到這一點,如果是的話,字典的關鍵是什麼。

我主要對消息應用程序和郵件應用程序(標題和正文)感興趣,但是如果您知道允許進行文檔交互的其他應用程序的密鑰,它也會很棒(Facebook,Twitter,WhatsApp ,Path,Tumblr,...)。

這裏是我做的:

- (void)openImageInOtherApp:(UIImage *)image 
{ 
    NSError *error = nil; 
    NSURL *tempDirectoryURL = [NSURL fileURLWithPath:NSTemporaryDirectory()]; 
    NSURL *imageURL = [tempDirectoryURL URLByAppendingPathComponent:@"image.jpeg" isDirectory:NO]; 
    NSData *imageData = UIImageJPEGRepresentation(image, 0.8); 
    BOOL saveSucceeded = [imageData writeToURL:imageURL options:NSDataWritingAtomic error:&error]; 

    if (!saveSucceeded || error) { 
     NSLog(@"Error : Saving image %@ at URL %@ failed with error : %@", image, imageURL, error); 
     return; 
    } 

    UIDocumentInteractionController *interactionController = [[UIDocumentInteractionController alloc] init]; 
    interactionController.delegate = self; 
    interactionController.URL = imageURL; 
    NSString *comment = @"A test comment"; // A comment that will be sent along with the image 
    if (comment != nil && comment.length > 0) { 
     interactionController.annotation = @{@"someKey": comment}; 
    } 
    self.interactionController = interactionController; 

    BOOL canOpenDocument = [interactionController presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES]; 
    NSLog(@"canOpenDocument : %@", canOpenDocument ? @"YES" : @"NO"); 
} 

然後系統視圖出現在那裏我可以選擇一個應用程序,可以打開該文件。

+1

它只是在浪費時間 –

+0

您能否請您提供您當前的代碼樣本? – Yuyutsu

+0

我剛剛用我使用的代碼編輯了我的答案。代碼不是問題,但我不知道如何設置註釋詞典來發送評論與圖像。 – deadbeef

回答

1

閱讀API開發人員文檔(Facebook,Twitter,WhatsApp,Path,Tumblr,...)

  1. API developer facebook

    // Put together the dialog parameters

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
               @"Sharing Tutorial", @"name", 
               @"Build great social apps and get more installs.", @"caption", 
               @"Allow your users to share stories on Facebook from your app using the iOS SDK.", @"description", 
               @"https://developers.facebook.com/docs/ios/share/", @"link", 
               @"http://i.imgur.com/g3Qc1HN.png", @"picture", 
               nil]; 
    
  2. API developer twitter

  3. API developer tumblr

這可能會幫助你:)

+0

謝謝,但這並不能回答我的問題。我不想在Facebook或Twitter上使用API​​分享,但使用UIDocumentInteractionController。另外,正如我所提到的,我想知道如何爲Messages應用程序和郵件應用程序執行此操作,其餘部分僅僅是一項獎勵。 – deadbeef

0

UIDocumentInteractionController不會奇蹟般地支持所有這些平臺。其中一些使用API​​將爲您提供更多選擇。

查看this documentation爲郵件應用程序創建彩信。使用this documentation發送帶圖像附件的電子郵件。