NSArray *activityItems = *activityViewControntroller = initWithActivityItems:activityItems applicationActivities:nil] ĪctivityViewControntroller. On an iPad, the sharing menu is present as a popover which means that we'll need to handle the sourceView (which is just our ViewController represented as self.view) and the sourceRect which is where the popover will be drawn on the screen. We'll also need to handle a special condition that occurs if our app is running on an iPad since that requires some extra logic. Apple has a list of the builtin activityTypes if you want to exclude any in your own implementation. We can also exclude Activity types if we want to restrict what shows up in our UIAlertViewController as options for sharing or saving the image. The UIActivityViewController is what we associate with a sharing screen. Next we'll need to create a new activityViewController of type UIActivityViewController. If we wanted to share other items we could also add it to this array (for example if we wanted to pass a string in to automatically provide a caption). This image can then be added into an array of activityItems which we can pass into our UIActivityViewController. We'll use the getImage method of our FlexChart object to return an NSData object that can be used to create a UIImage. This is actually pretty straightforward too. The next step is to handle what happens when our shareButton is clicked. Share any file, test and images in ios swift. let pdfDoc NSData(contentsOf:URL(string: documentPathToLoad)). All gists Back to GitHub Sign in Sign up. ShareButton = initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self = shareButton Share a PDF with UIActivityViewController in Swift 3 - sharePDF.swift. If you want to see another take on how to do this, check out David Owens’s article UIActivityViewController (Share Sheet) with Swift. We'll also specify the share method (which I'll get to shortly) to handle when the button is clicked. All you need to do is create an Array of whatever you want to share, give it to a UIActivityViewController initializer, and then present that ViewController. In the ViewController, we'll need to initialize the button, and add it as the right navigation item of our ViewController. First we need to declare our shareButton object (which is of the type UIBarButtonItem). Implementing a Share ButtonĬreating the share button is a straightforward process. In this article, we'll cover the highlights of implementing a sharing button in a small iOS app. Apple provides some tools to for this purpose that not only give you easy access to any available sharing options (Mail, Message, Facebook, etc.), but also the ability to quickly save and print your data visualization. Xuni gives you the ability to turn your chart or gauge control into an image using the getImage method, but you may wonder how you can easily share this with others.
0 Comments
Leave a Reply. |