在沙箱应用中使用FSEvents [英] Use FSEvents in sandboxed app

查看:179
本文介绍了在沙箱应用中使用FSEvents的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的沙盒应用程序中使用FSEvents来监视一些目录。我实现了以下类:

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");
}

的问题是,ASD永远不会被印刷(即回调函数从未调用)。当我在Xcode的主目标的摘要中禁用启用应用程序沙盒时,回调被调用。我做错了什么吗?我已经给了沙盒应用程序的唯一权利是可读写访问用户选定的文件。

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.

推荐答案

而usere有选择您尝试通过FSEvent监视的路径?因为如果他没有,你将不被允许访问它,因此也不监视它。只有在您允许访问路径时,才能监控路径。

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.

这篇关于在沙箱应用中使用FSEvents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