有没有办法阻止Mac使用Objective-C以编程方式进入睡眠状态?Apple开发站点上的I/O工具包基础部分告诉我驱动程序会收到空闲/系统睡眠的通知,但我找不到阻止系统休眠的方法.它甚至可能吗?
我遇到了一些使用咖啡因,摇晃,失眠甚至AppleScript的其他解决方案,但我想在Objective-C中这样做.谢谢.
我正在使用MacOS-X 10.6.7和Xcode 4.0.2上的Objective-C中的respondsToSelector方法来识别对象是否会响应某些消息.根据手册,NSString不应该响应appendString:而NSMutableString应该.这是测试它的代码片段:
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *myString = [[NSString alloc] init];
if ([myString respondsToSelector:@selector(appendString:)]) {
NSLog(@"myString responds to appendString:");
} else {
NSLog(@"myString doesn't respond to appendString:");
}
// do stuff with myString
[myString release];
[pool drain];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
Class02[10241:903] myString responds to appendString:
Run Code Online (Sandbox Code Playgroud)
我有点期待相反的事情.NSString对象如何响应appendString:这里发生了什么,我失踪了?