2012-01-07 34 views

Trả lời

7

Sau Mike K pointed me in the right direction, tôi đã có thể lấy đường dẫn đến một tập tin trong một gói ứng dụng với đoạn mã sau.

// 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); 

Điều này có vẻ dài hơn một chút so với mức cần thiết, nhưng ít nhất nó hoạt động!

Các vấn đề liên quan