My app inside iMessage UIActivityViewController
Instead of a URL scheme you need to add a document type to your app. Try adding the following fragment to your Info.plist
:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>public.jpeg</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>public.jpeg</string>
</array>
</dict>
</array>
With this fragment (specifically with the LSItemContentTypes
key) you declare that your app is an editor for documents that have the Uniform Type Identifier (UTI) public.jpeg
. Because this UTI is declared by the system, I believe it is not necessary that you include the UTI declaration in your app's Info.plist
.
You can find all system-declared UTI's in the Apple document titled System-Declared Uniform Type Identifiers. If you are new to UTI you should probably also read the Apple document Uniform Type Identifier Concepts.
Last but not least, don't forget to consult the Information Property List Key Reference to find out what you should specify for the Core Foundation keys CFBundleTypeRole
and LSHandlerRank
.
BTW: This excellent SO answer also has details about working with UTIs, especially if you ever need to declare your own app-specific UTI.
Why does iMessages change the URL I pass to it via the UIActivityViewController?
When the url is passed to iMessages, it retrieves the web site in order to render a preview.
At the top of the page returned is:
<link rel="canonical" href="https://app.acuityscheduling.com/schedule.php?owner=12808744">
This says that the canonical link for this page is https://app.acuityscheduling.com/schedule.php?owner=12808744, and so the activity item is updated with this, preferred, url for the page.
UIActivityViewController cannot add image to imessage
As others have said, iMessage only supports text, not images. Although it sounds like in iOS7, it does work.
I know personally I've gotten it to work with OvershareKit: https://github.com/overshare/overshare-kit .
It of course adds a bit of overhead but allows you to share with just about every medium there is with their slick interface/APIs.
UIActivityViewController not showing Message option When Sharing Image Object
Your code is completely fine, works to me.
First of all you Messages app may be missing if you have iMessage disabled in your settings. Go to Settings->Messages and make sure it's on:
Also you may not see it in the default items, check out hidden ones:
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 is some text that I want to share."
// set up activity view controller
let textToShare = [ text ]
let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
// exclude some activity types from the list (optional)
activityViewController.excludedActivityTypes = [ UIActivity.ActivityType.airDrop, UIActivity.ActivityType.postToFacebook ]
// present the view controller
self.present(activityViewController, animated: true, completion: nil)
}
// share image
@IBAction func shareImageButton(_ sender: UIButton) {
// image to share
let image = UIImage(named: "Image")
// set up activity view controller
let imageToShare = [ image! ]
let activityViewController = UIActivityViewController(activityItems: imageToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
// exclude some activity types from the list (optional)
activityViewController.excludedActivityTypes = [ UIActivity.ActivityType.airDrop, UIActivity.ActivityType.postToFacebook ]
// present the view controller
self.present(activityViewController, animated: true, completion: nil)
}
}
Result
Clicking "Share some text" gives result on the left and clicking "Share an image" gives the result on the right.
Notes
- I retested this with iOS 11 and Swift 4. I had to run it a couple times in the simulator before it worked because it was timing out. This may be because my computer is slow.
- If you wish to hide some of these choices, you can do that with
excludedActivityTypes
as shown in the code above. - Not including the
popoverPresentationController?.sourceView
line will cause your app to crash when run on an iPad. - This does not allow you to share text or images to other apps. You probably want
UIDocumentInteractionController
for that.
See also
- Add sharing to your Swift app via UIActivityViewController
- UIActivityViewController from NSHipster
UIActivityViewController
documentation- Share extension documentation
- comparison with
UIDocumentInteractionController
Related Topics
Uiapplication.Registerforremotenotifications() Must Be Called from Main Thread Only
How to Add Strings on X Axis in iOS-Charts
Swift - Uibutton with Two Lines of Text
How to Swizzle a Class Method on iOS
How to Get a Cgpoint from a Tapped Location
Using Ldap for Authentication in iOS
Disabling Automatic Scrolling of Uitableview When Editing Uitextfield Inside Uitableviewcell
How to Authenticate the Gklocalplayer on My 'Third Party Server'
Add Custom Controls to Avplayer in Swift
Uicollectionview Header Dynamic Height Using Auto Layout
Swiftui - iOS 13 Uiviewrepresentable of Wkwebview Gets Thread 1: Exc_Breakpoint Crash
This Class Is Not Key Value Coding-Compliant with @Ibinspectable