Xamarin studio folder structure issue in iOS project - ios

I am having trouble with xamarin folders. Currently I'm writing xamarin iOS project. In Xcode I used directories for grouping images, there could be several levels of nested folders, but when I was building project for device or iOS simulator, these resources where simply being copied to main bundle, without any folder structure. I can't reach the same behaviour in xamarin studio. Whenever I create folders in my project and put pictures or other resources in them, this folder structure is recreated on the actual device, and thus, I struggle against different paths, when loading images. How can I make xamarin studio simply copy the files in the folders to main bundle, instead of recreating folder structure?
Thanks for help.

My first suggestion is to change the BuildAction property of your images to BundleResource.
Once you do that, there are multiple ways of achieving your goal:
The first option is to specify a LogicalName to be whatever you want the name to be inside of the compiled app bundle. Currently there's no way to set the Resource ID (UI name for the LogicalName property) for anything other than EmbeddedResource files (I'll work on fixing that momentarily), but you can edit the *.csproj like so:
<BundleResource Include="Icons\icon.png">
<LogicalName>icon.png</LogicalName>
</BundleResource>
Normally, that Icons\icon.png file would be copied into the iOS app bundle as Icons/icon.png, however, the LogicalName property overrides the relative path name. In this case it would be copied over as simply icon.png.
As another example, you can also do this:
<BundleResource Include="Icons\iOS\icon.png">
<LogicalName>AppIcon.png</LogicalName>
</BundleResource>
This will copy the Icons\iOS\icon.png file into the root of the iOS app bundle and also rename it to AppIcon.png.
A second option is to simply move your image file(s) into the Resources folder. The Resources folder is special directory that get stripped out of the default path names when copied over to the iOS app bundle. In other words, Resources\icon.png would be copied over into the root of the iOS app bundle as icon.png rather than Resources\icon.png as is the case with normal project directories.
A third option is to simply register other "Resource" directories of your own (and they can exist within other directories, including the default Resources directory).
For example, you could have the structure in your project:
Resources/
Icons/
icon.png
icon#2x.png
And in your *.csproj file, edit the following tag:
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
and replace it with:
<IPhoneResourcePrefix>Resources;Resources\Icons</IPhoneResourcePrefix>
This will ensure that the icon.png and icon#2x.png files are installed in the root of the iOS app bundle.

Xamarin has two ways to setup files you want present in the iOS bundle:
Put them in any folder, and mark the "Build Action" as "Content". Whatever directory structure you have in your project will be present in the main bundle.
Put them in the "Resources" folder, with a "Build Action" as "BundleResource", this does the same as #1, but removes the "Resources" folder from the path present in the bundle. This is a nice place to put all images you want in the root of your bundle but would clutter up your project.

Related

Cordova - ios on-demand resources

Trying to use ios on-demand resources in a cordova project and need to add a folder to the ios project that I can mark as belonging to a target then add an on-demand resource tag.
I can do this in the generated xcode project by using 'add files' and adding the folder. Then in the File Inspector, check the required target then in the 'On Demand Resource Tags' text box adding my tag e.g. 'MY_TAG'.
Obviously it isn't feasible to generate the project by doing a cordova build then manually adding and tagging the folder but I can't figure out how to add the folder and tag it using various plugins, hooks etc. I tried moving the folder into the root of the ios project using a custom hook (after_prepare) and the folder is in the resulting xcode project but I still have to manually add it and tag it.
It seems that cordova is not happy about me adding folders at the same level as the www directory. I need a directory structure :
myproject
www
MyOnDemandResourcesFolder
If I do add the folder under the www folder (as a sub folder) the option to associate it with a target and provide an on-demand resource tag is not available in the file inspector of the xcode project. In fact, that goes for any sub folder that you create in the xcode project - it cannot be marked as an On-Demand Resource.
Any help would be much appreciated. It doesn't seem that many people are using on-demand resources apart from simple use cases of individual files.
On Demand Resources are not supported at the moment by Cordova.
Recently there was a PR submitted to cordova-node-xcode repository, that would be the step 1 for adding support, but a lot of work still pending.
https://github.com/apache/cordova-node-xcode/pull/87

Why does xcode ignore a symbolically linked app icon in the asset catalog source?

