Is it possible to share images, text or whatever you want through Whatsapp in a iOS app? I'm searching on google but I only found results talking about Android implementations.
12 Answers
Is now possible in this way:
Send Text - Obj-C
NSString * msg = @"YOUR MSG";
NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",msg];
NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
} else {
// Cannot open whatsapp
}
Send Text - Swift
let msg = "YOUR MSG"
let urlWhats = "whatsapp://send?text=\(msg)"
if let urlString = urlWhats.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) {
if let whatsappURL = NSURL(string: urlString) {
if UIApplication.sharedApplication().canOpenURL(whatsappURL) {
UIApplication.sharedApplication().openURL(whatsappURL)
} else {
// Cannot open whatsapp
}
}
}
Send Image - Obj-C
-- in .h file
<UIDocumentInteractionControllerDelegate>
@property (retain) UIDocumentInteractionController * documentInteractionController;
-- in .m file
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];
}
Send Image - Swift
let urlWhats = "whatsapp://app"
if let urlString = urlWhats.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) {
if let whatsappURL = NSURL(string: urlString) {
if UIApplication.sharedApplication().canOpenURL(whatsappURL) {
if let image = UIImage(named: "image") {
if let imageData = UIImageJPEGRepresentation(image, 1.0) {
let tempFile = NSURL(fileURLWithPath: NSHomeDirectory()).URLByAppendingPathComponent("Documents/whatsAppTmp.wai")
do {
try imageData.writeToURL(tempFile, options: .DataWritingAtomic)
self.documentInteractionController = UIDocumentInteractionController(URL: tempFile)
self.documentInteractionController.UTI = "net.whatsapp.image"
self.documentInteractionController.presentOpenInMenuFromRect(CGRectZero, inView: self.view, animated: true)
} catch {
print(error)
}
}
}
} else {
// Cannot open whatsapp
}
}
}
Because a new security feature of iOS 9, you need add this lines on .plist file:
<key>LSApplicationQueriesSchemes</key> <array> <string>whatsapp</string> </array>
More information about url sheme: https://developer.apple.com/videos/play/wwdc2015-703/
I did not find a single solution for both. More information on http://www.whatsapp.com/faq/en/iphone/23559013
I made a small project to help some. https://github.com/salesawagner/SharingWhatsApp

- 1,448
- 2
- 10
- 14
-
is it possible to integrate whatsapp with android application – BeingMIAkashs Dec 18 '13 at 05:50
-
can text be sent to specific number via whatsapp? means no need to pick contact from whats app contact list ? – Kalpesh Lakhani Feb 13 '14 at 06:50
-
You need to have "ID Address Book" to associate with a contact, simply add the parameter "abid =
". I do not know to send directly to the phone number, but I'm looking for a solution. The link has a better explanation. http://www.whatsapp.com/faq/en/iphone/23559013 – Wagner Sales Feb 13 '14 at 18:49 -
The whole "if ([self.delegate respondsToSelector:@selector(imageCompartilhar)]) {" seems to be redundant. Other than this it works, – Vaiden Apr 06 '14 at 13:41
-
1@vaiden, you're right about the "if ([self.delegate respondsToSelector: @ selector (imageCompartilhar)]) {" I put because I get the image of my delegate. something like "UIImage * iconImage = [_delegate imageCompartilhar];" – Wagner Sales Jul 02 '14 at 15:33
-
1Is it possible to come back to the app after message is sent – Imran Sep 01 '14 at 13:04
-
3Can we send both(text and image) at a time? – Sudhakar Nov 21 '14 at 07:41
-
3Thanks. But sharing image and text at the same time? And how to go back to previous application. – Bagusflyer Apr 30 '15 at 03:55
-
@bagusflyer i'm looking for the same answer too. By the way, `CGRectMake(0, 0, 0, 0)` can be replaced by `CGRectZero`. – Raptor Jun 09 '15 at 05:22
-
when I select whatsapp from iOS native share sheet , it gives me the following alert "pease launch whatsapp from the home screen before continuing." Is there any option to share text on whatsapp from native share sheet ? – Sushil Sharma Jan 28 '16 at 07:57
-
@Wagner Sales Does it give both options: 'WhatsApp' & 'Import with WhatsApp'? – BaSha Jan 27 '17 at 13:20
-
Any help to send gif? – iYoung Mar 16 '17 at 12:42
-
I have no idea @iYoung, maybe by native share. – Wagner Sales Mar 17 '17 at 13:25
-
@WagnerSales thanks it helped me, also update the answer to current swift version. – Sunny Jun 15 '17 at 06:36
-
Is there any character count? – Vaibhav Jhaveri Oct 04 '17 at 08:51
-
Is there a way to send image without using UIDocumentInteractionController. like we can do in instagram? – Iraniya Naynesh Sep 10 '19 at 10:17
It is now possible. Have not tried yet though.
The latest release notes for whatsapp indicate that you can through the share extension:
WhatsApp accepts the following types of content:
- text (UTI: public.plain-text)
- photos (UTI: public.image)
- videos (UTI: public.movie)
- audio notes and music files (UTI: public.audio)
- PDF documents (UTI: com.adobe.pdf)
- contact cards (UTI: public.vcard)
- web URLs (UTI: public.url)

