skip to Main Content

txt file under App.app/here.text ?
Currently I found NSSearchPathForDirectoriesInDomains

 NSArray* dirs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] error:NULL];

but it places under documents. Can i save it under under Appname.app/here

https://www.alphansotech.com/wp-content/uploads/2015/11/iosDirectory.png

in what level i can list read files?
/private/var/containers/Bundle/Application/EF4585FC-743D-409D-83A9-B8A298D44C74/App.app

NSString * path = [[NSBundle mainBundle] resourcePath];
  [path stringByDeletingLastPathComponent];
  NSArray* dirs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[path stringByDeletingLastPathComponent] error:NULL];
  NSLog(@"sss..%@",path );

  NSLog(@"sss..%@",[path stringByDeletingLastPathComponent]);

  NSString *stringToWrite = @"1n2n3n4";
  NSString *filePath = [path stringByAppendingPathComponent:@"main.jsbundle"];

  [stringToWrite writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
  
  [dirs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
      NSLog(@"sss...%@", obj);
  }];

2

Answers


  1. Find the resources path :

    NSString * path = [[NSBundle mainBundle] resourcePath];
    path            = [path stringByAddingPathComponent:@"myFileName.myExtension"];
    

    To simply get the file you can use :

    NSString * path = [[NSBundle mainBundle] pathForResource:@"myFileName" ofType:@"myExtension"];
    

    Note however that it’s not recommended to save files within the application bundle especially because of code signature.

    Login or Signup to reply.
  2. Long story short:

    No, you can’t. For obvious reasons it’s impossible to write into the application bundle.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search