我正在尝试在我的项目中获取 legal.txt 的路径。然而,无论我做什么。我得到一条空路径。它位于策略目录中。我如何将它的路径作为字符串。我需要将该路径发送到 webview Controller 。有人可以帮忙吗。
-(void)linkPressedOnTextView:(PPLinksTextView *)tv url:(NSURL *)url{
if ([url.host isEqualToString:@"sign_up"]) {
GetStartedController *getStartedVC = [[GetStartedController alloc] init];
[self.navigationController pushViewController:getStartedVC animated:YES];
}
else if([url.host isEqualToString:@"consentMedicalSevices"]){
PPNavigationViewController *vc = [[PPNavigationViewController alloc]init];
[vc openPolicies:@"Policies/privacy.txt"];
这行得通吗?我需要一种方法,在用户单击链接并打开隐私文本后将其定向到 WebView 。
最佳答案
来自苹果文档:
pathForResource:ofType:inDirectory:
返回由指定名称和扩展名标识并驻留在给定包目录中的资源文件的完整路径名。
NSString *filePath = [NSBundle pathForResource:@"file" ofType:@"txt" inDirectory:[[NSBundle mainBundle] bundlePath]];
NSLog(@"File Path: %@", filePath);
输出:
File Path: /Users/Ashok/Library/Developer/CoreSimulator/Devices/F629F99F-C745-46EB-8A11-01BC9FF1E592/data/Containers/Bundle/Application/EB4EA25F-65E6-4CA8-B8C2-C7C0C64C6C0F/Sample.app/file.txt
关于ios - 定位一个文本文件 Objective C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40580517/