iOS13 share sheet: how to set preview thumbnail when sharing UIImage

The simplest code I’ve implemented to share a UIImage with better user experience: Import the LinkPresentation framework: #import <LinkPresentation/LPLinkMetadata.h> // for Obj-C import LinkPresentation // for Swift, below Present the UIActivityViewController in the UIViewController, with [image, self]: let image = UIImage(named: “YourImage”)! let share = UIActivityViewController(activityItems: [image, self], applicationActivities: nil) present(share, animated: true, completion: nil) … Read more

UIActivityViewController for Facebook not Showing Default Text

It would seem Facebook no longer wants developers to pre-fill posts with text. From https://developers.facebook.com/docs/sharing/ios#ios-integration: Use of the iOS share sheet is subject to Facebook Platform Policy, including section 2.3 which states that apps may not pre-fill. In the context of the share sheet, this means apps may not pre-fill the share sheet’s initialText field … Read more

Showing ‘UIActivityViewController’ in SwiftUI

The basic implementation of UIActivityViewController in SwiftUI is import UIKit import SwiftUI struct ActivityViewController: UIViewControllerRepresentable { var activityItems: [Any] var applicationActivities: [UIActivity]? = nil func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityViewController>) -> UIActivityViewController { let controller = UIActivityViewController(activityItems: activityItems, applicationActivities: applicationActivities) return controller } func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext<ActivityViewController>) {} } And here is how to use it. … Read more

Cannot set text color of Send and Cancel buttons in the mail composer when presented from the UIActivityViewController in iOS7

Managed to change the text color of the Send and Cancel buttons, which are on the UINavigationBar in the MFMailComposerViewController (both Send and Cancel) and MFMessageComposeViewController (only Cancel), when presented from UIActivityViewController. Using an UIActivityViewController, tap on Messageor Mail: You’ll notice that the default text color of the Send and Cancel buttons is blue: In … Read more

How do I set recipients for UIActivityViewController in iOS 6?

For adding subject to the email using UIActivityViewController on iOS6, this is the best solution that anyone can use.. All you have to do is call the following while initializing UIActivityViewController. UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities]; [activityViewController setValue:@”My Subject Text” forKey:@”subject”]; And your UIActivityViewController is populated with a subject.

How to exclude Notes and Reminders apps from the UIActivityViewController?

If you don’t want to subclass UIActivityViewController you can include them in your .excludedActivityTypes when creating your UIActivityViewController. Objective C: UIActivityViewController *activityController = [[UIActivityViewController alloc]initWithActivityItems:sharingItems applicationActivities:nil]; activityController.excludedActivityTypes = @[ UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeAddToReadingList, UIActivityTypeSaveToCameraRoll, UIActivityTypeOpenInIBooks, @”com.apple.mobilenotes.SharingExtension”, @”com.apple.reminders.RemindersEditorExtension” ]; [self presentViewController:activityController animated:YES completion:nil]; Swift 4.2: let activityController = UIActivityViewController(activityItems: sharingItems, applicationActivities: nil) activityController.excludedActivityTypes = [ UIActivity.ActivityType.assignToContact, UIActivity.ActivityType.print, … Read more

Basic example for sharing text or image with UIActivityViewController in Swift

UIActivityViewController Example Project Set up your storyboard with two buttons and hook them up to your view controller (see code below). Add an image to your Assets.xcassets. I called mine “lion”. Code import UIKit class ViewController: UIViewController { // share text @IBAction func shareTextButton(_ sender: UIButton) { // text to share let text = “This … Read more

I have REAL misunderstanding with MFMailComposeViewController in Swift (iOS8) in Simulator

* * IMPORTANT – DO NOT USE THE SIMULATOR FOR THIS. * * Even in 2016, the simulators very simply do not support sending mail from apps. Indeed, the simulators simply do not have mail clients. But! Do see the message at the bottom! Henri has given the total answer. You MUST — allocate and … Read more