【问题标题】:how to manage sqlite database lite version to paid version in iphone application?如何在 iphone 应用程序中管理 sqlite 数据库精简版到付费版本?
【发布时间】:2013-07-09 05:11:44
【问题描述】:

我使用 sqlite db 创建了 iPhone 应用程序。在这个 sqlite db 中,我有故事文档、目录图像 url 和其他参数。当用户使用应用程序的“精简版”版本时,一切正常。但是当我将应用程序从“精简”版本升级到“付费”版本时,我希望能够将我的 Documents 目录中的数据库和最新文件复制到“付费”应用程序。我们将不胜感激。

【问题讨论】:

  • 我的问题是,当我从 App Store 升级我的 iPhone 应用程序新版本时,我从 sqlite 数据库获取字符串数据并显示在应用程序中,但我没有使用照片 url 在文档目录中获取照片。意味着问题是升级后应用程序没有在文档目录中获取照片?
  • @TBlue 升级应用后我的问题。我不仅看到了我存储在旧版本应用程序中的那些图像,而且还看到了它会显示的新添加图像。希望你能理解我的 pblm

标签: ios objective-c


【解决方案1】:

如果 Documents 目录中的数据库,那么在更新您的应用程序时,iOS 会保留旧数据库。

【讨论】:

  • 在我的应用程序中,我将图像 url 存储在 sqlite db 中,图像存储在文档目录中。当我升级应用程序时,其他包含获取并显示在应用程序中,例如图像名称、其他参数值,但只有问题图像没有显示在应用程序中。
  • 您好,我了解这种情况。这个问题不清楚你的担忧。请更新或提出有关此问题的新问题。
【解决方案2】:

由于应用沙盒,您无法完全按照自己的意愿行事,但有多种方法:

  1. 只有一个应用程序版本,而不是单独的专业版,它提供启用某些功能的应用内购买。见Convert the "lite app" to "pro app" within the application。因此,这消除了将文件/设置从一个应用程序导入另一个应用程序的需要。

  2. 您可以为您的应用的免费版和专业版实施单独的custom URL scheme,以允许它们通过 URL 交换有限数量的数据。因此,专业版应用程序可能会在第一次运行时检查是否安装了精简版应用程序,如果是,则向其请求数据:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
        BOOL runAlready = [userDefaults boolForKey:kRunAlready];
    
        if (!runAlready)
        {
            [userDefaults setBool:YES forKey:kRunAlready];
            [userDefaults synchronize];
    
            [self importDataFromLite];
        }
    }
    
    - (void)importDataFromLite
    {
        NSURL *liteURL = [NSURL URLWithString:@"testapp-lite://getdata"];
    
        // if we can open test app, then test app installed, so launch it, providing "getdata" request
    
        if ([[UIApplication sharedApplication] canOpenURL:liteURL])
        {
            // Getting data from lite app
    
            [[UIApplication sharedApplication] openURL:liteURL];
        }
    }
    

    精简版显然必须设置它的 Info.plist 来注册这个自定义 URL 方案,并且它的应用程序委托需要响应这个数据请求,进而调用专业应用程序的自定义 URL 方案来发送返回数据:

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
    {
        [[[UIAlertView alloc] initWithTitle:nil message:[url absoluteString] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
    
        if ([[url absoluteString] isEqualToString:@"testapp-lite://getdata"])
        {
            // I'm going to create URL from local NSDictionary, but you would presumably retrieve data from your model/database
    
            NSDictionary *dictionary = @{@"name" : @"Rob", @"age" : @"29"};
    
            NSMutableArray *array = [NSMutableArray array];
            [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, NSString *obj, BOOL *stop) {
                [array addObject:[NSString stringWithFormat:@"%@=%@", key, [obj stringByAddingPercentEscapesForURLParameterUsingEncoding:NSUTF8StringEncoding]]];
            }];
    
            // now create the URL
    
            NSURL *proURL = [NSURL URLWithString:[NSString stringWithFormat:@"testapp-pro://data?%@", [array componentsJoinedByString:@"&"]]];
    
            // if we can open pro app, then then do so, providing "getdata" request
    
            if ([[UIApplication sharedApplication] canOpenURL:proURL])
            {
                NSLog(@"Opening pro app");
                [[UIApplication sharedApplication] openURL:proURL];
            }
        }
    
        return YES;
    }
    

    反过来,专业版可以有自定义 URL 方案来接收来自应用的精简版的数据。因此,pro 应用程序处理来自 lite 应用程序的数据的处理程序可能如下所示:

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
    {
        NSArray *absoluteStringComponents = [[url absoluteString] componentsSeparatedByString:@"?"];
        NSArray *parameters = [absoluteStringComponents[1] componentsSeparatedByString:@"&"];
        for (NSString *parameter in parameters)
        {
            NSArray *parameterComponents = [parameter componentsSeparatedByString:@"="];
    
            // I'm just logging the results, but you'd presumably integrate the results into your model
    
            NSLog(@"%@ is equal to %@", parameterComponents[0], [parameterComponents[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]);
        }
    
        return YES;
    }
    

    这适用于少量的基本数据,但我不认为它非常适合交换图像文件。如果有兴趣,我可以给你举个例子。

  3. 1234563专业版应用中的数据文件(看起来不优雅)。
  4. 理论上,您可以将数据存储在云端,可能是 iCloud、DropBox 或您自己的服务器。

【讨论】:

  • 顺便说一句,如果您尝试获得“创意”并尝试从一个应用程序的沙箱中打开文件,请注意仅适用于模拟器:我记得,模拟器不会观察到设备强制执行的应用程序沙盒规则。确保在实际设备上测试您的解决方案。
  • 如果我将使用 InApp Purchases 但我的问题是 lite 和 Pro 应用程序名称不同,那么如何管理它?
  • @suhas.porchys 如果您使用 IAP 方法,则只有一个应用程序,而不是两个单独的应用程序(这就是使用 IAP 的全部目的,以避免有两个应用程序;否则为什么还要执行 IAP ?)。我不确定我是否在关注您的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-03
  • 2020-08-03
  • 1970-01-01
  • 1970-01-01
  • 2016-04-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多