Cordova - ios on-demand resources - ios

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

Related

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.

Xcode build process for linking & embedding framework to app in workspace

I've separated some functionality in an app I'm working on into a self-contained framework. Both the framework and the app are included in a workspace. How do I include this framework in my build in a machine-agnostic manner?
What I've been doing is adding the framework to the embedded binaries of my client app, as suggested on a number of posts here on SO. This works nicely until you start work on another machine, at which point the randomly generated 'DerivedData' directory the framework resides in can't be found, and you have to re-create the link. This will become a really tiresome process.
I was considering using CocoaPods for this purpose, but unless I'm reading it wrong, you can't just reference local projects with a podspec; the project needs to reside on a known source / repo.
So basically I'd like to know how people here have forged a multi-project build process that isn't linked to the directory structure of a particular development machine.
So I've found a solution that works. The issue was that my client app project referred to the framework file relative to the project itself.
The minimal steps I took to refer to (and embed) my framework were significantly fewer than some of the solutions I've seen.
In my client app's target (on the General tab), add the framework to the 'Embedded Libraries' section. This will also add a reference to the framework to the Project navigator.
Select the reference added to the Project navigator in step 1, and change it's location to be 'Relative to Built Products'. Optionally move the framework to the 'Frameworks' folder of the client app's project, where the rest of the frameworks live.
This second step ensures the build looks for the framework relative to the build products, rather than relative to something else, whose location may vary between machines / copies of the source.
Actually, you can indeed have private Pods. Most tutorials on how to do this usually keep these private Pods within private repos on GitHub, but you can also host them on another Git (non-GitHub) server.
As for the DerivedData directory issue, it sounds like you are including the framework via a build setting (i.e. something like "-framework ~/Library/Developer/Xcode/DerivedData/MyFramework-$$##$###$#/MyFramework.framework").
You should be able to simply click on the "Build Phases" section of your app's target settings and then the "add" (or "+") button and you'll see your (built via the same workspace) framework or library in that list that you can add. More information can be seen in this Apple documentation.

Adding a dependency to a repository with Xcode 6.1

I'm new to programming on iOS and I'm running into a roadblock with adding dependencies to my repository.
When I drag and drop a framework into the project directory and reference everything, I can build the project no problem. The issue is when I commit my project to the repository, the framework files do not get copied over. I can see that they are located in their original directory in some other location. Xcode merely references these files instead of adding them to the project directory.
So my question is, how do you add a framework or dependency to a project directory and commit it alongside your project to your repository?
Note I'm using SVN, however a Version Management System agnostic solution works for me.
In your case, or most cases people just download the framework and add it from there directly though it works in their machines, but will not work in other machine, because of absolute path added to the Header Search Paths settings in Build Settings.
In case of Third Party frameworks are as follows, will work for any case. Add the relative path rather than absolute path, though you don't set it, it is automatically added while you add a framework. So what are the steps? See below
Step 1
Create a folder named framework inside your svn/git folder of your project, and put all the frameworks inside the folder..
Step 2
Now add the framework, from the framework folder as you were doing earlier.
Step 3
Check your Header Search Paths in Build Settings. You will see entry for your framework header path. It should look something like
/Users/username/ProjectFolder/Project/frameworks/myframework/framework.h
Change the above entry by
$(SRCROOT)/frameworks/myframework/framework.h
Doing the above will automatically change this /Users/username/ProjectFolder/Project/ part of your path according to any system you clone the project. And it will work automatically.
Note - Before performing the steps, remove all old Header entries, which has absolute path.
Hope it helps.
Cheers.

Resources in custom iOS frameworks

I have made an empty single-view application in Xcode 6 (FWTest) and added a Cocoa Touch Framework (FWTestKit) as a target and asked it to embed in FWTest. Then I add an image (photo.png) to the framework, that I expect to be in Frameworks/FWTestKit.framework/Versions/A/Resources/photo.png when I build & archive my app. However, I find it in Frameworks/FWTestKit.framework/photo.png
How can I make it at least be in a Resources folder? Preferably a versioned folder so I can ship different versions of my framework?
When I add this framework to another app, do I need to do anything special to make sure the resources are bundled along with it, so that when I reference a resource from within my framework I can be sure it'll be available also when used in another app?
Cheers
Nik
You should add your photo.png into separate folder (let's call it "gica" ). Then drag folder into project, check Copy items if needed and create folder reference. Then (important) in build phases, drag photo.png again in Copy Bundle Resources, keeping Copy items if needed and create folder references. After you compile you should have now desired folder structure [It is keeping gica/photo.png].
I think you need to revise the architecture about versioning. Anyway if you still need to place the image inside the folder. Try creating a run script.
In your build phases instead of adding your images to copy bundle resource phase. You can create a shell script to copy your images to desired folder. Please note build phases are run in the order they placed. My point is you can customise xCode Build process through your own shell scripts.

Xamarin studio folder structure issue in iOS project

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.

Resources