2012-01-07 17 views

risposta

7

Dopo Mike K pointed me in the right direction, sono stato in grado di recuperare il percorso di un file in un bundle dell'applicazione con il seguente codice

// Get a reference to the main bundle 
CFBundleRef mainBundle = CFBundleGetMainBundle(); 

// Get a reference to the file's URL 
CFURLRef imageURL = CFBundleCopyResourceURL(mainBundle, CFSTR("MyImage"), CFSTR("bmp"), NULL); 

// Convert the URL reference into a string reference 
CFStringRef imagePath = CFURLCopyFileSystemPath(imageURL, kCFURLPOSIXPathStyle); 

// Get the system encoding method 
CFStringEncoding encodingMethod = CFStringGetSystemEncoding(); 

// Convert the string reference into a C string 
const char *path = CFStringGetCStringPtr(imagePath, encodingMethod); 

fprintf(stderr, "File is located at %s\n", path); 

Questo sembra essere un po 'più lungo di quello che deve essere, ma almeno funziona!

Problemi correlati