Reputation: 3695
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...
(This is shared from Android)
Upvotes: 38
Views: 21924
Reputation: 11
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
Upvotes: 1
Reputation: 404
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
Upvotes: 17
Reputation: 962
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.
This is just a possible solution if you want text and image both.But if you want to share link with text than . . . . . . .
Upvotes: -3
Reputation: 138
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;
}
}
Upvotes: -5
Reputation: 11343
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://stackoverflow.com/a/20601051/2082569
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
Upvotes: -5