简体   繁体   中英

iOS - Access App created Files and Folders

I am currently developing a Text Editor for coding for Android, and I am interested in creating an iPhone and iPad Version as well. I heard that iOS does not have a File Management system, and you cannot normally access files through a PC. Would it be possible for my app to create a folder and file (say, a Java or Swift file), and then display the names of those files in the main screen and allow the app to open that file that it created?

Tl;dr: Can I make files, and access them in the app?

Android Code for reference: https://github.com/MJonesDev/Pocket-Editor-Android

Yes you can.

To create java file:

NSError *error;
NSString *stringToWrite = @"1\n2\n3\n4";
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"myfile.java"];
[stringToWrite writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error];

To read java file:

NSString *str = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
NSLog(@"%@", str);

Source from here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM