I want to share image and text together with swift.How Can I do That ?
let url = NSURL(string: "whatsapp://app")
let shareText = "Beni Bons'da ekle : \(PFUser.currentUser()!.username!). http://apple.co/29RMfNn"
let bonsCardImage = UIImage.renderUIViewToImage(bonsCardView)
let activityItems = [bonsCardImage]
let vc = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
presentViewController(vc, animated: true, completion: nil)
Thanks
Related
Trying to share image and link in UIActivityController, But its only share link not the image
code snippet-
let model = self.memeFeedDataList[sender.tag]
let imageURL = NSURL(string: NetWorkingConstants.baseImageURL+model.imageUrl!) //https://xyz.png
let imagedData = NSData(contentsOf: imageURL! as URL)!
let img = [UIImage(data: imagedData as Data)]
let linkURL = NSURL(string:"https://stackoverflow.com/")
let shareAll = [img , linkURL! ] as [Any]
let activity = UIActivityViewController(activityItems: shareAll, applicationActivities: nil);
self.present(activity, animated: true, completion: nil)
Output screenshot-
I am using the following code to present a share sheet:
let url = "https://somelink.com"
let image = "https://myserver/an_image.png"
let text = "Join now!"
let shareSheetVC = UIActivityViewController(activityItems: [image, url, text], applicationActivities: nil)
shareSheetVC.popoverPresentationController?.sourceView = sender
shareSheetVC.popoverPresentationController?.sourceRect = sender.frame
present(shareSheetVC, animated: true)
What I'd like is something like this:
However, when I share I just get
https://somelink.com
https://myserver/an_image.png
Join now!
How can I format this to accomplish something like the example?
This is the basic example to share Text, Image and URL using UIActivityViewController
let text = "Join Now!"
let image = UIImage(named: "your_image")
let myWebsite = URL(string: "https://somelink.com")
let shareAll = [text , image! , myWebsite]
let activityViewController = UIActivityViewController(activityItems: shareAll, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
activityViewController.popoverPresentationController?.sourceRect = sender.frame
self.present(activityViewController, animated: true, completion: nil)
Hope you understand.
Alternatively, you could approach this from a different angle and try to fix your webpage by adding:
<meta property="og:image" content="https://myserver/an_image.png">
<title>Join now!</title>
Those tags will be picked up by default from the UIActivityViewController.
I am unable to share the msword and msexcel and ppt files in Swift Using UIActivityViewController
Here is the code snippet I am using
func ShareFileFromApptoIpad(filename : String!){
let fileManager = FileManager.default
let documentoPath = (self.getDirectoryPath() as NSString).appendingPathComponent("\(filename!)")
print("doc\(documentoPath)")
if fileManager.fileExists(atPath: documentoPath){
let documento = NSData(contentsOfFile: documentoPath)
let activityViewController: UIActivityViewController = UIActivityViewController(activityItems: [documento!], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView=self.view
present(activityViewController, animated: true, completion: nil)
}
else {
print("document was not found")
}
}
you can change your url Like this
let url = NSURL.fileURL(withPath: myFileName)
and then use in
let activityViewController = UIActivityViewController(activityItems: [url] , applicationActivities: nil)
I want to share a video in my app like default share of iPhone video share.
I have written code but its not like iPhone default share
here are difference between my share function and iPhone default share
func shareVideo() {
let paths = NSSearchPathForDirectoriesInDomains(
NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
let documentsDirectory: AnyObject = paths[0]
let dataPath = documentsDirectory.stringByAppendingPathComponent("saveFileName")
let URL: String = documentsDirectory.stringByAppendingPathComponent(dataPath)
let someText: String = "A nice song"
let urlToShare: NSURL = NSURL.fileURLWithPath(URL, isDirectory: false)
let dataToShare: [AnyObject] = [someText, urlToShare]
let activityViewController: UIActivityViewController = UIActivityViewController(activityItems: dataToShare, applicationActivities: nil)
activityViewController.excludedActivityTypes = [UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact]
self.presentViewController(activityViewController, animated: true, completion: { _ in })
}
In my app, I want to share the current song and artist followed by the album artwork. Here is my code:
var sharingItems = [AnyObject]()
let currentSong = musicPlayer.nowPlayingItem?.title
let currentArtist = musicPlayer.nowPlayingItem?.artist
let artwork = musicPlayer.nowPlayingItem?.artwork
let artworkImage = artwork?.imageWithSize(CGSizeMake(100, 100))
let shareText = "Now playing \(currentSong!) by \(currentArtist!) via Ryan's awesome app"
sharingItems.append(shareText) //text first, then image
sharingItems.append(artworkImage!)
let activityViewController = UIActivityViewController(activityItems: sharingItems, applicationActivities: nil)
activityViewController.excludedActivityTypes = [UIActivityTypeAddToReadingList, UIActivityTypeAssignToContact, UIActivityTypeOpenInIBooks, UIActivityTypePrint, UIActivityTypeSaveToCameraRoll]
self.presentViewController(activityViewController, animated: true, completion: nil)
When I choose a share option, like Messges, the image is before the text in the TextField. Why is the image first if it's last in the array?