Je développe une application iOS dans laquelle je dois partager une image sur WhatsApp depuis mon application. J'ai trouvé ce code mais il ne traite que du partage de text https://github.com/jberlana/JBWhatsAppActivity
Cela peut être possible en utilisant documentationInteractionController
. Récemment, je l'ai fait en utilisant le code ci-dessous pour partager l'image De notre application à WhatsApp, ligne, WeChat mais pendant que vous click l'icône WhatsApp, alors vous êtes application de navigation WhatsApp
de votre application et vous devez returnner l'application manuellement. Cela ne redirige pas à nouveau après ImageSharing.
dans le file .h: –
@interface ViewController : UIViewController<UIDocumentInteractionControllerDelegate> { } @property(nonatomic,retain) UIDocumentInteractionController *documentationInteractionController;
au format .m
- (IBAction)bocClick:(UIButton *)sender { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSSsortingng *documentsDirectory = [paths objectAtIndex:0]; NSSsortingng *getImagePath = [documentsDirectory ssortingngByAppendingPathComponent:@"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; }