It looks like the Share Extension allows other "host" apps to share content with my "containing" app. How do I share content from my app with other apps using the standard iOS share sheet? I have found information on how to use UISheetPresentationController and UIActivityViewController. What is Apple's designated standard API to share content from my iOS app? I would think their designated way would show all the the apps that the share sheet can share with. Is UIActivityViewController the way that is most intended by Apple to do this?
This article looks like a nice simple tutorial: UIActivityViewController by example, but when I try the first segment of code that it teaches, it doesn't work like the article says it should.
The most significant message in the debug window is the part in the first line that says "couldn't find entitlement CopresenceCore.Entitlement.publicAPI error nil". I can't find information about what entitlement that would be. I take it I need to have an entitlement file in my project for that entitlement.
I am using an iPhone 8 device with iOS 15.6.1 in an Xcode project set for iOS Deployment Target 13.0.
I works on an iPhone 5s device with iOS 12.5.6 in a separate Xcode project set for iOS Deployment Target 11.0.
The print statement that prints "presentation done" shows in the debug window in both cases.
Here's my code:
import UIKit
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let stringItem = "Hello there."
let activityViewController = UIActivityViewController(activityItems: [stringItem], applicationActivities: nil)
self.present(activityViewController, animated: true) {
print("presentation done")
}
}
}
Here's the debug window:
2022-10-20 21:08:10.536367-0500 TrialUIActivityViewControllerHackingWithSwiftPaulHudson[34244:1256968] [Default] Task TrialUIActivityV[34244]/1#3 LF=0 couldn't find entitlement CopresenceCore.Entitlement.publicAPI error nil
2022-10-20 21:08:11.266049-0500 TrialUIActivityViewControllerHackingWithSwiftPaulHudson[34244:1256968] [Default] Task TrialUIActivityV[34244]/1#3 LF=0 couldn't find entitlement CopresenceCore.Entitlement.publicAPI error nil
2022-10-20 21:08:12.000344-0500 TrialUIActivityViewControllerHackingWithSwiftPaulHudson[34244:1256968] [default] LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]}
2022-10-20 21:08:12.001351-0500 TrialUIActivityViewControllerHackingWithSwiftPaulHudson[34244:1256968] [default] Attempt to map database failed: permission was denied. This attempt will not be retried.
2022-10-20 21:08:12.001421-0500 TrialUIActivityViewControllerHackingWithSwiftPaulHudson[34244:1256968] [db] Failed to initialize client context with error Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]}
2022-10-20 21:08:12.062430-0500 TrialUIActivityViewControllerHackingWithSwiftPaulHudson[34244:1256968] [default] -imageForImageDescriptor: can do IO please adopt -imageForDescriptor: for IO free drawing or -prepareImageForDescriptor: if IO is allowed. (This will become a fault soon.)
2022-10-20 21:08:12.199153-0500 TrialUIActivityViewControllerHackingWithSwiftPaulHudson[34244:1256968] [default] LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]}
2022-10-20 21:08:12.199262-0500 TrialUIActivityViewControllerHackingWithSwiftPaulHudson[34244:1256968] [default] Attempt to map database failed: permission was denied. This attempt will not be retried.
2022-10-20 21:08:12.199340-0500 TrialUIActivityViewControllerHackingWithSwiftPaulHudson[34244:1256968] [db] Failed to initialize client context with error Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]}
2022-10-20 21:08:12.199640-0500 TrialUIActivityViewControllerHackingWithSwiftPaulHudson[34244:1256968] [default] -imageForImageDescriptor: can do IO please adopt -imageForDescriptor: for IO free drawing or -prepareImageForDescriptor: if IO is allowed. (This will become a fault soon.)
2022-10-20 21:08:12.240705-0500 TrialUIActivityViewControllerHackingWithSwiftPaulHudson[34244:1256968] [LayoutConstraints] Changing the translatesAutoresizingMaskIntoConstraints property of a UICollectionReusableView that is managed by a UICollectionView is not supported, and will result in incorrect self-sizing. View: <_UIActivityContentFooterView: 0x131d15bc0; baseClass = UICollectionReusableView; frame = (16 474.5; 343 52); layer = <CALayer: 0x281180420>>
2022-10-20 21:08:13.864915-0500 TrialUIActivityViewControllerHackingWithSwiftPaulHudson[34244:1256968] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x283245f90 UIStackView:0x131d56460.centerY == UIView:0x131d54de0.centerY (active)>",
"<NSLayoutConstraint:0x283246490 _UIActivityActionCellTitleLabel:0x131d55cc0.height >= 54.5 (active)>",
"<NSLayoutConstraint:0x283245ea0 V:|-(>=4)-[UIStackView:0x131d56460] (active, names: '|':UIView:0x131d54de0 )>",
"<NSLayoutConstraint:0x283246850 'UISV-canvas-connection' UIStackView:0x131d56460.top == _UIActivityActionCellTitleLabel:0x131d55cc0.top (active)>",
"<NSLayoutConstraint:0x2832468a0 'UISV-canvas-connection' V:[_UIActivityActionCellTitleLabel:0x131d55cc0]-(0)-| (active, names: '|':UIStackView:0x131d56460 )>",
"<NSLayoutConstraint:0x28324e5d0 'UIView-Encapsulated-Layout-Height' UIView:0x131d54de0.height == 30 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x283246490 _UIActivityActionCellTitleLabel:0x131d55cc0.height >= 54.5 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
presentation done
2022-10-20 21:08:18.385209-0500 TrialUIActivityViewControllerHackingWithSwiftPaulHudson[34244:1256968] [TraitCollection] Class CKBrowserSwitcherViewController overrides the -traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate API.