iOS share image AND text to WhatsApp
Asked Answered
P

5

38

I have googled, and get some solutions, it seems the only possible way is thru UIDocumentInteractionController. I have found the result that able to share text ONLY, also found result that share image ONLY.

But what I want is share BOTH.

I know this question may be duplicated, I just wanted to make it clear, here is the screenshot...

WhatsApp share image + text

(This is shared from Android)

Potomac answered 20/4, 2015 at 7:39 Comment(10)
Did you find any solution for this?Penalize
@VishnuKumar.S no, I didn't find the solutionPotomac
I am also finding the solution for this question.Coarse
As of now it is not possible on iOS. WhatsApp simply ignores the text if a image is present. It doesn't on Android, which means it is intentional by WhatsApp.Diphthongize
whatsapp.com/faq/en/iphone/23559013 They have mentioned that only independent text is shared.For images,video,audio use documentation controller.So cannot attach text with media type.Diorite
After iOS 8.0,UIActivityViewController is supporting whatsapp share. In this both Image or Video and Caption can shareMabellemable
@RajeshBalam Can you please let me know how to do this?Califate
@JsLim can you get solution for that than please? help me.Song
Can any one know how to share image , text and app url i tried UIActivityViewController but it isn't work for these.Cruse
UIActivity controller also share the text and url but not share my app imageCruse
R
17

You can use UIActivityViewController to share image , text or URL .Here is a small example :

NSString *textToShare = @"Enter your text to be shared";
UIImage * image = [UIImage imageNamed:@"imagename"];

NSArray *objectsToShare = @[textToShare, image];

UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];


[self presentViewController:activityVC animated:YES completion:nil];

Run the above code and select whats app to share if you want you can share by other mediums also . This is apple' s default share method

Redbud answered 2/3, 2016 at 11:15 Comment(8)
in this way "textToShare" string not share in whats app...so, that's not working for me...Strobile
Its working fine, But image only sharing not content.Honour
Can we use this with Swift 2?Slapdash
@MarcLemien You can try this code : let shareText = "Hello, world!" if let image = UIImage(named: "myImage") { let vc = UIActivityViewController(activityItems: [shareText, image], applicationActivities: []) presentViewController(vc, animated: true, completion: nil) }Redbud
One workaround i was thinking of, we can copy the caption to clipboard and ask the user to manually paste it in the Whatsapp caption textfield. Doesn't serve the actual purpose but can be a valid workaround.Epigraphy
image or text share, both sharing is not possiblePierson
@Cruse you or anyone able to do this?Slashing
this answer seems to be incorrect, There is no way image and text are sharing using uactivitycontroller. Can any one please shed some light on this.Dace
M
1

something not usually mentioned the user doesn't actually needs to share a text message and an image.

If your text contains URL then the whatsapp application will try to retrieve info about the URL and show a preview

In order for this to work you need to make the URL conform to open graph protocol. that basically means that the URL needs to have meta tags in its DOM which contain the relevant preview data

Minta answered 19/7, 2016 at 19:39 Comment(1)
But for that, the user will have to integrate the image in the meta-tags of the website. With this method, the user will only get the image of the website, not the actual product in this case.Epigraphy
B
-3

Good one,

As I know it is not possible in ios. But I am having an alternate solution for it by which you can share text and image both.But it's a tricky or I think stupid solution.

  1. Create a View where you can put your image.Write text on that view whatever you want to write.
  2. Take Screen shot of that view with help of code.You will get image (image of view where text and image added).
  3. Just share that image via document interaction controller.

This is just a possible solution if you want text and image both.But if you want to share link with text than . . . . . . .

Baneberry answered 8/12, 2015 at 7:11 Comment(2)
Taking into consideration font style possible difference, screens resolution, font sizes this is not going to work as expectedSclaff
Just try it with all possible resolutions.you will find a great resultsBaneberry
J
-5

You can use UIDocumentInteractionController for this purpose like this:

@property (retain) UIDocumentInteractionController * documentInteractionController;


if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){

    UIImage     * iconImage = [UIImage imageNamed:@"YOUR IMAGE"];
    NSString    * savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];

    [UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];

    _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
    _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:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}

Check this answer for reference: https://mcmap.net/q/328813/-share-image-text-through-whatsapp-in-an-ios-app

Also you can have a look at Socialize SDK that is also very easy to use and integrates with various social SDKs. Check this documentation for Whatsapp sharing: http://socialize.github.io/socialize-sdk-ios/whatsapp.html

Jardiniere answered 20/4, 2015 at 9:20 Comment(1)
I don't see property that set the message. The code above I already tested many times, only can share image. My question is HOW TO SHARE BOTH IN A SINGLE SHAREPotomac
B
-5

Please check below project on github

https://github.com/salesawagner/SharingWhatsApp

typedef enum{
    kSendText = 0,
    kSendImage,
    kSendTextWithImage,
    kSendAudio,
    kSendCancel
} options;
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    switch (buttonIndex) {
        case kSendText:
            [[WASWhatsAppUtil getInstance] sendText:@"Text"];
            break;
        case kSendImage:
            [[WASWhatsAppUtil getInstance] sendImage:[UIImage imageNamed:@"image.jpg"] inView:self.view];
            break;
        case kSendTextWithImage:
            NSLog(@"Send text with image");
        case kSendAudio:
            [[WASWhatsAppUtil getInstance] sendAudioinView:self.view];
            break;
        default:
            NSLog(@"Cancel send");
            break;
    }

}
Brooking answered 7/12, 2015 at 10:1 Comment(1)
Improve your descriptionAlaniz

© 2022 - 2024 — McMap. All rights reserved.