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
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 tried different ways to show a URL icon with text but didnt succeed. Here is the code and its output snippets
Example 1:
let text = "I am text"
let myWebsite = URL(string:"https://www.youtube.com/")
let shareAll = [text, myWebsite] as [Any]
let activityViewController = UIActivityViewController(activityItems: shareAll, applicationActivities: nil)
self.present(activityViewController, animated: true, completion: nil)
Output 1:
UIActivity View Messages View
Example 2:
let myWebsite = URL(string:"https://www.youtube.com/")
let shareAll = [myWebsite] as [Any]
let activityViewController = UIActivityViewController(activityItems: shareAll, applicationActivities: nil)
self.present(activityViewController, animated: true, completion: nil)
Output 2:
UIActivity View
Required:
I want URL icon like in Output 2 for Example 1.
There is a difference between sharing data and showing data - I think in your case, showing the data that's about to be shared.
I could be wrong, but if not, you are actually able to share the data - in this case a UIImage and text - but wish to display what is about to be shared. I had this issue a while back. Here's my code. See if it can help you - basically you need to add metadata to UIActivityViewController delegate.
func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
let shareImage = preview.uiImage.adjustedForShareSheetPreviewIconProvider()
let imageProvider = NSItemProvider(object: shareImage)
let metadata = LPLinkMetadata()
metadata.imageProvider = imageProvider
metadata.title = "Title"
return metadata
}
Adjust shareImage and title as needed.
EDIT
I was using my code and was incomplete. adjustedForShareSheetPreviewIconProvider() is part of UIImage, and as such, it assumes this. In my code, I'm actually calling a GLKView to return this UIImage and then use it this way in the metadata.
So if your image is something returned from the URL as an icon and is (or can be converted to) a UIImage, just add it to the metadata like my code above.
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)
}
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)
I want to share a url like what Safari do in my own iOS app, How can i do this?
Use socail framework can share in some specified social plartform, but in my case ,I just want to share url like Safari.
Do you think on UIActivityViewController?
#IBAction func shareTextButton(_ sender: UIButton) {
// image to share
let link = "https://www.google.rs/"
// set up activity view controller
let activityViewController = UIActivityViewController(activityItems: [link], 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)
}