Using iPhone resources in a C ++ file

I was wondering how you open a file in an application bundle from a C ++ file.

those. I have a "manifest.xml" file that starts by copying to the application bundle. I need a path from C ++ to load this file. I think this will be due to setting the path somewhere in the Obj-C code so that the file is in the working directory.

+4
source share
2 answers

You must use either CoreFoundation (C) or Foundation (ObjC). Access to any objects in the application bundle ("Basic Kit") is carried out using the CFBundle / NSBundle .

In CoreFoundation you do (NULL-check omitted):

 CFURLRef manifest_url = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("manifest"), CFSTR("xml"), NULL); char manifest_path[1024]; CFURLGetFileSystemRepresentation(manifest_url, true, manifest_path, sizeof(manifest_path)); CFRelease(manifest_url); FILE* f = fopen(manifest_path, "r"); // etc. 

At foundation you do

 NSString* manifest_string = [[NSBundle mainBundle] pathForResource:@"manifest" ofType:@"xml"]; const char* manifest_path = [manifest_string fileSystemRepresentation]; FILE* f = fopen(manifest_path, "r"); // etc. 
+6
source

The OS X app is at the heart of the Unix app.

How can an application find its parent directory and open a file in Linux? You would do the same in C ++ on OS X.

Now, if you are ready to make a couple of Cocoa or CoreFoundation calls, you can make your life a lot easier, but if your requirement is that only C ++ calls can be used, then the task will not be different than in any other Unix-sytle system .

+2
source

Source: https://habr.com/ru/post/1300586/


All Articles