Mojave: OpenDialog to select an Image File / Access to "Photos"

In order to let the user select an Image File, we have to use code like this (copied more or less from Xojo’s FileType documentation):

[code]Dim pngType As New FileType
pngType.Name = “image/png”
pngType.Extensions = “png”

Dim d As New OpenDialog
d.Filter = jpegType + pngType
d.Title = “Select an Image”
d.InitialDirectory = SpecialFolder.UserHome

Dim f As FolderItem = d.ShowModal[/code]

In an application built with Xojo <= 2018r3:
This will immediately pop up on of these Mojave Security Questions: “Would you like to allow XYZ to access your Photos”?

In an application built with Xojo >= 2018r4:
Nothing special at the first glance. No security warning - the InitialDirectory shows and allows to pick a file.

What’s special is that Finder shows a section “Media: Photos” on the left, as soon as we use a .Filter for jpg, png, and probably other Picture/Image types.

That makes this “security warning” more obvious… With Xojo built apps (up until 2018r3), the Mojave-user always gets a warning (well, the first time the app is used) when trying to open an Image File. If this warning is accepted, one can select an Image from the Photos Library.
With Xojo 2018r4 built apps, the “Media: Photos” is there - but nothing will happen.

The trick is once again to add an Info.plist to the Xojo project containing:

[code]<?xml version="1.0" encoding="UTF-8"?>

NSPhotoLibraryUsageDescription Allow photos to be selected from the photo library. [/code]

To reset the access list to Photos in Mojave, you can execute this command in Terminal:

tccutil reset Photos

So in a “fresh start” (an app built with Xojo 2018r4 and this Info.plist):
Nothing special to notice at first - the .InitialDirectory shows an allows the Mojave-user to pick an Image File. If the user tries to use “Media: Photos” or “UserHome:Pictures” in Finder, the security warning will now show up (and if accepted, it’s possible to select a Photo from Photos Library or the designated Pictures Folder).
Kind of what’s expected - but I haven’t found this information in the Xojo documentation.

Having said that… is there some way to not even enable that “Media: Photos” in Finder?
I don’t want “Xojo <= 2018r3” applications to ask the user for access to their “Photos Library” if I want to let them select an Image File. Same for “Xojo >= 2018r4”: I may explicitly don’t want to use a “Photo (from Photos Library)” - just an ordinary Image File in some folder.
Why is the Xojo Framework adding this “Media section”? It may be default macOS behavior - but then again: is there some way to prevent this?

It seems that just not providing the Info.plist will kind of do that trick. The user can’t choose a Photo out of the “Photos Library” (even though it’s visible in Finder). But it’s also not a great user experience, since this “Media:Photos” can be clicked - and nothing happens (apart from a spinning wheel in Finder).

Regarding the designated “Pictures” folder in UserHome:
Note that without the Info.plist: selecting a File in that folder is possible (without warning). I kind of like this (downside is the “spinning wheel” when trying to select “Media: Photos”).
With the Info.plist: the security warning (with explanation) will show once this folder is being selected. I think this is kind of “wrong” - but most likely Apple wants it that way. I’d prefer to only see this warning if the user actually selects the “Photos Library”. Well… that doesn’t seem to be up to us :slight_smile:

How does “Pixelmator” do this? With that application, I can open any Image in the “Pictures” folder and from my “Photo Library” without getting any warning on Mojave…?

First of all, up until Xojo 2018r3 your apps had been telling the OS that it was linked against the 10.9 SDK, but In 2018r4, we bumped that up to the macOS 10.14 SDK.

It was around the release of macOS 10.10 that Apple started requiring the plist entries for requesting access to the privacy sensitive sections of user accounts, things like photos, music, camera, microphone, etc.

With regards to the Media: Photos section, I suspect that what you’ll find is that it’s always there. In my case, if I remove the filters, I get:

Media: Music Media: Photos Media: Movies

It’s only when I specify the file types that it gets “filtered” down to only show the Photos section.

As a matter of fact, if you use a filter that has “audio/mp3” and “mp3”, only the Media: Music section appears.

I suspect the answer to this is that it’s the OS that’s supplying these items.

Entitlements & Sandbox. In Xcode a sandboxed app can specify that it needs access to a user’s Pictures with Read-Only or Read/Write access.

I know… that’s why it seems we have to provide a NSPhotoLibraryUsageDescription on our own now - even though I haven’t found that documented or mentioned in the Xojo Documentation :slight_smile:
That’s the main reason why I’ve posted this Thread.

That’s my suspicion, too… Thanks for testing with the other “Media” types.
But my question has been if there is a way to “hide” them programmatically. So far, I doubt it.

Ah, right - that could account for the difference in behavior that I see with “non sandboxed apps”.

Or in other words:
Is Apple to blame that they show “Media: Photos” even if an application doesn’t provide a NSPhotoLibraryUsageDescription?
Or does the Xojo Framework contain Code to deal with “Photos Library”, which causes the OpenDialog to show it? Is it possible at all to have an OpenDialog without this “Media section” (if one wants to just access Files on Disk, not out of Media-Libraries)?