ios - 定位一个文本文件 Objective C

标签 ios objective-c xcode

enter image description here

我正在尝试在我的项目中获取 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/

相关文章:

ios - 使用 Pod 依赖项中的 IB_DESIGNABLE 实时渲染自定义组件

objective-c - 灵活空间与固定空格键按钮项目

html - 如何检索图像 url 的标题

javascript - 使用 Cloud Code javascript 和 iOS Parse SDK 编辑用户

ios - 多层 scn 文件需要时间来渲染 arkit

ios - 在应用商店更新应用版本时更改关键字或添加新关键字

ios - 如何使用 CoreData 构建复杂查询?

ios - 我只想统计和分析我的SDK(框架)中的崩溃,但不发生在集成我的SDK的APP中

ios - 使一个属性强,非原子的objective-c

iphone - 在 XCODE 4.2 中崩溃时线程不会停在实际的代码行