let image : UIImage = getImage () let item = ShareImage ( placeholderItem : image ) let activityViewController = UIActivityViewController ( activityItems :, applicationActivities : nil ) currentViewController. It is called UIActivityViewController, and for simple use cases, it is pretty easy:Ĭlass ShareImage : UIActivityItemProvider. On iOS, the Share Sheet comes in the form of a view controller that you need to programmatically create and present to the user. You send the operating system your content to be shared, and it will tell the user where it can be shared to. Share sheets are set up this way so you don't have to update your app code to handle new apps that can share the same content. The actual logic behind the Share Sheets is handled by the operating system, all you need to do as an app developer is tell it to open. For example, in your Photos app, you can select an image and then share it to other apps like Instagram, your mail app, your messaging app and plenty more. Share Sheets are interfaces in both iOS and Android that allows you to share content from your app to another app. What is a Share Sheet and why should I use it? If you are an application developer and you want your users to be talking about your product, a compelling experience with a well set up Share Sheet can help unlock network-effect growth. I also love to hear how you use this in your applications.A Share Sheet is a really powerful feature that's available on pretty much any phone today. I welcome comments and suggestions on improving the code. I hope it has been useful and if so please share with others. This example shows how to start using the share sheet based on the content. I am using the simulator so share options may be different. Click the button and the keyboard should disappear and share sheet should appear. func displayAlert(title: String, message: String) ) We will call the method with a title and message, add the following func to the view controller. We are going to keep the code tidy by separating the creation and display of the Alert in a separate method. If you are not familiar with the UIAlertController then I recommend my article ‘ Display an Alert or Action Sheet Using Swift in iOS 8‘. We will check if the text field is empty and if it is just alert the user giving them instructions to enter something and try again. The share sheet should only show if there is something to share. The button needs to handle any possible out comes and handle them gracefully. I also added constraints to keep the layout nice and pretty regardless of the device. Next create an each in the view controller. I added them to a storyboard from the object library. Now add a text field and a button using your method of choice. Start by creating a Swift based iOS application in Xcode. We are going to create an iPhone application with a text field to enter some text and a button that shares the contents using share sheet. One thing to remember, on iPhone you present the sheet as a modal view but on the iPad you have to present it as a popover. It is worth noting that you can override the options iOS gives you but we will not cover that this time around. You only need to tell iOS what you want to share and it will present only those options capable of handling the content you send to it. It is not hard to add this feature to your Swift applications thanks to iOS. That is when the magic of the sharing sheet appears. You find a great piece of content and want to Tweet it, post it to Facebook or maybe just email to a friend. To achieve this in applications you can use the UIActivityViewController. A nice feature on iOS is the ability to share just about anything to anywhere using the built in sharing system.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |