我试图对目录进行文件监控,从苹果文档中获取代码。它崩溃在fseventstreamcreate函数调用时出现此错误:
异常类型:EXC_BAD_ACCESS(SIGSEGV)
例外代码:KERN_INVALID_ADDRESS位于0x0000000000000008
我对目标C相当新(虽然我知道这是C代码,它是一个obj-c应用程序的一部分)并且真的不知道为什么会崩溃,这是一个noob错误。我很感激任何帮助。
void monitorCallback(
ConstFSEventStreamRef streamRef,
void *clientCallBackInfo,
size_t numEvents,
void *eventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[])
{
int i;
char **paths = (char**)eventPaths;
// printf("Callback called\n");
for (i=0; i<numEvents; i++)
{
/* flags are unsigned long, IDs are uint64_t */
printf("Change %llu in %s, flags %u\n", eventIds[i], paths[i], eventFlags[i]);
}
}
- (void) monitorFolder
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString * monitorFolder = [[NSUserDefaults standardUserDefaults] objectForKey:@"monitorFolder"];
//Create stream to monitor for changes.
CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&monitorFolder, 1, NULL);
FSEventStreamRef stream;
CFAbsoluteTime latency = 3.0; /* Latency in seconds */
/* Create the stream, passing in a callback */
stream = FSEventStreamCreate(
NULL,
(FSEventStreamCallback)&monitorCallback,
NULL,
pathsToWatch,
kFSEventStreamEventIdSinceNow,
latency,
kFSEventStreamCreateFlagNone );
...
}