我想根据用户当前使用的语言获取法律文档。
我的代码就是这个:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths objectAtIndex:0];
if (sender == privacyPolicyButton) {
ppPath = [libraryDirectory stringByAppendingPathComponent:@"privacy_policy.html"];
} else if (sender == termsOfServiceButton) {
ppPath = [libraryDirectory stringByAppendingPathComponent:@"terms.html"];
} else if (sender == endUserButton) {
ppPath = [libraryDirectory stringByAppendingPathComponent:@"eula.html"];
}
NSData *ppData = nil;
policyView.scrollView.scrollEnabled = NO;
[loadingIndicator startAnimating];
policyView.hidden = closePolicyButton.hidden = NO;
privacyPolicyButton.hidden = termsOfServiceButton.hidden = endUserButton.hidden = YES;
ppData = [NSData dataWithContentsOfFile:ppPath];
NSLog(@"%@", ppPath);
[policyView loadData:ppData MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:nil];
我有西班牙语和英语的每个文档的版本,我如何告诉使用西班牙语版本的路径?
答案 0 :(得分:1)
NSBundle
课程为您完成此任务。假设您的HTML文件是应用程序资源包的一部分,您可以执行以下操作:
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"terms" ofType:@"html"];
这将根据用户的区域设置/语言设置为您提供正确的terms.html文件的路径。