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
WhatsApp image sharing iOS [closed]
Asked Answered
Refer to this link: whatsapp.com/faq/en/iphone/23559013 –
Karinakarine
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;
}
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 –
Meldameldoh
first test this code using button click even –
Surbeck
@IronMan:
self.documentationInteractionController.UTI = @"net.whatsapp.image";
by this you are setting UTI ! No ? –
Stiltner 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 –
Surbeck
Can sharing be possible through UIActivityViewController –
Meldameldoh
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 :) –
Surbeck
Does this method open WhatsApp? I mean redirect the app? –
Masefield
@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? –
Masefield
Would you be so kind to share the UTI for WeChat and Line? thanks –
Muirhead
if you device installed wechat and line then you can also able to share with wechat or LINE as well –
Surbeck
It's possible to share image and text at the same time? –
Collogue
@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 –
Artur
© 2022 - 2024 — McMap. All rights reserved.