MacOS app - Detecting\Reading from storage devices

Hi!

I am just starting with MacOS development, and I was looking online for ways to interact with any storage devices being mounted on the system (both detecting and reading from them). All the code references I've found to do something like that, make use of the IOKit Registry and interfaces; and also are from many years ago.

I was wondering if that keeps being the only way to achieve this or there is even a higher-level abstraction to interact with those devices in Swift?

Any help or references would be appreciated, Thanks!

I was looking online for ways to interact with any storage devices being mounted on the system (both detecting and reading from them).

Can you provide more details about your goals here?

[is there] a higher-level abstraction to interact with those devices in Swift?

Well, the high-level abstraction for dealing with storage devices is the file system, but I don’t think that’s what you’re looking for (-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Yes, I am sorry for being quite generic (and my bad english). What I would like to do is to detect any USB storage device and then read content from them; I would like to even do so with phones if possible, but I do not sincerely understand if they can be mounted as drives (and how in any case) and be interacted with, the same way through IOKit.
As you can probably see by my descriptions, I am not very knowledgeable on the topic, so that's why I am asking this before digging into the whole I/O Registry stuff.

Thanks a lot for the answer!

What I would like to do is to detect any USB storage device and then read content from them

Read blocks? Or read files?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Whole files, if that's the case could I use the FileManager class, accessing the URI of the mounted volume?

From my very small knowledge and what I've been reading online, I would need to use the IOServiceAddMatchingNotification to register a callback to get notified of any new device driver being created in the I/O Registry.
I do not know how to match specifically the devices I want ( USB storage drives ), and neither if I could access a property in the Registry that would map to the URI accessible via FileManager; assuming the FileManager would indeed serve to read the files in there.

I had probably missed entirely in my understanding, my apologies if that's the case. Any guidance is appreciated, thanks for bearing with me!
Accepted Answer
If you want to read files then this job is much easier than you’ve feared. You can call mountedVolumeURLs(includingResourceValuesForKeys:options:) to get the current volume list and register for didMountNotification and didUnmountNotification to learn about changes.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Ohh, I had not come across those.
I will make sure to try them.

Thanks a lot for the patience and assistance!!
MacOS app - Detecting\Reading from storage devices
 
 
Q