Sync: “Slide to cancel”

Slide to CancelYeah, I’ve just found out how to handle this and terminate sync when user slides cancel switch.

We need following functions (meta-language):

ERROR AMDObserveNotification(HANDLE proxy, CFSTR notification);
ERROR AMDListenForNotifications(HANDLE proxy, NOTIFY_CALLBACK cb, USERDATA data);

and callback delegate:

typedef void (*NOTIFY_CALLBACK)(CFSTR notification, USERDATA data);

First, we need AMDObserveNotification to subscribe notifications about “com.apple.itunes-client.syncCancelRequest”. Then we should start listening for notifications (second function) until we get “AMDNotificationFaceplant”.
That’s it. When notification got, you should unlock and close lock file handle (don’t sure if you need to post “syncDidFinish” to proxy, seems it doesn’t matter) and terminate sync gracefully.

P.S. The same notification is also got when you unplug your device, so you should always be ready for errors.

Leave a Reply