In my case, I need to send some data to a server before the app can know what URL to share, so the item provider needs to be set up to do that on demand. ShareLink(item: url) That’s it to share a URL using SwiftUI in Xcode 14 for application running iOS 16+. If you already have everything you need in memory or on disk, you can probably just use one of the initializers for NSItemProvider to provide the sharable data, and this will be pretty simple. The implementations for these two different APIs are similar, but not similar enough to make it trivial, at least if you have meaningful work you need to do to produce the sharable item.īut this is what we must do, so let’s define a way to create an item provider from a project. It’s a bit frustrating that we need to use NSItemProvider for this, since we already had to implement either UIActivityItemSource or UIActivityItemProvider to be able to use UIActivityViewController. ![]() They’re a way to capture the various representations of an object in an app such that it can be sent to another app, which can then use whichever representation is appropriate. If you’ve implemented drag-and-drop in table views or collection views, you’ve used NSItemProviders before. The implementation can be as simple as implementing one method:Įach sharable item is represented by an NSItemProvider, so you’ll need a way to create one from the model objects you want to share (in this example, a Project). I think the root view controller for your window is a good candidate to implement this, as it’s likely to have all the relevant state for where the user is in the app to know what should be shared. You have to provide the items to share at initialization time, and most applications want to change what is shareable based on where the user is in the application, so let’s implement the protocol ourselves. UIKit provides a concrete implementation of this protocol called UIActivityItemsConfiguration, but I don’t think it will be useful in this situation. When using AppKit, you provide a delegate to the toolbar item instead, which has a different API. Aside: The activityItemsConfiguration property is specific to Mac Catalyst. You do this by setting activityItemsConfiguration to an object that implements the UIActivityItemsConfigurationReading protocol. Instead of performing an arbitrary action, this toolbar item will handle all the work if you just tell it how to get the items to share when it needs to. ![]() It turns out NSSharingServicePickerToolbarItem doesn’t use the action property at all. You can also define custom actions as well. Oh no! Now the icon looks right, but the button is always disabled. UIActivityViewController SwiftAre you looking for chart for uiactivityviewcontroller tutorial Want to learn how to use share sheet ios This uiactivityviewc. UIActivityViewController is a simplified built in interface to share contents such as texts, images and URLs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |