swiftmacosmac-catalystmtp

macOS Catalyst: How to read a USB device with Media Transfer Protocol? Is it possible with IOUSBHost API?


I want to make a macOS app (Catalyst) interact with Nintendo Switch by USB cable. I found that Nintendo Switch will use MTP when launch “Copy to a Computer via USB Connection” function inside system settings.

Besides, I found an API, IOUSBHost, in Apple’s developer document. (https://developer.apple.com/documentation/iousbhost)

So my question is, is this API possible used with USB MTP devices? If not, can I found any alternative ways to achive that read USB MTP devices with macOS Catalyst?


Solution

  • Suggesting interaction you need is copy files to and from Nintendo Switch, I would say you don't really need to create a driver to do the thing, and IOUSBHost is far too deep for your purposes.

    There are already some implementations for MTP on macOS which I would start with.

    Try libmtp: via homebrew, with their sourceforge or forks on github.

    libmtp is written in C, you will need to create a wrappers or use a bridging header if you want to use them in Swift to develop some complex application.

    There are also some helpers for macOS that could work for you or could not.

    Anyway, if the files-oriented interaction is what you want, focus on MTP libraries to implement things you need, not USB stuff.