UIActivityViewController is always sharing image before text - ios

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?

Related

Unable to Share Image and Link in UIActivityController

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-

ios - format the information shared with share sheet

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.

How Can I share text and Image Together on Whatsapp

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

how to share video like iPhone default share

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 })
}

Text not showing up in UIActivityViewcontroller

I have a share function in my app that calls a uiactivityviewcontroller with text,url and an image to share.
The url and image work fine, but the text doesn't show up..
Here is the code I am using:
var highscore:Int = NSUserDefaults.standardUserDefaults().integerForKey("highscore")
var text = "My favourite game: 'Zig Zag!' My highscore: \(highscore)"
let link = NSURL(string: "https://itunes.apple.com/us/app/go-down!/id101725307?l=nl&ls=1&mt=8")
let actviewcon = UIActivityViewController(activityItems: [text,link!,shareima!], applicationActivities: nil)
actviewcon.excludedActivityTypes = [
UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
]
actviewcon.completionWithItemsHandler = {
(activity, success, items, error) in
//println("Activity: \(activity) Success: \(success) Items: \(items) Error: \(error)")
}
self.presentViewController(actviewcon, animated: true, completion: nil)
}

Resources