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
Find the resources path :
To simply get the file you can use :
Note however that it’s not recommended to save files within the application bundle especially because of code signature.
Long story short:
No, you can’t. For obvious reasons it’s impossible to write into the application bundle.