【问题标题】:Download localizable 'strings' files from server从服务器下载可本地化的“字符串”文件
【发布时间】:2013-12-18 02:14:53
【问题描述】:

我希望能够在我的 iOS 应用程序中添加/编辑语言。因此,我遵循this question 中的方法,但是无法使其正常工作。

这就是我所做的:

我创建了一个文件夹 myFolder 并将本地化文件夹(en.lproj,...)从我的 XCode 项目拖到该文件夹​​中。然后我将其重命名为myFolder.bundle。 然后我尝试从这样的 URL 加载整个包:

NSURL *url = [NSURL URLWithString:@"http://192.168.0.12/language_plists/Localizable.bundle"];
NSBundle *bundle = [[NSBundle alloc] initWithURL:url];

抛出以下错误:

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“*** -[NSBundle initWithURL:]: 非文件 URL 参数”

【问题讨论】:

    标签: ios objective-c nsbundle


    【解决方案1】:

    明确地,它不能使用非文件 URL,因为 NSBundle 只处理文件 URL。充其量,如果您要下载,则必须下载到缓存或文档位置,并且您必须明确这样做。

    此外,您需要重新提交应用才能获得本地化的许多好处,因为您的 App Store 条目将只包含可以在下载前测试的语言。

    【讨论】:

      【解决方案2】:

      你可以选择这个github

      在您的文档目录中下载您的 json 文件并访问其路径。

      //Download the app from server and save it to Document directory
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *path = [[paths lastObject] stringByAppendingPathComponent:@"strings.json"];
      

      【讨论】:

        猜你喜欢
        • 2011-12-18
        • 1970-01-01
        • 1970-01-01
        • 2018-06-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-13
        • 2011-01-03
        相关资源
        最近更新 更多