title: How to read files of External Mass Storage Devices Without DocumentPicker? (iOS)
body: <p>Just to give some context, there is an iOS app I'm building (in Xamarin) that requires the ability to fetch files <strong>(in an automatic way <strong>without</strong> having the user to navigate to the files and select them manually)</strong> that are stored on External Storage Devices (USB Sticks), and are connected (paired) to an iPhone/iPad.</p>
  <p><strong>Users connect a lighting cable to the iOS Devices, and plug their USB Sticks into this lighting cable.</strong> Here is an example of the cable that end users use to pair the USB Sticks with their iPhone/iPad, and the app then auto fetches these files from the USB Storage Devices.</p>
  <p><a href="https://i.stack.imgur.com/EXx62.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EXx62.png" alt="enter image description here" /></a></p>
  <p>The app then performs 2 functions:</p>
  <ol>
  <li>It listens to notifications, for when a usb stick is paired with the iOS Device.</li>
  <li>When it receives this notification, it then proceeds with querying the files on the USB Stick, and reads and processes the files. The app reads these files automatically and the user does not need to manually select these files</li>
  </ol>
  <p>I've tried using External Accessory Framework, however that's only suitable for devices that you register with the MFi program.
  <a href="https://developer.apple.com/documentation/externalaccessory" rel="nofollow noreferrer">https://developer.apple.com/documentation/externalaccessory</a></p>
  <p>Notifications Center never seems to work (the Notifications that handle when a Device gets Connected and Disconnected, the delegates never get called), and I've tried using the Microsoft Helpers.</p>
  <p><a href="https://docs.microsoft.com/en-us/dotnet/api/externalaccessory.eaaccessorymanager.notifications.observedidconnect?view=xamarin-ios-sdk-12" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dotnet/api/externalaccessory.eaaccessorymanager.notifications.observedidconnect?view=xamarin-ios-sdk-12</a></p>
  <p>I've also tried some 3rd party libraries, but haven't found anything useful.</p>
  <p>It doesn't look Apple has any Api Available to auto query and read the files, without having to use a DocumentPickerController. I know this is because of the App Sandbox, and I cannot directly access the Removable Storage Devices.</p>
  <p>Now for my questions:</p>
  <ol>
  <li><strong>Are there any 3rd party libraries anybody can recommend, that can help achieve most of the heavy lifting for this task</strong>? I'd prefer a library that's compatible with Xamarin, however if it's a native library (Swift or Objective-C Library, Cocoapods) I'm sure there is a binding I can use on nuget.</li>
  <li><strong>Does anybody have any snippets, or documentation, or can point me in the right direction here (Please feel free to post Swift, or Objective-c solutions here if you like)</strong>? Where should I look, which Apple Framework (iOS SDK) is most suitable to deal with this situation. And to summarise, is what I'm asking for at all possible on iOS, without having to jailbreak, or get around the App Sandbox?</li>
  </ol>
  <p><strong>Update</strong></p>
  <p>So I've tried the solution that @Saamer suggested:
  <a href="https://stackoverflow.com/questions/46883205/detect-if-usb-is-connected-to-iphone-device/46976113#46976113">Detect if USB is connected to iPhone device</a></p>
  <p>Here is an example I wrote just to verify if the callback gets invoked, and the app can detect if a usb is plugged in.</p>
  <pre><code>CFNotificationCenter.Darwin.AddObserver(&quot;com.apple.mobile.lockdown.host_attached&quot;, null, (e, s) =&gt;
          {
              MainThread.BeginInvokeOnMainThread(async () =&gt;
              {
                  var picker = await Xamarin.Essentials.FilePicker.PickAsync();
              });
      }, CFNotificationSuspensionBehavior.DeliverImmediately);
  </code></pre>
  <p>A file picker should immediately get invoked, and open up, once I plug the USB in, <strong>however this doesn't happen.</strong></p>
  <p><strong>I'm happy for a solution right now which opens up a file picker, when the user plugs in a USB Device, and navigates to the root directory to start off with. So when the File Picker opens up the user should see this.</strong> Then they can select the files they want to transfer into the app.</p>
  <p><a href="https://i.stack.imgur.com/B4TY3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B4TY3.png" alt="enter image description here" /></a></p>