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.

How can I get this? Thank you.

有帮助吗?

解决方案

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.

其他提示

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.

Or, you can use UserDefaults to store just whether the user has upgraded or not, and keep the storyboard names as constants in 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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top