I am developing an iOS application in which i have to share image on WhatsApp from my application. I found this code but it deals with only text sharing https://github.com/jberlana/JBWhatsAppActivity
Asked
Active
Viewed 9,668 times
8
-
Refer to this link: http://www.whatsapp.com/faq/en/iphone/23559013 – Parth Bhatt Dec 09 '13 at 12:32
1 Answers
8
That can be Possible using documentationInteractionController
.
Recently I have done this using bellow code to share image From our App to whatsApp, Line, WeChat but while you click on WhatsApp icon, then you are navigation WhatsApp
app from you app and you must return you app manually. That does not redirect again after ImageSharing.
in .h file:-
@interface ViewController : UIViewController<UIDocumentInteractionControllerDelegate>
{
}
@property(nonatomic,retain) UIDocumentInteractionController *documentationInteractionController;
in .m file
- (IBAction)bocClick:(UIButton *)sender {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"]; //here i am fetched image path from document directory and convert it in to URL and use bellow
NSURL *imageFileURL =[NSURL fileURLWithPath:getImagePath];
NSLog(@"imag %@",imageFileURL);
self.documentationInteractionController.delegate = self;
self.documentationInteractionController.UTI = @"net.whatsapp.image";
self.documentationInteractionController = [self setupControllerWithURL:imageFileURL usingDelegate:self];
[self.documentationInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
}
- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL
usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
self.documentationInteractionController =
[UIDocumentInteractionController interactionControllerWithURL: fileURL];
self.documentationInteractionController.delegate = interactionDelegate;
return self.documentationInteractionController;
}

Armel Larcier
- 15,747
- 7
- 68
- 89

Nitin Gohel
- 49,482
- 17
- 105
- 144
-
Where are we setting the UTI for UIDocumentInteractionController in this piece of code. Because once these 2 lines self.documentationInteractionController.UTI = @"net.whatsapp.image"; self.documentationInteractionController = [self setupControllerWithURL:imageFileURL usingDelegate:self]; overwrite it – IronMan Dec 06 '13 at 06:11
-
-
1@IronMan: `self.documentationInteractionController.UTI = @"net.whatsapp.image";` by this you are setting UTI ! No ? – Maulik Dec 06 '13 at 06:25
-
actually i use this above code in my project and i test it well and i can able to share image. this is working code i dont understand where did you stuck – Nitin Gohel Dec 06 '13 at 06:27
-
2
-
i dont think that will be possibel wia UIactivityViewcontroller but i m not sure if some one done using this.. i done using above one :) – Nitin Gohel Dec 06 '13 at 06:45
-
-
@NitinGohel I am not sure how it works. I know how works url scheme. Is this the same one. Or it is some internal feature. Will app open WhatsApp in your case? – Matrosov Oleksandr Feb 04 '14 at 06:23
-
-
if you device installed wechat and line then you can also able to share with wechat or LINE as well – Nitin Gohel May 08 '14 at 04:45
-
-
@Nitin Gohel in iOS 9 not working. in this code in ios 9 1)open Share Actionsheet 2) display Whatsapp icon . and than i click on this icon than display contact list for 1-2 second and than dismiss the contactView automatically. so bro. Guide me and help me – ramesh bhuja Apr 22 '16 at 14:45