IOS: NSString file path for NSURL

I have it:

NSURL *url = [NSURL fileURLWithPath:@"/Users/myusername/Library/Application Support/iPhone Simulator/4.2/Applications/5ABF1395-4A80-46C0-BD4A-419ED98CE367/Documents/DBV/v.m4v"]; 

Then I launch movieViewController, but it always crashes .. This code does not work on the iPhone simulator or on the device ... How to fix it?

EDIT: Before writing the file path manually, I used the correct way to select the folder.

 [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] 

Then I got this log:

file: // local / Users / MyUserName / Library / Application% 20Support / iPhone% 20Simulat or / 4.2 / Applications / 5ABF1395-4A80-46C0-BD4A-419ED98CE367 / Documents / DBV / v.m4v

Then I thought it was due to spaces in the folder name, so I decided to write the full path manually for debugging (replacing each% 20 with a space)

EDIT 2: Note: I'm trying to access a dynamically created file in the Documents folder, not the file from my package.

+4
source share
1 answer

For files in documents, you should get the path from NSSearchPathForDirectoriesInDomains.

 //get list of document directories in sandbox NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //get one and only document directory from that list NSString *documentDirectory = [documentDirectories objectAtIndex: 0]; 

Then you add the file name to it.

+2
source

All Articles