Receive Darwin Notification on Cable Connection

I have a project requirement that my iOS App (written in Swift) should get notification when the iPhone gets connected to an Android device/Mac through a cable (e.g. lightning-to-usb).

I heard this is possible with Darwin Notification but I've never worked with it before, and seems like there isn't any well-documented article that contains all about Darwin Notification from Apple.

Can anyone help me with which notification (status/identifier) of the Darwin Notification Centre to look for to get notified when such wired connection is made between two devices (one being iPhone ofcourse)?

Replies

AFAIK there’s no public API to be notified when the iPhone is connected to another machine via USB. This kinda makes sense in that there are no APIs that operate over USB [1], and thus there’s no reason to know whether there’s a connection.

What do you intend to do with that info?

I heard this is possible with Darwin Notification

That may be true but, if so, that’s not considered API. For a list of Darwin notification keys that are considered API, see <notify_keys.h>.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Specifically. There are APIs that can work over USB — for example, External Accessory framework can talk to accessories and the networking APIs can work over a USB Ethernet adaptor — but those APIs all have their own mechanisms for service discovery.

Ok, if that's not possible, I am left with another option (and this is the preferred one).

How can I emit Darwin notification from one iOS device, and receive the notification from another, provided that the two devices are connected to each-other via a wired-connection?

I know I can achieve this using a TCP/IP wireless connection, but I need to do this specifically for Wired Connection and using Darwin...

It’s hard to offer any suggestions without an answer to the question I posed in my previous response:

What do you intend to do with that info?

You’re outlining a bunch of constraints without explaining those constraints, and that gives us no idea what might work. For example, you wrote:

I know I can achieve this using a TCP/IP wireless connection, but I need to do this specifically for Wired Connection

TCP/IP doesn’t necessarily imply Wi-Fi. iOS supports Ethernet out of the box [1]. Is that acceptable? I can’t say without more context.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Presuming that “the box” is the one that your USB Ethernet adaptor shipped in (-: