Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save christianselig/b272af7bb329e1db7d9d74b940f08900 to your computer and use it in GitHub Desktop.
Save christianselig/b272af7bb329e1db7d9d74b940f08900 to your computer and use it in GitHub Desktop.
import UIKit
class RootViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let text = "Cute cat"
let image = UIImage(named: "cat.jpg")!
// Note: you can't wrap the text and image into a single "TextImage" object and selectively return both or one as UIActivityItemSource doesn't like holding arrays
let activityViewController = UIActivityViewController(activityItems: [image, OptionalTextActivityItemSource(text: text)], applicationActivities: nil)
navigationController?.present(activityViewController, animated: true, completion: nil)
}
}
class OptionalTextActivityItemSource: NSObject, UIActivityItemSource {
let text: String
init(text: String) {
self.text = text
}
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
return text
}
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
if activityType?.rawValue == "net.whatsapp.WhatsApp.ShareExtension" {
return nil
} else {
return text
}
}
}
@dipeshpatel7733-hub
Copy link

Is it possible to upload both text and image on WhatsApp? is there any solution for this?

@Mh-Alim
Copy link

Mh-Alim commented May 1, 2024

Is it possible to upload both text and image on WhatsApp? is there any solution for this?

did anyone find anything about this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment