Could anyone suggest me how to share image with text to whatsaap or any alternative for the same.I have tried it using UIActivityViewController but its possible to share image+text simultaneously on mail bt not on whatsaap .
Help will be appreciated.
Thank you :)
code is as follows:
let textToShare = "Hello world"
let myWebsite = NSURL(string:"https://www.apple.com/")
let img = UIImage(named:"BookImg")
let shareall = [img!,textToShare,myWebsite!] as [Any]
let vc = UIActivityViewController(activityItems: shareall, applicationActivities: nil)
vc.popoverPresentationController?.sourceView = self.view
self.present(vc, animated: true, completion: nil)
Sorry, but you can't post Images and Text together on WhatsApp. However, you can post one at a time. As Whatsapp does not provide any API you can add captions and post images with text.
For your reference , WhatsApp:
http://www.whatsapp.com/faq/en/iphone/23559013
An easy alternative is handing the image part from your server side. Host it and share the link along with the caption. the image will be shown automatically through the URL you are sharing.
It will appear like below,
SS: https://ibb.co/7tpqm8S
Related
I want to exclude Weibo and WeChat, and set the following code:
let av = UIActivityViewController(activityItems: items, applicationActivities:nil)
av.excludedActivityTypes = [.postToWeibo, .postToTencentWeibo]
self.present(av, animated: true)
No matter what I did, the two apps still show up on UIActivityViewController. But excluding mail and copyToPasteboard are both work
av.excludedActivityTypes = [.postToWeibo, .postToTencentWeibo, .copyToPasteboard, .mail]
Any other way to exclude them? Thanks
I am working on a sharing functionality where I have achieved the basic sharing part and is working perfectly. Below is the code for same
let message = "Download the app from the link below"
//Set the link to share.
if let link = NSURL(string: "http://yoururl.com") {
let objectsToShare = [message,link] as [Any]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.excludedActivityTypes = [UIActivityType.airDrop, UIActivityType.addToReadingList]
self.present(activityVC, animated: true, completion: nil)
}
The above code is working great and gives the output as seen in the screenshot
What I want is to have an extra icon/option to share the content for the frequently used app.
for e.g. I use Whatsapp frequently so the share window should show WhatsApp icon somewhere besides "More".
any help will be highly appreciated. TIA
This can't be done because the share sheet is a library provided by apple and only the user can rearrange icons on their own!
I am trying to implement the Facebook Share in my quiz app. The content is app store link and quiz score.Which is working fine in simulator but in device shows in different and not showing my description. Here is my Code
func ShareFB() {
let fbVC = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
fbVC?.setInitialText("Hey! I scored \(String(describing: UserDefaults.standard.string(forKey: "TOTAL_SCORE")!)) in Test. This is really interesting! You can also try.")
fbVC?.add(URL(string: "https://itunes.apple.com/us/app/test-app/i?ls=1&mt=8"))
fbVC?.add(UIImage(named: "AppIcon"))
present(fbVC!, animated: true) { _ in
}
}
also attaching screen Shot of simulator and device.
now you cannot share image, text and url simultaneously in facebook. also Facebook does not allow pre filled text now
Why don't you use UIActivityController for such functionality?
Example:
let shareItems = [
"Hey! I scored \(String(describing: UserDefaults.standard.string(forKey: "TOTAL_SCORE")!)) in Test. This is really interesting! You can also try.",
URL(string: "https://itunes.apple.com/us/app/test-app/i?ls=1&mt=8"),
UIImage(named: "AppIcon")] //Add the items you want to share in this array
let activityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
self.present(activityViewController, animated: true, completion: nil)
Edit:
Check this out:
https://stackoverflow.com/a/30020929/5716829
According to Facebook's 2.3 policy rules, you can't share pre-filled content because of policy violation. Facebook does not allow you to share the pre-filled user message parameters with any content the user didn't entered himself.
If you want to share content on Facebook then user has to write/enter himself in Facebook prompt message dialog.
For more info, please visit: https://developers.facebook.com/docs/apps/review/prefill
I am working on a project where I need to share an image and a video together on Facebook, but facing undefined behaviour.
Issue: When I am trying to share a video using FBSDKShareMediaContent class (using below code), the FBSDKShareDialog is not appearing, but it appears when I share only an image.
My code:
let photo: FBSDKSharePhoto = FBSDKSharePhoto.init(image: imageToShare, userGenerated: true)
let vid: FBSDKShareVideo = FBSDKShareVideo.init(videoURL: URL(string:vidUrl!.path))
// FBSDKShareDialog not appearing in this case
let shareContent: FBSDKShareMediaContent = FBSDKShareMediaContent()
shareContent.media = [photo, vid]
/*
// FBSDKShareDialog appearing
let shareContent: FBSDKShareMediaContent = FBSDKShareMediaContent()
shareContent.media = [photo] */
FBSDKShareDialog.show(from: self.getCurrentViewController(), with: shareContent, delegate: nil)
Video URL: file:///var/mobile/Containers/Data/Application/2E0E48B7-30E5-4567-8C0B-ACAC100AE389/Documents/AppName/1499773278.555753.mp4
Please help.
The solution i found is, the url path i was assigning is wrong as per the Facebook guidelines of sharing video.
The video URL videoURL must be an asset URL. You can get a video asset URL e.g. from UIImagePickerController.
See video sharing section inside the link.
UPDATE:
Final Solution to share image, video together using picker or document directory path whichever, this works.
let shareText = "Upload video, image and text."
let vc = UIActivityViewController(activityItems: [shareText, vidUrl, imageToShare], applicationActivities: [])
present(vc, animated: true)
How do I share text and a link for Facebook through UIActivityController? I can add an URL but not text, is this possible to do somehow?
I have the following today:
let activityItems = ["Some text", "", "http://test.com"]
let vc = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
self.presentViewController(vc, animated: true, completion: nil)
For twitter, mail and sms I get both the text and the URL, for Facebook only the URL.
So
Is it possible to add text to the Facebook share?
What does the second empty string parameter do?**
Facebook's policies don't allow you to pre-populate status messages and require all content to be user generated.
Reference.