MonoDevelop's Images directory does not seen on XCode(IB) - xamarin.ios

In my project files marshalling shown below ,Mono Develop doesn't show Images directory(group) in XCode and they are not seen on xib interfaces,also crashes on runtime. But when I put images under Project's root directory works fine!
Fine! But seeing dozens of images on root directory make things confusing.
Here goes details;
My images built actions are content.
I have tried adding them to Xcode by creating a group named Images then this time all images copied to Mono Develop's root again.
Am I missing something?
Project
--Images
---- FaceOff.Png
---- icons
---------CandyButton32x.png

I think you are experiencing a limitation of the XCode integration with MonoDevelop.
Images only show up in XCode if they are in the root directory of your project. To combat this, there are two ways you can setup your image folders for MonoTouch projects:
Use build action Content, put your images anywhere, but they will only show up in XCode if they are in the root of the project
Use the build action BundleResource and put all your images in the Resources folder, this is the same as putting your images in the root of the project, but you get to package them nicely in a subfolder
I have not experimented with BundleResource and XCode to see if subfolders work via that method or not.
This is from my experience, someone from Xamarin, feel free to chime in.

Further to Jonathan's great answer, I have a nice organised setup for my images using BundleResource and the Resources Folder.
On the filesystem I have all my images in a nice directory structure, for example: img/common/title.png.
I then add all the image files (not directories) into the iOS project Resources folder, using the 'Add Files' option and selecting BundleResource for the files I select.
When given the copy, move or link option, because my files are outside the target directory, I select the 'Add a link to the file' option.
This procedure allows me to:
Happily keep all my images in an organised directory structure on the file system
Have access to them in XCode Interface Builder
Access them as root when in code, such as Image.FromFile("title.png")
Easily update them in the filesystem and have them automatically change in Xamarin Studio

Related

Xamarin ios - Include Files in IPA

I want to include some images within my ipa-File, that need to be placed into the app's documents folder. A similar request was here: Preloading Documents into iOS App. But I'm not familiar with Objective-C. I think I can do it some way in Xamarion.iOS, but the problem in my opinion is the quite large number of files (around 300MB). When I include the files within the AppRessources and copy them on startup, they exist twice on the disk. So there is no real saving...
Any other ideas, how i can include files without being stored twice?
Files that you include in studio goes into your bundle. You can only read them from your application. Modifications and removing is not possible. File that you copy from bundle into your Documents folder, can be modified or removed in Document folder. So there is no way to removing files from a bundle, even if you copy them into Document folder.
You can use on demand resources to download them later intro your app:
https://developer.xamarin.com/guides/ios/tvos/application-fundamentals/resources-data-storage/#On-Demand-Resources

How do I add images to an Xamarin iOS project and make them available in Interface Builder?

I am working in Xamarin to build an iOS iPad app.
I have created a folder called Resources in the project root e.g. ProjectName/Resources. Within here is a subfolder ProjectName/Resources/Images. I have added 2 images into the Images folder.
Then, in Interface Builder (in Xcode), I have added a UIImageView to my xib file and gone to the Image drop down in the attributes inspector. There are no images available to select.
Maybe I have to add them via Xcode instead? If so what are the correct steps and file structures to use?
What is the correct way to work with images and make them available for selection in Interface Builder?
Xamarin Studio only exports images that would live in the top-level app bundle directory when the app gets compiled. This is because Xcode's .xib files only seem to be able to refer to images in the top-level app bundle.
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. In Xamarin Studio, this property is called the Resource ID (may or may not be available depending on which version of Xamarin Studio you are using - it was only recently added). You can also set the LogicalName by editing the *.csproj file 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 install 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 a special directory that gets 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.

Publish Web App files to different locations

