And if you want to learn more about UIActivityViewController, check out the docs – scroll to the bottom to see all the activity types you can use.Įnter your email below and grab my advice, tips, and tutorials on iOS development designed to help you become a master of iOS development – and never worry about whether your iOS chops are getting old, crusty, stale, and irrelevant again. If you want to see the full sample code for this in a working app, it’s on GitHub. The activityItems attribute is an array with the data we want to share. However, when I try to share a URL to Messages from my own code (even if it's one that works from Safari like ), it just shares the URL as plain text. The UIActivityViewController class is a very powerful but simple class. If you want to exclude certain sharing activities – for example, if you only want the user to be able to share on Facebook and Twitter, you can do that with the excludedActivityTypes property on UIActivityViewController: controller.excludedActivityTypes = that’s it! When I share a webpage (example: ) from Safari to the Messages app, it shares a rich preview in a custom UI element with an image and the page's title and URL. NSData someData /./ UIActivityViewController activityViewController UIActivityViewController alloc initWithActivityItems: someData applicationActivities:nil But unfortunately this resulted in something like this: So in order to get a filename instead of Attachment-1 I create a file in the temporary directory and pass. ![]() Then we create an instance of UIActivityViewController, passing it our text, URL, and image. So in the first three lines, we’re just creating the text string, URL, and image. I am using UIActivityViewController to share image. NSURL *url = [NSURL *image = [UIImage *controller = Swift UIActivityViewController Image&Url Share not working with FB. ![]() Here’s an example with all three: NSString *text = to add Facebook and Twitter sharing to an iOS app" ![]() To use UIActivityViewController, you just need to pass some data to it (like text, a URL, or an image), then present the view controller. There are several ways to have your iPhone application interact with WhatsApp: universal links, custom URL schemes, share extension, and the Document. And, in fact, UIActivityViewController allows you to share or send data to several other services, like Mail, Messages, the Camera Roll, Reading List, Flickr, Vimeo, AirDrop, and more. colorChoiceImage(size: CGSize(width: 380, height: 160)) let shareURL. In iOS 6 and above, you can just use UIActivityViewController to allow the user to share on Facebook or Twitter. Select the ViewController.swift file and replace the first two statements with the. Let’s see how UIActivityViewController handles text sharing, URLs, images, and more.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |