iOS-用于检测故事板的iPad/iPhone设备的逻辑

iOS-用于检测故事板的iPad/iPhone设备的逻辑

问题描述:

我需要在我的App Delegate文件中将我的情节提要板定义为身份验证脚本的一部分,该脚本用于将相关数据传递到特定视图.

I need to define my storyboard as part of an Authentication script in my App Delegate file - which is used to pass relevant data to particular views.

一切正常-但通过以此方式定义情节提要,我覆盖了所有设备(iPad或iPhone)的路径,我希望我的应用程序具有通用性,并遵循依赖于设备的不同情节提要-因此,理想情况下,我希望想检测设备并将相关的故事板ID应用于变量,以便运行正确的故事板,并且身份验证脚本仍能正常运行-但我不确定如何执行此操作.

All works fine - but by defining my storyboard in this way I overwrite the path for all devices (iPad or iPhone), i'd like my app to be universal and follow different storyboards dependant on device - therefore ideally I'd like to detect the device and apply the relevant storyboard ID to a variable so the correct storyboard runs and the authentication script still functions properly - but I'm not sure how to do this..

到目前为止,这是我的代码-

This is my code so far -

 UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"ipad_story" bundle:nil];
 UIViewController *controller;
 UINavigationController *navigationController;

情节提要能否包含检测设备并应用ipad_story或ipad_phone的逻辑?

Could the storyboard contain logic to detect the device and either apply ipad_story or ipad_phone?

有两个选项,请使用iOS设备修饰符~ipad,因此您将拥有类似main_story(适用于iphone)和main_story~ipad(适用于iPad)的故事.

There are two options, use the iOS device modifier, ~ipad, so you will have story like main_story for iphone and main_story~ipad for iPad.

或者如果您需要在代码中检测到它,请查看

Or if you need to detect it in code look at the UIUserInterfaceIdiom :

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
    // iPad
} else {
    // iPhone
}

如果可能的话,应该使用第一个选项,仅当必须在代码中执行时,才需要第二个op选项.

The first option should be used if possible, the second op option is only need if you have to do it in code.