简体   繁体   English

带有相同NSUserdefaults的免费和高级游戏

[英]Free & premium game with both same NSUserdefaults

I Want to publish 2 versions of my game, 1 for free with advertisement and 1 premium. 我想发布我的游戏的2个版本,其中1个带有广告免费和1个高级版。

But if the user is in level 9 in the free version and it buys the premium, than it should begin from level 9 in the premium version. 但是,如果用户在免费版中处于第9级,并且购买了高级版,则应该从高级版中的第9级开始。

How do I do this? 我该怎么做呢?

You can take advantage of the ability to share NSUserDefaults suites between applications. 您可以利用在应用程序之间共享NSUserDefaults套件的功能。

[[NSUserDefaults alloc] initWithSuiteName:@"yourGroupIdentifier"];

To enable your apps for this functionality you need to enable App Groups in your targets: 要为您的应用启用此功能,您需要在目标中启用应用组:

  • Select the project file in the Xcode Project Navigator 在Xcode Project Navigator中选择项目文件
  • Select your target 选择你的目标
  • Select the tab Capabilities 选择选项卡功能
  • Enable App Groups and give it a name ("yourGroupIdentifier") 启用应用程序组并为其命名(“ yourGroupIdentifier”)

Initialising NSUserDefaults as shown above in both your apps will enable you to read and write the same defaults from both apps. 如上所示在两个应用程序中初始化NSUserDefaults将使您能够从两个应用程序读取和写入相同的默认值。

Having said that, I would suggest to use an In-App Purchase to unlock the pro version, instead of having 2 different products; 话虽如此,我建议您使用应用内购买来解锁专业版,而不要使用2种不同的产品; for a better user experience. 以获得更好的用户体验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM