根据我在此处找到的答案:https://stackoverflow.com/a/18121292/1701170,我有以下代码:
bool accessibilityEnabled = false;
// Check and make sure assistive devices is enabled.
if (AXIsProcessTrustedWithOptions != NULL) {
// 10.9 and later
NSDictionary *options = @{(id)kAXTrustedCheckOptionPrompt: @YES};
accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options);
} else {
// 10.8 and older
if (AXAPIEnabled() == true) {
accessibilityEnabled = true;
}
}
if (accessibilityEnabled) {
// do something
}
我得到的错误如下:
[apply] error: use of undeclared identifier 'NSDictionary'; did you mean 'UseDictionary'?
[apply] NSDictionary *options = @{(id)kAXTrustedCheckOptionPrompt: @YES};
[apply] ^~~~~~~~~~~~
[apply] UseDictionary
我必须导入NSDictionary吗?
文件顶部的导入如下:
#include <pthread.h>
#include <sys/time.h>
#include <ApplicationServices/ApplicationServices.h>
#include "NativeErrors.h"
#include "NativeGlobals.h"
#include "NativeHelpers.h"
#include "NativeThread.h"
#include "NativeToJava.h"
#include "OSXInputHelpers.h"
这是我第一次看到Objective-C。
答案 0 :(得分:3)
您链接的项目对我来说就像一个普通的C项目。 NSDictionary是一个Objective-C类,是Apple的Foundation框架的一部分。您必须链接Foundation.framework并确保它已在您的源中导入。如果您只是在尝试,最好的办法可能是使用命令行工具(类型为Foundation)模板在Xcode中创建一个新项目。