contentsOfDirectoryAtPath: is not listing customized file extension - ios

In my project (iOS), I have added some files with file extension (customized) ".dncx", for example. The customized file are visible in xcode project (Copt items into destination's.... checkbox is selected).
After using the following code, I'm printing the list of all the files.
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resourcePath error:nil];
The files with .png, .wav, .plist, .jpg, extensions, all are getting printed, which are present in the same path along with customized files.
But the files with the customized extension like, ".dncx" are not at all shown.
Could you please guide me, making the customized file extensions listed.

Those files are obviously not in the directory that you think they are. I've put some dncx file in my bundle (and in Documents) without incident.
Typical problems include:
If you're looking for these files in your bundle, the question is whether they were included in the bundle at all. If you open your target settings, choose "Build Phases" tab, expand "Copy Bundle Resources" and see if your dcnx files are listed there; if not, add them there by clicking the "+" button immediately at the end of the list of "Copy Bundle Resources";
Again, if you're looking for these files in your bundle, make sure they weren't accidentally put in another folder within the bundle;
If you want to externally confirm the contents of your bundle or Documents folder, I would run the app on the simulator and then navigate to the folder in question (e.g. "~/Library/Application Support/iPhone Simulator/ ..." and see if they're there ... you might want to go to Terminal and type in chflags nohidden ~/Library if your Library folder is hidden in Finder (which it is by default)). To see inside the bundle, once you've navigated to the app itself, control-click on that (or right-click) and choose "Show Package Contents"

Related

How to bundle text files into an xcode application to be readable at runtime?

I have added a few .js files to an xcode project:
I am trying to load those .js files at runtime but they apparently are not available. This was seen by looking at the physical disk location of the simulator sandbox that we can find at: Bundle.main.bundlePath whose value is:
/Users/steve/Library/Developer/CoreSimulator/Devices/CC7AE0CD-4EEE-412F-8E01-E5F55F73887E/data/Containers/Bundle/Application/ECB90596-FF9F-4E40-B500-0D55DDFC0E2E/hybrid.app
Under that directory there are a few gyb files, the Info.plist, some code signature files, the storyboard .. and one .js file. That one file was added to the project earlier and I am not certain using what mechanism.
I'd be happy to see all of the .js files there - but maybe that's too much to ask? Is there a different way to get those other .js files - like reading from some Resources bundle?
Just drag any file into the Project navigator (project files structure browser) pane on the left. This file will be accessible via
let jsonFilePath = Bundle.main.path(forResource: "fileName", ofType: "js")
This is an exercise in more deeply understanding xcode project structures and Build phases. Go to the Project Properties then select the Build Phases tab. Select the Copy Bundle Resources and add the files - javascript in my case - in that section:
The files now do show up in the root directory of the simulator output sandbox directory.

how to add subfolders inside in-app-purchase iOS package?

For some reason, any files I put inside my IAP package (hosted on Apple) under a subfolder, gets eventually downloaded directly under the iOS temporary Contents folder.
I've created a simple IAP package using xcode template which initially had the following directory structure:
projectname/projectname/ContentInfo.plist
I then placed some extra files in the package under a subdir like so:
projectname/projectname/dir1/file1.txt
Then I go to xcode->add files->select dir1 and check "create groups" for added folders. All is ok so far. When I look at xcode, I see a group called "dir1", its location relative to group is "dir1" and full path is correctly set to xxxx/dir1.
I also see "file1.txt" with its location relative to group is "file1.txt" and full path correctly set to xxxx/dir1/file1.txt.
I package everything and upload to Apple.
I run a test to download the package and set a breakpoint after the content has been downloaded. I run a file scan function to list all the files. This is what I see under the xxx.zip/Contents folder that iOS creates:
ContentInfo.plist
file1.txt
dir1 is missing and file1.txt is directly under Contents!
I decided then to reopen the package xcode created (xcarchive) using "Show Package Contents" and indeed I see file1 under Contents/ and not under Contents/dir1...
How do I get the package to retain the directory structure when it's built?
Thanks...
Ah, after several hours, found the answer:
I needed to remove the file and group references and re-create them by "adding files" to the project, selecting dir1 folder with "create folder references", not "create groups" option.
After re-packaging this way, the folders were retained inside the package!

Error: no such file or directory

My project was working perfectly fine. I then moved some files around from the project's root directory to some subfolders. Now, when I try to run the app, I receive this error message:
<unknown>:0: error: no such file or directory:
'/Users/anapaix/Desktop/currencyExchange/CommentsController.swift'
And I receive this same error for all 20 of the files that I moved around.
Additionally, the files now show up in red like this in my project:
When I double click the file, an empty Swift file shows up, like there is nothing inside. I have a feeling there should be some easy fix to this, in order for Xcode to recognize these files, but just have no idea what it would be.
You moved the files. Xcode doesn't know that. You need to tell Xcode where the files are. (Note: the other answers work too, but if you don't want to remove them and add them again, you can use this method)
Select your red file(s), open the File Inspector (Option+Command+1), and click the folder (circled in red in the below screenshot). Then find your file(s) and click Choose. The filenames should go back to being black.
If multiple red files are in the same folder, you can select multiple files in the Project Navigator (left column, Command+1), click the folder icon in the File Inspector (still the one circled in red, but the text will be different; it might say "multiple selected" or something) and click the folder containing the files. Xcode should automatically detect all of them, provided the filenames haven't changed.
Go Xcode->File->Add Files... and add missing files to the project.
when you move any file in finder from the projewct workspace then xcode doesn't recognize the new path automatically, and xcode consider it as deleted. So,Please remove this files that are in red colour in your explorer.
Then again drag the files from the finder in to your project.
This way your project found the new file path of files for the compling.

