OSX에서 볼륨의 외관/사라짐 감지
-
05-07-2019 - |
문제
사용자가 USB 키를 삽입하고 외부 디스크 및 마운트 디스크 이미지를 추가 할 때 스토리지 장치 목록을 업데이트하고 싶습니다. iokit의 ioServiceaddinterestNotification은 갈 길처럼 보이지만 KiomeDiaclass에 일반적인 관심을 등록하는 것이 명백한 사용은 볼륨의 수소를 마치고 때로는 알림 만 제공합니다.
이것을하는 올바른 방법은 무엇입니까?
해결책
Diskittration에서 다음과 같은 전화 .H 내가 원하는 것을 정확하게 수행합니다.
DARegisterDiskAppearedCallback
DARegisterDiskDisappearedCallback
DARegisterDiskDescriptionChangedCallback
이 커버 삽입, 제거 (셀 수없는 볼륨조차도)
메타 데이터 변경 이벤트.
추신 : 추가하는 것을 잊지 마십시오 DASession
런 루프에
또는 콜백을 얻지 못합니다.
다른 팁
사용자가 USB 키를 삽입하고 외부 디스크 및 마운트 디스크 이미지를 추가 할 때 스토리지 장치 목록을 업데이트하고 싶습니다.
이 코드로 3 개 중 2 개를 얻을 수 있습니다.
File: USBNotificationExample.c
Description: This sample demonstrates how to use IOKitLib and IOUSBLib to set up asynchronous
callbacks when a USB device is attached to or removed from the system.
It also shows how to associate arbitrary data with each device instance.
USB HDD의 연결을 모니터링하기 위해 개인적 으로이 코드의 약간 수정 된 사본을 오랫동안 사용했습니다.
이 작은 샘플에서 볼 수 있듯이 장착 드라이브를 모니터링하는 데 쉽게 적응할 수 있습니다. 아니면 그렇지 않을 수도 있습니다. ymmv.
matchingDict = IOServiceMatching(kIOUSBDeviceClassName); // Interested in instances of class
// IOUSBDevice and its subclasses
그리고 그것이 일치 할 때
void DeviceAdded(void *refCon, io_iterator_t iterator)
{
kern_return_t kr;
io_service_t usbDevice;
IOCFPlugInInterface **plugInInterface=NULL;
SInt32 score;
HRESULT res;
while ( (usbDevice = IOIteratorNext(iterator)) )
{
io_name_t deviceName;
CFStringRef deviceNameAsCFString;
MyPrivateData *privateDataRef = NULL;
UInt32 locationID;
printf("Device 0x%08x added.\n", usbDevice);
그리고 그렇게. 등.
보고있을 것입니다 /Volumes
변경을 위해 필요한 것을 수행합니까?
코코아 수준에서 일하는 경우 다음 알림을 받기 위해 등록 할 수도 있습니다. nsworkspace:
- nsworkspacedIdMountNotification
- nsworkspacedidrenamevolumenotification
- nsworkspacewillunmountnotification
- nsworkspacedIdUnMountNotification
제휴하지 않습니다 StackOverflow