I want to add the my app sharing feature in my App. Like The Action Sheet Toggle up with the all the social Media and other app in which i can share my app Url. I try to find the tutorial for that but i can't find the proper tutorial for that. this is what I have Done.
func shareApp (){
let textToShare = "Swift is awesome! Check out this website about it!"
if let myWebsite = NSURL(string: "http://www.google.com/") {
let objectsToShare = [textToShare, myWebsite] as [Any]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.excludedActivityTypes = [UIActivityType.airDrop, UIActivityType.addToReadingList]
self.present(activityVC, animated: true, completion: nil)
}
This What i Get.
So just want to show there Some Social Media options There.
All you have done is right, except you have not added the App url of your appstore link. Add that link like https://itunes.apple.com/in/app/more-customers-app/id1280868223?mt=8 and all your media will be appear in list if those application is installed in iphone.
You have got UIActivityViewController presented now, Just add in text like,
func ShareApp()
{
let items:[Any] = ["Marketplace of Building Material for Architects, Interior Designers, Contractors and Home Owners. Find Material for your next project. Download https://itunes.apple.com/in/app/more-customers-app/id1280868223?mt=8"]
let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
self.present(ac, animated: true)
}
Related
I need to exclude .saveToCameraRoll from a UIActivityViewController but it is ignoring excludedActivityTypes.
activityVC = UIActivityViewController(activityItems: [imgUrl], applicationActivities: activities)
activityVC!.excludedActivityTypes = [.saveToCameraRoll]
I also tried creating a "custom" UIActivty and exclude it:
let saveToCameraRollActivity = UIActivity.ActivityType.init(rawValue: "\(UIActivity.ActivityType.saveToCameraRoll.rawValue)")
activityVC!.excludedActivityTypes = [saveToCameraRollActivity]
Both ways have no effect, the Save Image option is still displayed. What is the point of being able to exclude activity types if they are ignored?
The header says:
// default is nil. activity types listed will not be displayed
excludedActivityTypes: [UIActivity.ActivityType]?
I need to use my own Save Image because standard one is not respecting the file name (even though it is shown with the file icon and I am using a URL).
I am using this function and hide "save video" button :--
func otherShare(url : URL) {
let imageToShare = [ url ]
let activityViewController = UIActivityViewController(activityItems: imageToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
activityViewController.excludedActivityTypes = [UIActivity.ActivityType.copyToPasteboard, UIActivity.ActivityType.saveToCameraRoll]
self.present(activityViewController, animated: true, completion: nil)
}
I have an application which collects the video assets of a users camera roll, using the Photos Framework and methods requestImage & requestAVAsset
I'm allowing the user to share the asset using the UIActivityViewController class and the URL from the AVAsset. My problem is that for some strange reason it won't allow me to share the video.
On the app the error message I get on the UIActivityViewController is
The item cannot be shared. Please select a different item.
Any pointers or advise is appreciated, thanks!
Here is how I present the UIActivityViewController:
let selectedVideo = self.selectedVideo //(AVAsset)
let videoURLPath = selectedVideo.url // URL
DispatchQueue.main.async {
let activityItems: [Any] = [videoURLPath]
let activityViewController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
activityViewController.excludedActivityTypes = [UIActivity.ActivityType.addToReadingList, UIActivity.ActivityType.airDrop, UIActivity.ActivityType.assignToContact,]
activityViewController.popoverPresentationController?.sourceView = self.view
activityViewController.popoverPresentationController?.sourceRect = self.view.frame
self.present(activityViewController, animated: true, completion: nil)
}
Here's how the video URL looks:
file:///var/mobile/Media/DCIM/107APPLE/IMG_7966.MP4
I want to share a PDF directly to WhatsApp.
Below is the link I found to send text and image in WhatsApp in an iOS app, but unable to find that how to send PDF directly to WhatsApp.
Share image/text through WhatsApp in an iOS app
You can use Share Extension (UIActivityViewController) to share your pdf fileURL. Note that the user will have to select the WhatsApp application to share the file. Note is is required to edit your info.plist and add whatsapp to your LSApplicationQueriesSchemes array if you would like to check first if WhatsApp is installed:
func sharePdfWhatsApp(url: URL) {
let whatsappURL = URL(string:"whatsapp://app")!
// this will make sure WhatsApp it is installed
if UIApplication.shared.canOpenURL(whatsappURL) {
let controller = UIActivityViewController(activityItems: [url], applicationActivities: nil)
present(controller, animated: true) {
print("done")
}
}
}
First you have to retrieve your PDF file as a Data format.
var pdfDATA:Data!
Once you get data to above variable you can run below code to send PDF via WhatsApp.
self.pdfDATA = try? Data.init(contentsOf: yourFilepath)
let activitycontroller = UIActivityViewController(activityItems: [self.pdfDATA], applicationActivities: nil)
if activitycontroller.responds(to: #selector(getter: activitycontroller.completionWithItemsHandler))
{
activitycontroller.completionWithItemsHandler = {(type, isCompleted, items, error) in
if isCompleted
{
print("completed")
}
}
}
activitycontroller.excludedActivityTypes = [UIActivityType.airDrop]
activitycontroller.popoverPresentationController?.sourceView = buttonItemSize
self.present(activitycontroller, animated: true, completion: nil)
Is there any specific method to share button that detect all social media apps on your iOS phone ?
example : my phone have whatsapp and twitter installed. so when I pressed share button only whatsapp and twitter came out, not facebook and any other apps not installed on my phone.
In android there's particular intent to use that kind of method. However in iOS I still can't find it.
Note : I need it for Swift 3 programmatically
Any help is very useful, Thank you
You should try this:
#IBAction func shareImageButton(_ sender: UIButton)
{
// image to share
let image = UIImage(named: "Image")
// set up activity view controller
let imageToShare = [ image! ]
let activityViewController = UIActivityViewController(activityItems: imageToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
// exclude some activity types from the list (optional)
activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook ]
// present the view controller
self.present(activityViewController, animated: true, completion: nil)
}
Im trying to implement UIActivityViewController to my app, It works correctly. However, I'd like to add Instagram to the options. When searching on the internet, I've seen this reply :
"You're able to use UIActivityViewController to show up Instagram as
long there is just an UIImage inside the activity items. It won't show
up if you add more items like text, url etc. This is a bad limitation
made by Instagram.".
Is there any way, how to add Instagram even with initial text, or should I integrate another UIActivityViewController option and turn off all of the other options (FB, Twitter, mail) to show Instagram option? Maybe through if clauses for text?
Here ist the piece of code
#IBAction func ShareRecipe(_ sender: AnyObject) {
let initialText = "-Check out this app"
let img: UIImage = ImageView.image!
let activityVC = UIActivityViewController(activityItems: [img, initialText], applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = self.view
self.present(activityVC, animated: true, completion: nil)
}