xcode 我可以在应用程序中更改“主故事板文件基本名称”吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18009911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I change 'main storyboard file base name' in app?
提问by bureaucoconut
I have made a pro and lite version app using different target from an project. These two apps use different storyboard and info.plist file.
I want to make in app purchase button in lite version app for operating like pro version app. For do that, I need to change the storyboard file that lite version uses to pro version's storyboard file when users buy in app purchase feature.
The storyboard file name used is stored at 'main storyboard file base name' in xxx-info.plist file. So, can I change the storyboard file base name when users do something. I don't know it's possible or not.
我使用项目中的不同目标制作了专业版和精简版应用程序。这两个应用程序使用不同的 storyboard 和 info.plist 文件。
我想在精简版应用程序中制作应用程序内购买按钮,以便像专业版应用程序一样操作。为此,当用户购买应用程序购买功能时,我需要将精简版使用的故事板文件更改为专业版的故事板文件。
使用的故事板文件名存储在 xxx-info.plist 文件中的“主故事板文件基本名称”中。那么,当用户执行某些操作时,我可以更改故事板文件的基本名称吗?我不知道这可能还是不可能。
How can I get this? Thank you.
我怎样才能得到这个?谢谢你。
回答by Mundi
You can set it dynamically at startup:
您可以在启动时动态设置它:
// set storyBoardName according to upgrade status
UIStoryboard *storyBoard =
[UIStoryboard storyboardWithName:storyBoardName bundle:nil];
UIViewController *initViewController =
[storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
So I guess it is OK to start up the app again after upgrade.
所以我想升级后再次启动应用程序是可以的。
回答by Marius Waldal
Yes, in your AppDelegate application:didFinishLaunchingWithOptions:launchOptions method you can get the storyboard name from your plist, and then load the storyboard based on this setting. Or, you could store the storyboard name in UserDefaults instead, and update that setting after the user has paid for the pro version.
是的,在您的 AppDelegate application:didFinishLaunchingWithOptions:launchOptions 方法中,您可以从 plist 中获取情节提要名称,然后根据此设置加载情节提要。或者,您可以将情节提要名称存储在 UserDefaults 中,并在用户为专业版付费后更新该设置。
Or, you can use UserDefaults to store just whether the user has upgraded or not, and keep the storyboard names as constants in appdelegate:
或者,您可以使用 UserDefaults 来存储用户是否已升级,并将故事板名称保留为 appdelegate 中的常量:
#define kStoryboardLite @"LiteStoryboard.storyboard"
#define kStoryboardPro @"ProStoryboard.storyboard"
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *storyboardName;
NSString *userType = [[NSUserDefaults standardUserDefaults] objectForKey:@"userType"];
if ([userType isEqualToString:@"pro"]) {
storyboardName = kStoryboardPro;
} else {
storyboardName = kStoryboardLite;
}
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
UIViewController *initialViewController = [storyboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
}
If you use this approach, you would have to ask your user to restart the app to load the other storyboard.
如果您使用这种方法,您将不得不要求您的用户重新启动应用程序以加载另一个故事板。