可能重复:
Automatically close iOS Simulator when application is stopped in Xcode
就像标题所说,是否有可能让Xcode app中的代码停止并在完成后关闭模拟器?我问的原因是,如果我忘记手动关闭模拟器并让Xcode在运行模拟器的情况下运行,由于CPU周期要求运行模拟器,Macbook会变热。
答案 0 :(得分:2)
使用applescript关闭模拟器:
tell application "/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app"
quit
end tell
然后从您的应用中启动它:
NSString * pstrScript= @"tell application \"/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app\"\nquit\nend tell";
if(!pstrScript)
{
NSLog(@"Error ReadAlbumArtitunesOperation::runWIthParameters:: if(!pstrScript)\n");
return nil;
}
_script = [[NSAppleScript alloc] initWithSource:pstrScript];
if(!_script)
{
NSLog(@"ERROR ReadAlbumArtItunesOperation:: runWithParameters:: if(!_script)\n");
return nil;
}
NSAppleEventDescriptor* desc= [_script executeAndReturnError:&_errorInfo];
if( _errorInfo )
{
NSLog(@"Couldn't run script: err=%@",[_errorInfo description]);
}