- 91,618
- 3
- 107
- 122

- 411
- 5
- 9
-
2its not possible its just open the app but not share the image etc...:) – Rushabh Sep 12 '13 at 05:23
-
The above link is good. This is now possible. This should become the best answer. – Yoav Shapira Feb 21 '14 at 17:09
-
2The above link does not allow for sharing of media to Whatsapp without displaying the menu. You must always show the document controller's menu before going to Whatsapp, which is a pain in the ass. – user3344977 Mar 01 '16 at 04:45
-
PDF documents (UTI: com.adobe.pdf) -> has problems while sharing. If I create pdf on the code, store it on documentdirectory and try to share it on whatsapp, it fails. I think whatsapp wants a pdf file that has a type of Adobe pdf i.e. has UTI com.adobe.pdf only – Kaan Esin Sep 28 '18 at 07:04
-
1@Adel: How we have to set this UTI in UIActivityViewController???? – Abhishek Thapliyal Jul 30 '20 at 11:18
No this is not possible, whatsapp does not have any public API you can use.
Please note that this answer is correct for 2011 when there was no API for WhatsApp.
Now there is an api available for interacting with WhatsApp: http://www.whatsapp.com/faq/en/iphone/23559013
The Objective-C call to open one of these URLs is as follows:
NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Hello%2C%20World!"];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
}

- 16,304
- 7
- 99
- 130

- 69,092
- 8
- 134
- 166
-
1now any api for this, please help me, i have spend more time for this – SampathKumar May 28 '13 at 09:03
-
1
-
You can talk to the whatsapp app using url schemes! See @Wagner Sales answer. – JHSnows Dec 16 '13 at 18:56
-
1
-
-
@Suragch can't delete the answer since it is accepted as an answer and see no need why I should expanded it. – rckoenes Nov 23 '15 at 09:37
-
What will this code do if the user doesn't have whatsapp installed? – Adil Malik Apr 14 '17 at 18:27
-
-
This is the correct code for share link to whats app users.
NSString * url = [NSString stringWithFormat:@"http://video...bla..bla.."];
url = (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef) url, NULL,CFSTR("!*'();:@&=+$,/?%#[]"),kCFStringEncodingUTF8));
NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",url];
NSURL * whatsappURL = [NSURL URLWithString:urlWhats];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
} else {
// can not share with whats app
}

- 81
- 1
- 1
Simple code and Sample code ;-)
Note:- You can only share text or image, both sharing together in whatsApp is not working from whatsApp side
/*
//Share text
NSString *textToShare = @"Enter your text to be shared";
NSArray *objectsToShare = @[textToShare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
*/
//Share Image
UIImage * image = [UIImage imageNamed:@"images"];
NSArray *objectsToShare = @[image];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
[self presentViewController:activityVC animated:YES completion:nil];
For Swift 4 - Works fine
delclare
var documentInteractionController:UIDocumentInteractionController!
func sharePicture() {
let urlWhats = "whatsapp://app"
if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) {
if let whatsappURL = NSURL(string: urlString) {
if UIApplication.shared.canOpenURL(whatsappURL as URL) {
let imgURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let fileName = "yourImageName.jpg"
let fileURL = imgURL.appendingPathComponent(fileName)
if let image = UIImage(contentsOfFile: fileURL.path) {
if let imageData = image.jpegData(compressionQuality: 0.75) {
let tempFile = NSURL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Documents/yourImageName.jpg")
do {
try imageData.write(to: tempFile!, options: .atomicWrite)
self.documentInteractionController = UIDocumentInteractionController(url: tempFile!)
self.documentInteractionController.uti = "net.whatsapp.image"
self.documentInteractionController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
} catch {
print(error)
}
}
}
} else {
// Cannot open whatsapp
}
}
}
}
Do not forget to edit the .plist with the following lines
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
</array>
Enjoy!!!