I'm start to develop modules for DotNetNuke. I followed different tutorials(most by Chris Hammond) but there is something i don't like, and I'm searching a different way to do so.
He recommends to put a DotNetNuke installation, with IIS and SQL Server, on the developer PC and put your Project into the DesktopModules folder. I don't like it because i want to separate my project from DotNetNuke.
Is there a way to split the build/publish to different location like dll into folder x and all other stuff into folder y?
You could, but I don't really see the point. I see where you're coming from because it seemed awkward to me at first as well, but it really is the most efficient way to develop on the DNN platform. I have mine set up so all of my modules are in the same solution and branched in source from the root DNN folder. We don't keep the DNN core in source so the developer is responsible for that, although that may change at some point to keep versioning consistent.
By keeping your project located where it's installed, you can develop your modules the same way you'd develop any other web app you're building. If you make a change in markup you just have to save the file and refresh your page. If you change something in code just build and refresh.
If you really must keep them separate, you can absolutely do so (really the only benefit of this that I can see is that if you uninstall a module and accidentally click the checkbox to delete files - it happens - you don't have to worry about it). Create your project where you want it, change the Output Path to your DNN bin folder, and create post-build events to copy all of your .js, .ascx, and .css files (plus any others you may need - images, HTML files, XML files, etc.) to appropriate folder(s) in the DesktopModules folder. Just remember that you have to build the project every time you make ANY changes to test them, and you have to write/change your post-build events every time you add a new type of resource, change/add a directory, etc.
Either that or you can build an install package and uninstall/reinstall the module every time you change some padding in your stylesheet ... but I'd stick with keeping the project in the DesktopModules folder.
Sure you can do that.
Set up your solution and module projects anywhere, build the projects and copy the appropriate parts (such as the *.ascx , *.ascx.resx, *.dnn files) back to your website folder -
website/ DesktopModules/Your_module_name
Copy the module dll to the website's bin and you good to go.

How to add a lot of resource files to a monotouch project?

I have a lot of png images into a directory. I've added it to the project as Content/Copy if newer. I can load them from the app without problems.
But, the project needs a lot of time to compile. If i make a little change in the code, the project recompiles all again. It takes a lot of time.
I've tried to add another project, add the files to the new project, but then i can not access to the files from the app.
Is there any solution?
Of course, when i debug the app into the iPad, the uploading+install takes a lot of time. These files will not change ever, so...Is there any method to copy all the content ONE time?
Thanks
I just have discovered a tricks. It seems that monotouch does not remove directories when you upload and install from the MonoDevelop environtment, so:
Add your folders and all the files and mark them as Content
Build your project for iPhone/iPad and Run it from MonoDevelop
Remove your data foldres from your porject
Clean the solution
Make any changes you need in your code, your data reamins in the device!!!
That changes all!!! Before that, when i need to make a minor change in my code, i needed to wait about 15' for building and uploading. Now it's just 1 minute!!!
Place your images in a separate class library
Mark all your files as embedded resources
Add a logical name to each resource (in your project file)
<EmbeddedResource Include="Images\Folder\Filename.ext">
<LogicalName>LogicalNameForImage</LogicalName>
</EmbeddedResource>
4. Load the resource as
UIImage.FromResource(yourAssembly, "LogicalNameForImage");
Embedded resources are loaded on demand, not when the assembly loads.
In A future version of MonoDevelop (my patch didn't make it in time for the upcoming 4.0 release), this won't be an issue any longer.
What currently happens in MonoDevelop 3.x is that when building a project, it will only copy the images that have changed into the app bundle, however, after building, MonoDevelop invokes a script that is installed along with Xcode called iphone-optimize which scans the entire app directory and uses pngcrush to crush all of the images (it also converts all plist files into binary plists). This is the step that causes such slow build times if you have a lot of images.
Just after the 4.0 branch closed for QAing, I wrote a patch that avoids the need for invoking the iphone-optimize script. Instead, what MonoDevelop will do is it will directly invoke pngcrush on only the images that have changed, passing the proper app directory location as the output argument to pngcrush so that we avoid an additional file-copy.
From my own testing, this makes a massive improvement to build times for projects with a lot of image files.
In the meantime, what you could do, is make a backup of the iphone-optimize script (should be located somewhere under /Applications/Xcode.app) and then modify it to not crush image files. Then, once you've done that, go and pre-crush all of your png files in your project.
(Note: when the MonoDevelop with my patch finally ships, it'll also have an option to disable calling pngcrush for developers who have already pre-crushed their images).

MonoTouch Enterprise - Deployment

Our firm has begun building MonoTouch iPad/iPhone apps for enterprise deployment.
How do I take the app and create a *.ipa file for upload to our MDM server?
An .ipa file is basically a glorified .zip file. There are a couple of routes you can go down:
Export the project to xcode and under "Build" click "Build and Archive" - fill in the appropriate details and the project should create the .ipa for you as expected.
If this isn't an option, (which it isnt for us, so this is the method I've used, to great success) you can simply create all the components that go into the .ipa and right-click, "Compress..." in Finder.
The .ipa is made up of the following components:
A folder named "Payload", which contains the compiled (release/iPhone) .app
a 57x57 .png icon file (which is displayed while the app is being downloaded)
a 512x512 .png file of the icon once again - however this has to renamed itunesartwork with no extension
iTunesMetadata.plist - this contains information about the app, such as copyright name, genre, itemname, softwareIconNeedsShine (you can google what information this needs).
The way I package up our .ipa, is I have a folder called "App Packaging" which has all of these components already in, and I simply update the .app file whenever we do an upload, "Compress..." then rename the file to x.ipa (OS X will ask if you want to use this extension, make sure you select ("use .ipa" !).
With the current Monodevelop (2.8.6.5) and Monotouch (5.2.5) it is as easy as right clicking on your project -> options -> iPhone IPA Options -> check Build ad-hoc/enterprise package (IPA) for the desired configuration.
We created a special configuration called Distribution which builds using the Distribution Certificate and In House Distribution Profile.
Luke, I like your answer and have given you the credit. I am adding some more details for my own, and others, notes.
Use SpotLight to find one of your own MonoTouch apps. Search on ".ipa".
Rename it to SomeThing.Zip
Unzip it.
You can then use the structure of the unzipped folder to edit then rezip.
Just another way to get an IPA that made it easy for me, drag your .app file onto your itunes library and sync your device. ITunes then creates a copy of the app as an .ipa file in the user/music/itunes/itunes media/mobile applications. This can then be distributed much easier than the .app file.

Resources