Post not yet marked as solved
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)?
Post not yet marked as solved
I'm trying to learn how to use Darwin Notifications, and I'm having trouble getting my callback function to trigger. I've been writing a command line tool just to learn how to get Darwin notifications working, but eventually will use them in an iPhone app. I have sample code below; can anyone with Darwin Notifications experience point out what am I doing wrong?
//callback
static void myCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
NSLog(@"In callback function");
}
int main(int argc, const char * argv[]) {
// Add Observer
CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, //observer
myCallback, //callback
CFSTR("sanity_check"), //event name
NULL, //object
CFNotificationSuspensionBehaviorDeliverImmediately
);
// Post notification 1
CFNotificationCenterPostNotification(
CFNotificationCenterGetDarwinNotifyCenter(), // center
CFSTR("sanity_check"), // event name
NULL, //object
NULL, //userinfo dictionary
true);
// Post notification 2
notify_post("sanity_check");
return 0;
}