2014-11-23 991 views
15

我已經使用上了WhatsApp共享圖像下面的代碼,但我無法設置使用下面的代碼的標題文字。如何在iphone上分享whatsapp上的圖片+文字說明(URL)?

我已經試過的UIDocumentInteractionController註釋財產,但在WhatsApp的開發形式沒有任何鍵被註解指定。

我知道我們可以通過UIImageGraphicContext做到這一點,但我需要共享URL作爲標題

if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]) 
{ 
    NSString * savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"]; 

    [UIImageJPEGRepresentation([UIImage imageNamed:@"Convenor- image-SURANA1.png"], 1.0) writeToFile:savePath atomically:YES]; 

    _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]]; 
    _documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"wwww.google.com" forKey:@"whatsappCaption"]; 

    _documentInteractionController.UTI = @"net.whatsapp.image"; 
    _documentInteractionController.delegate = self; 

    [_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES]; 

} else { 
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Alert." message:@"Por favor, instale Whatsapp." delegate:nil cancelButtonTitle:@"Está bem" otherButtonTitles:nil]; 
    [alert show]; 
} 
+0

我沒有看到[iOS開發人員專用的WhatsApp FAQ]任何明顯的(http://www.whatsapp.com/faq/en/iphone/23559013)。您可能需要[通過[email protected]發送電子郵件給他們的產品支持](http://www.whatsapp.com/contact/)。 – 2014-11-23 12:54:45

+0

謝謝,我已經郵寄支持,但無法得到他們的回覆。最後我做到我有共同文字圖片URL,這樣圖片將可在該圖像的URL路徑 – Bhavik 2014-11-26 19:20:17

回答

1
NSError *error  = nil; 
NSURL *documentURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:&error]; 

UIImage *image  = [UIImage imageNamed:@"share.png"]; 
NSURL *tempFile = [documentURL URLByAppendingPathComponent:@"whatsAppTmp.wai"]; 
NSData *imageData = UIImageJPEGRepresentation(image, 1.0); 

NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 

NSLog(@"%@",docDir); 
NSLog(@"saving png"); 

NSString *pngFilePath = [NSString stringWithFormat:@"%@/test.png",docDir]; 
NSData *data1 = [NSData dataWithData:UIImageJPEGRepresentation(image,1.0)]; 
[data1 writeToFile:pngFilePath atomically:YES]; 
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:pngFilePath]]; 
_documentInteractionController.delegate = self; 
_documentInteractionController.UTI = @"net.whatsapp.image"; 

[_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES]; 
4

你不能預先填寫標題,而在WhatsApp的分享圖像。 Facebook也已經棄用了Facebook的這一功能。

您可以發送文本或圖像。但以編程方式預填字幕是不可能的。

在問題的代碼是罰款發送圖像。爲了發送純文本可以使用下面提及鏈接的參考:

http://www.whatsapp.com/faq/en/iphone/23559013

注意:編程設置標題是不可能的。

希望這有助於!

enter image description here

+0

Facebook和Twitter允許發佈網址一招。他們從網址獲取圖片和標題。你怎麼用whatsapp做到這一點? – Luda 2015-09-24 14:10:03

+0

你對Fb和Twitter很對。但是,Facebook,Instagram,WhatsApp不會允許使用預先填充的文本/標題。我已經上傳了WhatsApp圖片+標題共享的截圖。 – 2015-09-24 14:24:25

+0

如果你只是想發送一個鏈接,那麼你可以通過使用我的答案中的網址。但請確保代替該共享網址,該網址中的圖片和標題不會自動填充。在whatsapp中,共享網址只會顯示爲超鏈接。希望這能回答你的問題。 – 2015-09-24 14:36:41

相關問題