• 1
name Punditsdkoslkdosdkoskdo

Swift - Only share image with WhatsApp in ios

I'm implementing sharing in an application and I must be able to share with many applications, including WhatsApp

@objc static func shareItem(viewController: UIViewController, position: CGRect, item: [Any], subject: String) {

    // item = [image, title, content, signature]
    let activityVC = UIActivityViewController(activityItems: item, applicationActivities: nil)
    activityVC.popoverPresentationController?.sourceView = viewController.view
    activityVC.popoverPresentationController?.sourceRect = position
    activityVC.setValue(subject, forKey: "subject")

    viewController.present(activityVC, animated: true, completion: nil)

I know that WhatsApp does not allow text and image sharing at the same time, so I would only like to share the image.

The problem is that the function I use to share with WhatsApp is also used to share with all other applications, so I can't just leave the image alone in my table

Is there a way to detect that the user will share with WhatsApp and then only send the image?

Thank you in advance

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

  • 0
Reply Report

Related Questions

Trending Tags