I have the following structure in my iOS Project source folder:
resources:
ios/ mac/
resources/ios:
Images.xcassets/ Info.plist LaunchScreen.storyboard
resources/ios/Images.xcassets:
Contents.json LaunchImage.launchimage/ AppIcon.appiconset/
Everything works fine. If I replace the directory AppIcon.appiconset with a symbolic link to a directory with the exact same content, then when I open Images.xcassets in Xcode it shows only LaunchImage and I get a build error that no icon named AppIcon could be found.
This appears to be an Xcode issue. Is it a bug or by design? If the latter, is there a way around it? I really don't want to have multiple copies of these images in the sources for multiple apps.
I can't use hard links because the code is in a git repo so anything other than the original repo would end up with multiple copies on checkout.
If Xcode refuses to copy resources from symbolic, there is probably no way to do this. However, if you want to strictly keep the icons synchronized, you can use a custom shell script phase in your project, which copies the image assets from the macOS folder to the iOS folder.
Just another, even simpler solution could separation the images into special and common icons, and sharing the complete 'common' asset catalog in both targets.
You can create AppIcon.appiconset as a regular directory and put symlinks inside to each of the shared Contents.json and png files. This requires more symlinks but does centralize the image storage.

File With Same Name From different folder in ios

I am using "xcode 6.1.1" and "cocos2dx-3.2".
I need to access same file name from different folder.
In Resource i have 3 folder "A,B and C" and all this folder contain image with same name "1.png".
If i need to access 1.png of folder "A" ,How i can do this in cocos2dx please help?
following code is working fine in Android but not working in iOS
helpImage->setTexture("A/1.png");
Thanks.
Didn't used cocos for some time now, but it is pretty easy to do.
Do this:
Prepare directory with your game data. Here lets call it "GameData". Pick name you like.
Drag and drop that directory to the xcode, probably best location is Supporting files. Dialog will show up. Select "Create folder references", deselect copy if needed.
And basically you are done. During build process all resources will be copied to bundle with paths as is in that directory "GameData". So you can have files with same name without problems.

Can you put iOS icon & launch images in a different directory to the project root?

I have a cross-platform codebase, structured a bit like this:
/Projects
/App1
/src
/iOS
/App2
/src
/iOS
/App3
/src
/iOS
Win32.sln
iOS.xcodeproj
XCode wants to put icons and launch images under /Projects, as siblings of the .xcodeproj file, but that's messy - these are project/target-specific files. I would rather have each app keep app-specific iOS files under e.g. App2/iOS.
I've seen some topics on this kind of issue, talking about how xcode wants to copy images to the root, but no definitive answer if you can or can't do it.
edit: the same goes for my app .plist file, can I relocate this?
Currently the project I'm working on has the load screen icon in root folder and the appIcons under Resources/Icons so there's definitely a way of copying them there.
Try copying the icons to the desired folder manually, then add them to your project and uncheck "Copy items into destination group folder".
Also, I would advise you to create folders using finder, then adding them into Xcode to use them as Groups instead of creating them in Xcode.
I have found these are all possible
The plist file is easiest, there is a build setting info.plist which must be updated accordingly.
For the icon and launch images, remove references from your project and then move the files on disc to some folder that makes sense for your codebase. Then add these items to the project (right-click, "add files to "). Finally, use a copy files build phase to copy them to the Resource folder, or possibly add them to a Copy Resource Bundle build phase.
When I did this, the files were copied into the App-Bundle itself, the iPad displayed them as expected, and XCode displayed the images in the Project Summary screen.

XCode: Where to put image resources

I'm trying to add some App Icons and Launch Images for my App. My code-files are organized in groups inside Xcode and the same in the File System. I tried to drag a folder named Resources with my PNG images into my App and afterwards trying to add them as the App Icons and Launch Images for my App, but Xcode then gave me an warning and copied the file to the root of my project -- both in Xcode and File System.
Is it normal, that the Image are put in the root (in same level as the xcodeproj file)?
Yes it's OK. What can I suggest you is not to worry about filesystem and organize your files/directories within the project.
It's same as with iTunes: you don't care what and where your files are, but you have a nice interface to work with them.

Resources