Is there a way for an app to get notified if a SD Card reader is plugged into the lightning port?

Lets say my app is in the foreground and the user plugs in/out a SD Card reader with an SD Card into the iPad's lightning port. Is there a notification posted to the app when this event happens?

Replies

In theory, yes. However I haven't been able to get it working yet in iOS 13 Beta 4.


Take a look at the ImageCaptureCore framework. In particular, ImageCaptureCore/ICDeviceBrowser.h. You would:


  1. Initialize the browser.
  2. Set the delegate.
  3. Start the browser.
  4. Your delegate should then receive "deviceBrowser:(ICDeviceBrowser*)browser didAddDevice:(ICDevice*)addedDevice" notifications.


For example:


#import <ImageCaptureCore/ImageCaptureCore.h>


    ...
    id deviceBrowser = [[ICDeviceBrowser alloc] init];
    deviceBrowser.delegate = self;
    [deviceBrowser start];


You should then receive notifications that a device was added. However, I have not been able to get this working in iOS 13 Beta 4. No notifications are received and the browser's "devices" property always returns an empty array.


Hopefully this will be working in futre releases.

In the past, the ability to communicate with a card reader has gone away during betas, at least with iOS 10, 11 and 12, so it's not surprising to see history repeat itself. Might need to wait until later in the beta cycle, or for iOS 13 release version.

Thanks for the answer. It still doesnt work in beta 8. The delegate is never called. I suspect that disk device insertion notification is related to the functionality offered by the Disk Arbitration Framework which exists in MacOS. Currently that framework doesnt exist in iOS/iPadOS

The code below is for macOS, iOS should be the same. I'm using this to detect a camera being plugged into a Mac.


    mDeviceBrowser = [[ICDeviceBrowser alloc] init];
    mDeviceBrowser.delegate = self;
    mDeviceBrowser.browsedDeviceTypeMask = ICDeviceLocationTypeMaskLocal|ICDeviceLocationTypeMaskRemote|ICDeviceLocationTypeMaskShared|ICDeviceLocationTypeMaskBluetooth|ICDeviceTypeMaskCamera;

//    ICDeviceLocationTypeMaskLocal     = 0x00000100,
//    ICDeviceLocationTypeMaskShared    = 0x00000200,
//    ICDeviceLocationTypeMaskBonjour   = 0x00000400,
//    ICDeviceLocationTypeMaskBluetooth = 0x00000800,
//    ICDeviceLocationTypeMaskRemote    = 0x0000FE00

    [mDeviceBrowser start];


To see all of this in full flight, take a look at the mac sample app for this called CameraBrowser.

https://developer.apple.com/library/archive/samplecode/CameraBrowser/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007761


https://developer.apple.com/library/archive/samplecode/SimpleCameraBrowser/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009232


I found two sample apps...


Hope that helps.


- David

  • Hi @dgwilson, thank you for the app examples. You don't happen to know of any more current ones? The sample app isn't building on my macOS 11.5.1

Add a Comment