- 3,048
- 30
- 19
-
1This doesn't open whatsapp directly, this opens the document interaction view. Any way to open directly whatsapp? – DanielZanchi May 23 '22 at 10:27
Swift 3 version of Wagner Sales' answer:
let urlWhats = "whatsapp://app"
if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) {
if let whatsappURL = URL(string: urlString) {
if UIApplication.shared.canOpenURL(whatsappURL) {
if let image = UIImage(named: "image") {
if let imageData = UIImageJPEGRepresentation(image, 1.0) {
let tempFile = NSURL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Documents/whatsAppTmp.wai")
do {
try imageData.write(to: tempFile!, options: .atomic)
self.documentIC = UIDocumentInteractionController(url: tempFile!)
self.documentIC.uti = "net.whatsapp.image"
self.documentIC.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
}
catch {
print(error)
}
}
}
} else {
// Cannot open whatsapp
}
}
}

- 3,545
- 2
- 29
- 33
Swift 4
let urlWhats = "whatsapp://app"
if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlHostAllowed) {
if let whatsappURL = URL(string: urlString) {
if UIApplication.shared.canOpenURL(whatsappURL) {
if let imageData = UIImageJPEGRepresentation(image, 1.0) {
let tempFile = NSURL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent("Documents/whatsAppTmp.wai")!
do {
try imageData.write(to: tempFile, options: .atomic)
self.documentController = UIDocumentInteractionController(url: tempFile)
self.documentController.uti = "net.whatsapp.image"
self.documentController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
} catch {
print(error)
}
}
} else {
let ac = UIAlertController(title: "MessageAletTitleText".localized, message: "AppNotFoundToShare".localized, preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OKButtonText".localized, style: .default))
present(ac, animated: true)
print("Whatsapp isn't installed ")
// Cannot open whatsapp
}
}
}

- 11,242
- 5
- 69
- 122
WhatsApp provides two ways for your iPhone app to interact with WhatsApp:
- Through a custom URL scheme
- Through the iOS Document Interaction API
For more information Visit this link
Thanks.

- 599
- 9
- 21
Yes it's possible :
NSMutableArray *arr = [[NSMutableArray alloc]init];
NSURL *URL = [NSURL fileURLWithPath:path];
NSString *textToShare = [NSString stringWithFormat:@"%@ \n",_model.title];
NSString *SchoolName= [[AppUtility sharedUtilityInstance]getAppConfigInfoByKey:@"SchoolName" SecondKeyorNil:Nil];
[arr addObject:textToShare];
[arr addObject:URL];
[arr addObject:_model.body];
[arr addObject:SchoolName];
TTOpenInAppActivity *openInAppActivity = [[TTOpenInAppActivity alloc] initWithView:_parentController.view andRect:((UIButton *)sender).frame];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:arr applicationActivities:@[openInAppActivity]];
// Store reference to superview (UIActionSheet) to allow dismissal
openInAppActivity.superViewController = activityViewController;
// Show UIActivityViewController
[_parentController presentViewController:activityViewController animated:YES completion:NULL];

- 31
- 5
Swift 3 version for sending text:
func shareByWhatsapp(msg:String){
let urlWhats = "whatsapp://send?text=\(msg)"
if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
if let whatsappURL = NSURL(string: urlString) {
if UIApplication.shared.canOpenURL(whatsappURL as URL) {
UIApplication.shared.openURL(whatsappURL as URL)
} else {
let alert = UIAlertController(title: NSLocalizedString("Whatsapp not found", comment: "Error message"),
message: NSLocalizedString("Could not found a installed app 'Whatsapp' to proceed with sharing.", comment: "Error description"),
preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("Ok", comment: "Alert button"), style: UIAlertActionStyle.default, handler:{ (UIAlertAction)in
}))
self.present(alert, animated: true, completion:nil)
// Cannot open whatsapp
}
}
}
}
Also, you need to add whatsapp
to LSApplicationQueriesSchemes
in your Info.plist

- 1,579
- 3
- 28
- 53

- 2,232
- 28
- 18
NSString *shareText = @"http:www.google.com";
NSArray *objectsToShare = @[shareText];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
if (isIphone)
{
[self presentViewController:activityVC animated:YES completion:nil];
}
else {
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVC];
[popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

- 13,035
- 13
- 56
- 62

- 1,090
- 7
- 7
-
5You need to add some explanation. Why do you think this code works? How is it different from earlier answers? – default locale Mar 02 '17 at 09:04