Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 目标C回调失败_Objective C_Callback_Iokit - Fatal编程技术网

Objective c 目标C回调失败

Objective c 目标C回调失败,objective-c,callback,iokit,Objective C,Callback,Iokit,我有发布通知处理程序的代码 IONotificationPortRef notificationPortRef = IONotificationPortCreate(kIOMasterPortDefault); if (!notificationPortRef) { return nil; } CFRunLoopSourceRef notificationRunLoopSource = IONotificationPortGetRunLoopSource(notificationPor

我有发布通知处理程序的代码

IONotificationPortRef notificationPortRef = IONotificationPortCreate(kIOMasterPortDefault);
if (!notificationPortRef)
{
    return nil;
}

CFRunLoopSourceRef notificationRunLoopSource = IONotificationPortGetRunLoopSource(notificationPortRef);
if (!notificationRunLoopSource)
{
    CFRelease(notificationPortRef);
    return nil;
}
CFRunLoopAddSource(CFRunLoopGetCurrent(), notificationRunLoopSource, kCFRunLoopDefaultMode);

CFDictionaryRef matching = IOServiceMatching (kIOUSBDeviceClassName);
if (!matching)
{
    CFRelease(notificationPortRef);
    return nil;
}

io_iterator_t matchingIterator;
kern_return_t result = IOServiceAddMatchingNotification(notificationPortRef,
                                                        kIOMatchedNotification,
                                                        matching,
                                                        &driverNotificationRoutine,
                                                        self,
                                                        &matchingIterator);

driverNotificationRoutine(self, matchingIterator);

if (result != KERN_SUCCESS)
{
    CFRelease(notificationPortRef);
}

CFRunLoopRun();
这个回调处理程序

static void driverNotificationRoutine (void *refcon, io_iterator_t matchingIterator)
{
    NSLog(@"Callback called.");

    if (matchingIterator)
    {
            io_service_t device;
            NSInteger count = 0;
            while (device = IOIteratorNext(matchingIterator)) count++;
            IOObjectRelease(matchingIterator);

            if (count)
            {
                    ...
            }
    }
}
但我的回调函数从未被调用。我用USB闪存驱动器尝试了一下,但没有成功。我错在哪里?

不应该有错误

IOObjectRelease(matchingIterator);
在回调函数中