0
我想根據用戶當前使用的語言獲取合法文檔。根據所需語言檢索文件
我的代碼,這是一個:
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];
我的西班牙語和英語有一個版本的文檔,我怎麼能告訴路徑在西班牙使用的版本?
如果文件位於應用程序的資源包中,請使用'[NSBundle pathForResource:ofType:]'獲取路徑。它會自動給你正確的版本。 – rmaddy
其實你是對的! [NSBundle mainBundle] pathForResource:@「privacy_policy」ofType:@「html」]給了我正確的版本:)非常感謝! – Alejandra
你能否提出正式答案,以便我可以將其標記爲正確? ;) – Alejandra