Ackman
Ackman

Reputation: 1592

locating a text file Objective C

enter image description here

I am trying to get path of legal.txt in my project. However, whatever I do. I am getting a null path back. it is in the Policies directory. How do I get it's path as a string. I need to send that path to a webview controller. Can someone help.

-(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"];

Will this work. I need a way to direct user to a webview once he clicks on the link and privacy text opens up.

Upvotes: 1

Views: 72

Answers (1)

Ashok R
Ashok R

Reputation: 20766

From apple doc:

pathForResource:ofType:inDirectory:

Returns the full pathname for the resource file identified by the specified name and extension and residing in a given bundle directory.

NSString *filePath = [NSBundle pathForResource:@"file" ofType:@"txt" inDirectory:[[NSBundle mainBundle] bundlePath]];
    NSLog(@"File Path:  %@", filePath);

Output:

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

Upvotes: 1

Related Questions