Gre*_*reg 24 iphone test-data ios eventkit ios-simulator
在我的iPhone应用程序代码中,任何示例代码都会告诉我如何:
任何其他更好的建议如何在模拟器上掩盖管理这些测试数据将是好的.这里的背景是我在谈论日历中的测试数据(例如使用事件工具包),所以当我部署到我的设备时,我不希望应用程序将日历项目放入我的iPhone(对不起 - 只有1个人iPhone在这里).
zrz*_*zka 49
我显然使用这样的东西......
#import <TargetConditionals.h>
#if TARGET_IPHONE_SIMULATOR
// Simulator specific code
#else // TARGET_IPHONE_SIMULATOR
// Device specific code
#endif // TARGET_IPHONE_SIMULATOR
Run Code Online (Sandbox Code Playgroud)
对于你的第二个问题......这样的事情可以帮助你.在您的app委托中:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ( ! [[NSUserDefaults standardUserDefaults] boolForKey:@"initialized"] ) {
// Setup stuff
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"initialized"];
}
... your code ...
}
Run Code Online (Sandbox Code Playgroud)
mah*_*tin 12
如果您想检查运行时(而不是使用#compiler宏编译时间),请使用以下代码:
UIDevice *currentDevice = [UIDevice currentDevice];
if ([currentDevice.model rangeOfString:@"Simulator"].location == NSNotFound) {
//running on device
} else {
// running in Simulator
}
Run Code Online (Sandbox Code Playgroud)
另请参阅此问题: 如何以编程方式确定我的应用程序是否在iphone模拟器中运行?
Niy*_*Ray 11
斯威夫特 5:
TARGET_OS_SIMULATOR
在 Swift 5. 中不起作用targetEnvironment(simulator)
,如下所示:
#if targetEnvironment(simulator)
// code to run if running on simulator
#else
// code to run if not running on simulator
#endif
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17910 次 |
最近记录: |