Ackman Ackman - 19 days ago 5
iOS Question

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.

Answer

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
Comments