Adding a photo picker #185
Replies: 4 comments
-
I guess you want to do basically the same thing as the SwiftUIDemo does with the DocumentPicker. AFAIK the PhotosPicker just takes
The
What I do is specify a So, maybe a |
Beta Was this translation helpful? Give feedback.
-
Thanks Steven, that code was above-and-beyond the call. You've given me a lot to puzzle over. I hear you about the efficiency of moving all the images around. I'm already loading the image from the PhotosPicker and storing it in a cache directory of my own for display in another web view, and ultimately it all gets converted into data for socking away in a CoreData store, so I might need to figure out how to consolidate some of these caches. As near as I can tell, there's no simple way to get a URL from the PhotosPIcker. I did find this, though. |
Beta Was this translation helpful? Give feedback.
-
Please post your code if you get the PhotoPicker working reasonably well. I'll leave this open, or we could move it to a discussion. |
Beta Was this translation helpful? Give feedback.
-
I pretty much just followed your suggestions. You're correct that PhotosPicker fires an onChange when the user taps on an image. There doesn't seem to be a way to get it to deliver a URL – perhaps they don't have the images stored as files anywhere. Instead, it gives you a big chunk of data that is a UIImage. For my app, I need this stored in a CoreData Persistent Container, so in the onChange, I encode the image and sock it away in the CoreData store. Then I write it out to my resourcesURL as a png. Using the code you posted above, I then call markupImageToAdd and pass it the URL of the file that I just saved. I had to make one small change to markupImageToAdd. It creates a filename for the image that you pass to it, and I need the image name to match the one that I've already used in my CoreData store so I took out the part of markupImageToAdd that was creating a filename and stuck with the one I already had. Once you pointed me in the right direction, it was very easy to get working. If you want the user to be able to select multiple images at once, I don't think you can do that with the PhotosPicker, so that simplifies a lot of things on the back end. |
Beta Was this translation helpful? Give feedback.
-
Okay, I've got, hopefully, one last hurdle to integrate MarkupEditor: When I insert an image I'd like to select it from the standard Photos picker. In another part of my app I do this with the SwiftUI PhotosPicker. I see how I can override the markupShowImagePopover through my delegate, but since that's outside of the normal View hierarchy, I'm at a loss for how to implement the PhotosPicker. Any tips would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions