Use FSEvents in sandboxed app

混江龙づ霸主 提交于 2019-12-12 08:48:16

问题


I'm trying to use FSEvents in my sandboxed app to monitor some directories. I implemented the following class:

@implementation SNTracker

- (id)initWithPaths:(NSArray *)paths {
    self=[super init];
    if (self) {
        trackedPaths=paths;
        CFTimeInterval latency=1.0;
        FSEventStreamContext context={0,(__bridge void *)self,NULL,NULL,NULL};
        FSEventStreamRef eeventStream=FSEventStreamCreate(kCFAllocatorDefault,&callback,&context,(__bridge CFArrayRef)trackedPaths,kFSEventStreamEventIdSinceNow,latency,kFSEventStreamCreateFlagUseCFTypes|kFSEventStreamCreateFlagWatchRoot|kFSEventStreamCreateFlagFileEvents);
        FSEventStreamScheduleWithRunLoop(eeventStream,[[NSRunLoop mainRunLoop] getCFRunLoop],kCFRunLoopDefaultMode);
        FSEventStreamStart(eeventStream);
    }
    return self;
}

static void callback(ConstFSEventStreamRef streamRef,void *clientCallBackInfo,size_t numEvents,void *eventPaths,const FSEventStreamEventFlags eventFlags[],const FSEventStreamEventId eventIds[]) {
    NSLog(@"asd");
}

The problem is that "asd" never gets printed (i.e. the callback function is never called). When I disable "Enable App Sandboxing" in the Summary of my main target in Xcode, the callback gets called. Am I doing something wrong? The only entitlement I've given to the sandboxed app is read-write access to user selected files.


回答1:


And the usere has selected the path you are trying to monitor via FSEvent? Since if he hasn't, you won't be allow to access it and thus also not monitor it. A path can only be monitored as long as you are allowed to access it.



来源:https://stackoverflow.com/questions/14957747/use-fsevents-in-sandboxed-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!