UIActivityViewController Gmail Share unable to set subject field in swift - ios

I am using UIActivityViewController to share but on gmail when I set its subject specifically it does not set. Any help please.
let eventURL = eventShare[sender.tag]
let eventTitleText = eventTitle[sender.tag]
let contentDescription = eventDescription[sender.tag]
let contentURL:NSURL = NSURL(string:eventURL)!
let activityViewController : UIActivityViewController = UIActivityViewController(activityItems: [contentDescription, contentURL],applicationActivities: nil)
activityViewController.setValue("Our Buzz - \(eventTitleText)", forKey: "Subject")
activityViewController.popoverPresentationController?.sourceView = self.view
self.presentViewController(activityViewController, animated: true, completion: nil)

Try "subject" instead of "Subject" (lower case)

This seems to be a bug with the Gmail/Inbox apps. Using "Subject" as the key works correctly for Apple's Mail app but not for Gmail/Inbox. Other keys which also do not work include "subject", "title", "Title".
Another thing to be aware of is that the subject for Gmail/Inbox will include all the items in activityItems that you pass.
Since "Subject" sets the subject, people might be inclined to think that "Body" or some variant may work; but that results in a crash.

Related

How can I find custom UTIs App support in iOS?

I'm developing a custom UTI like "com.xyz".
All the apps supporting this UTI may be shown in the UIActivityViewController.
Code snippet:
let extensionItem = NSExtensionItem()
let data = NSItemProvider.init(item: nil, typeIdentifier: "com.xyz")
extensionItem.attachments = [data]
let activity = UIActivityViewController(
activityItems: [extensionItem],
applicationActivities: nil
)
present(activity, animated: true, completion: nil)
In order to have a better user experience, I would like to check if the iOS device has any App supporting "com.xyz" before presenting the UIActivityViewController.
Just like check URL:
UIApplication.shared.canOpenURL(URL(string: urlStr)!)
Otherwise the user may see an empty UIActivityViewController without any app.
As I know, there is an ActivityNotFoundException could be try and catch to handle the app not found situation in Android.
Does iOS support something like ActivityNotFoundException?
THANKS! 🙏

UIActivityViewController excludedActivityTypes not work

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

Add frequently used app for fast sharing swift

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!

Share image and text to whatsapp in single share in swift 4

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

Share text on facebook post

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.

Resources