texture atlas file not found in main bundle in resources folder

I'm having a problem where a file in my Resource directory is not being recognized as being in the Main Bundle.
I am creating a texture atlas using a pvr file format using texturePacker. The output of texturePacker produces two files xxx_iPhone-hd.pvr.ccz and xxx_iPhone-hd.plist. These two files are being stored in my Resource directory of my cocos2d project. Once the files are stored in the Resource folder, I go to the Resource folder and right click to 'Add Files to "myProject"' (with the copy items into destination box unchecked).
When my cocos2d project runs and tries to load this file, the absolute path is unknown to the Main Bundle. Specifically, my code executes the following line of code:
backgroundBgNode = [CCSpriteBatchNode batchNodeWithFile:#"StoreMenuBackground_iPhone.pvr.ccz"];
The cocos2d code knows that the device has a retina display and modifies the filename to create a relPath of "StoreMenuBackground_iPhone-hd.pvr.ccz". It then tries to execute the following:
NSString *imageDirectory = [relPath stringByDeletingLastPathComponent];
fullpath = [[NSBundle mainBundle] pathForResource:file
ofType:nil
inDirectory:imageDirectory];
This results in full path being nil. I previously created a different xxx_iPhone5-hd.pvr.ccz file with the above procedure, and the above code successfully returns the fullpath. I have very carefully checked and rechecked the spelling and don't see any problems. I have also tried removing and re-adding the files under "Copy Bundle Resources" of the "Build Phases" for the project. Is there something I can do to force the mainBundle to find this file?
You should verify that the file actually is in the bundle.
You can do that by right-clicking the built bundle (in your project's DerivedData folder) and select "Show Package Contents". If you don't know how to locate the built product, do an Archive Build targeting a device (archive builds are unavailable for simulators). In the Organizer window that opens right-click the app and select "Show in Finder", that brings you to the xcarchive. Run "show package contents" on the xcarchive and navigate to /Products/Applications and perform another "show package contents" on the bundle.
If the file is there but in a subfolder (not in the root of the bundle) then you have created a folder reference inside Xcode, denoted by the blue folder icon. Remove that and re-add, this time uncheck the checkbox "create folder references for..." in the Add File dialog.
If the file IS there, copy its filename and paste it back into code. Case differences can sometimes be elusive and hard to notice, even if you double-check.
desperate measures then. Copy in finder the files on the side ... ie not in the project directory structure. Rename the newly copied files to something dead simple , like a-hd.pvr.ccz and a.plist (hoping you dont already have an a-hd.pvr.ccz in your project ;) ).
Edit a-hd.plist to make certain that the last section points to the right file name. Drag them from Finder onto the xCode resources folder, selecting to copy the files. Make certain to change the name in your code. Delete the previous files from the project. Deep clean the project. Delete the app from the device. Run. If that worked, redo the same steps, reverting the name to your favourite name.

How to add existing .momd to a project in Xcode 4?

I have a project that includes a subproject. The subproject has a Core Data model and generates a .momd "bundle." I need that .momd bundle to be included in the main projects app bundle that is generated when the project is built. The .momd file is generated, and is in the build directory, but I cannot see how to get it included in the final app bundle.
I can add the .momd as a file in the "Copy Bundle Resources" (by adding a reference to it to the main project in my Supporting Files group) but since the .momd is not a Finder level bundle, it adds it in as a directory and the .momd contents get copied into the app bundle, but not the .momd folder itself, so the system cannot find it when the app runs.
Of course, after trying all sorts of things all afternoon, and searching with Google and Bing and inside SO, and not coming up with anything, soon after I post the question, I figure it out.
When adding the .momd file to the main app project (I added it to "Supporting Files" group), check "Create folder references for any added folders" and NOT "create groups for any added folders" (And also do not check "Copy items into destination group's folder" if the .momd is being generated in a sub-project)
Doing it that way makes the .momd gets copied into the app bundle...

Resources