How to add this sharing button? IOS8 with fast

I want my application to have a button that, when clicked on it (see image below). How can I do it? I do not want to create custom extensions, I just want the default? What code am i using? All online tutorials are in objective-c. Please respond quickly.

Image: http://9to5mac.com/2014/06/30/hands-on-1password-beta-shows-off-ios-8s-touch-id-extensions-apis-video/#jp-carousel-330420

Here is my code so far, but I get an error that UIBarButtonItem is not convective for UIVIew Why? Is the action associated with a navigation bar button element?

@IBAction func ActionButton(sender: UIBarButtonItem) { let firstActivityItem = "Text you want" let secondActivityItem : NSURL = NSURL(string: "http//:urlyouwant")! // If you want to put an image let image : UIImage = UIImage(named: "TALogo")! let activityViewController : UIActivityViewController = UIActivityViewController( activityItems: [firstActivityItem, secondActivityItem, image], applicationActivities: nil) // This lines is for the popover you need to show in iPad activityViewController.popoverPresentationController?.sourceView = (sender as! UIBarButtonItem) // This line remove the arrow of the popover to show in iPad activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.allZeros activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0) // Anything you want to exclude activityViewController.excludedActivityTypes = [ UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo ] self.presentViewController(activityViewController, animated: true, completion: nil) } 
+3
iphone ios8 swift sharing ios-extensions
source share
1 answer

The method uses a UIActivityViewController , for example, as follows:

 @IBAction func shareSheet(sender: AnyObject) { let firstActivityItem = "Text you want" let secondActivityItem : NSURL = NSURL(string: "http//:urlyouwant")! // If you want to put an image let image : UIImage = UIImage(named: "image.jpg")! let activityViewController : UIActivityViewController = UIActivityViewController( activityItems: [firstActivityItem, secondActivityItem, image], applicationActivities: nil) // This lines is for the popover you need to show in iPad activityViewController.popoverPresentationController?.sourceView = (sender as! UIButton) // This line remove the arrow of the popover to show in iPad activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.allZeros activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0) // Anything you want to exclude activityViewController.excludedActivityTypes = [ UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo ] self.presentViewController(activityViewController, animated: true, completion: nil) } 

The above code works for both iPhone and iPad, because when you install the new popoverPresentationController in iOS 8, it works for iPad popoverPresentationController .

If using UIBarButtonItem you need to replace this line:

 activityViewController.popoverPresentationController?.sourceView = (sender as! UIButton) 

With the help of this:

 activityViewController.popoverPresentationController?.barButtonItem = (sender as! UIBarButtonItem) 

Hope this helps you.

+6
source share

All Articles