Loading external .bundles on iPhone - iphone

I would like to add resource files to a .bundle and push them to my application and it seems to work fine in the simulator but fails to build when I change to the device.
/Users/sosborn/Projects/MyPro/build/Debug-iphoneos/FooBar.bundle:
object file format invalid or
unsuitable
I don't want to load any code or anything, just plain text and jpegs and it would be nice to be able to package them as dependencies.

iPhones and iPod touchs do not have support for loading external modules (neither bundles nor dylibs). If you need to share object code between projects, you can use static libraries

Instead of trying to load it like an NSBundle, just reference the resources therein by path.
You could pretty easily create your own class that did something similar to the non-code stuff in NSBundle to help out, as there really isn't much logic in there.

I found a better solution to my problem. It actually doesn't require the use of bundles at all. I just created an aggregate target instead of a bundle target. Then I added a copy step and a script step. The copy step contains all of the resources I had in the bundle target and the script step actually zips up the files. Then when I download the content into my application I can just unzip it and use it just as if it were a bundle since I'm just storing resource dependencies.
Thanks for your help.

Related

Packaging multiple applications together

I have a project that requires me to add another application to the package.
This application will act as a proxy, such as the one described in the BBMSDKDemoProxy sample project. I'd like the user to be able to download one package, both applications are installed, and my main application is launched via the proxy.
The problem is that I don't know exactly what steps to follow to achieve this. The project will be distributed via the app world, but I'd like to know how to do this via a website too.
I've found a link stating that you simply add both applications in a single .zip and upload that to the app world, but I want to be sure about this.
Any help would be greatly appreciated, thanks.
For AppWorld: just include the extra cod file in the file set to be uploaded. If you are uploading a zip then include the extra cod in the zip content.
For Desktop/BES: you can include the cod file along the other files and manually edit the .alx to add an entry for the new module. I'd not recommend doing this unless you have a good understanding of the alx format and the different elements in the descriptor.
For OTA downloads: You'd place the new cod file with the other cod files (if it contained sibling cods you'd publish the siblings instead). Then you can manually edit the .jad file to add the new module(s).
Of these 3 options, only the first one is safe. Manually editing the alx or jad is tricky, and is very easy to make mistakes. If you need files for desktop-BES or OTA installs I'd add a new library project as #preetam has suggested in the comments.

Three20/Three20.h file not found for Archive

I'm trying to update an app that already have the Three20 library. Now i'm using xcode 4.5 and everytime i try to make an Archive i recive this error:
Three20/Three20.h file not found
At the beginning i wasn't able to make any kind of build,but after the adding of $(BUILT_PRODUCTS_DIR)/../three20 and $(BUILT_PRODUCTS_DIR)/../../three20 in the Header Search Path of the build and the target settings i can make a Build in my Device. Anyway if i try to made an Archive to publish my app, the same errors returns. What i can do? I have already reinstall the last version of Three20.... I have to try this solution that i found on internet:
Go to Xcode4 Preferences (Cmd + ,) > Locations > Build Location > and select “Place build products in locations specified by targets”
In xcode 4.5 i can't approach this solution...Maybe Build Location menù is changed, i can't find the option “Place build products in locations specified by targets” .... Someone knows where i can found this setting?
At least there's someone how have made successfully an Archive on Xcode4.5 and Three20?
I also support switching away from three20, but sometimes it's not that simple.
To resolve your issues, you can try to use CocoaPods. it's a library dependencies tool that let's you add any library you need. someone added a pod for three20 few weeks ago.
That should let you build your project using the standard xcode archive process.
If you don't feel like using cocoapods, you can also build that app using the "Build for..." -> "Archiving". you can find it in the same "Product" menu. it will generate a .app file that you can submit using the Application Loader app.
you can find the .app file by secondary clicking on the target name under the "Products" folder in your project sidebar.
I did the following to make it work for me:
for the three20 static library, I used cocoapods to include the files within the main project.. it just got rid of all the trouble three20 was giving me (and they are lots..) btw i tried replacing three20 with Nimbus.. but Nimbus was lacking on some of the features that my project was using three20 for.. so Nimbus wasn't helpful.
set skip install to yes under build settings for all other sub projects/static libraries and switched the copy headers from public to project under build phases
most importantly: under the sub libraries.. under build phases i ensured that copy files destination was changed from Absolute path to products directory.
and that was it!
hint: to get an idea of the offending files that's causing your archive to create an archive file rather than an ipa do this:
Select the archive and click the Distribute button.
Select the 'Save Built Products' option.
Hit Next and Save.
Browse the created directory in Finder.
The 'libraries' subdirectory will identify the libraries that you need to set the Skip Install to Yes.
in some cases usr/local/include will identify the culprit header files you need to move from Public to Project or the files that you have to change from absolute path to products directory. but that directory (ie usr/local/include) varies depending on your sublibrary directory structure
Three20 has't update in long time.And it has many bugs.set up this framework is very hard.
you can try nimbus.It come from three20.
Nimbus' Background
Nimbus has been built with much inspiration from the Three20
framework. That being said, there are a number of fundamental problems
with Three20 that Nimbus works very hard to avoid. Among them:
Poor documentation. Spaghetti dependencies. Suffering from a "kitchen
sink" complex. A complex build structure. An enormous number of
difficult-to-solve bugs. Next-to-zero test coverage. For its
weaknesses, Three20 does provide a good deal of value through its
feature set. It is used in over 100 apps in the app store by companies
such as Facebook, LinkedIn, Posterous, Meetup, and SCVNGR.
Nimbus hopes to one day provide as much value as Three20 does on a
feature-by-feature comparison, but with the invaluable benefit of
sublime documentation and test coverage.

What is the correct way to ensure read-only plists are copied to the application build directory?

I have an iPhone application that uses a set of plists to load the data. I found during development that I was getting very strange behaviour whereby XCode did not always read from the latest revision of the list.
I researched this and found that plists are not treated as other files and that updating them may be ignored by XCode. I also found I could fix this by manually dragging the plists to the Copy Bundle Resources list in Targets, but I'd have thought that if Apple really wanted me to do this, they might have XCode add it into that list when the file is added to the project in the first place.
Can anyone tell me what is the correct approach to this problem, please?
Xcode does not automatically copy certain resources and they have to be added manually to the Copy Bundle Resources list in your targets like you said. I find this rather annoying (especially since it seems that only some of my files do this) and im not quite sure if this is a bug or not. I also noticed that xcode usually never adds C source files to the Compile Sources list in Targets in my iPhone projects. Dragging the file into the Copy Bundle Resources should never present a problem unless of course you are creating a file template.

Can you reference Xib files from static libraries on the iPhone?

In my app, i currently have all my code separated into a static library, to make it easier to set up the xcode project targets for the actual app and for unit tests for my code. The problem with this is that i want to put most of my xib files in the static library as well, but it seems that when i run my app and try to reference the xib it can't find it unless it is included in the actual app's target instead of the static library target. Is it possible to have xib files and other resources included in static libraries that can be referenced by code in that same library, and if so, how?
No it isn't possible, because a static library is not the same as a "bundle".
A bundle is a directory that may contain all manner of files including resource files (xib), executable files and static libraries. It exists on the filesystem as a group of individual files.
A static library is a single file that contains classes, code and variables that were linked together by the library creator. It does not "contain" other files, it is essentially a database of compiled code.
Although it would be possible to put the data for the xibs in there, Xcode would have no way of knowing that it was in there, as it looks for them as individual files on the filesystem.
In Mac OS, you may create a "Framework" which is essentially a bundle of code, resources, settings etc which may be reused by multiple projects. However, Apple does not seem to support custom framework creation for iPhone OS.
Bundles
https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW1
Static Libraries
http://en.wikipedia.org/wiki/Static_library
Reply to comment (won't fit in comment box)
No worries, I've been trying to do pretty much the same thing as you for the last week - I'd like to ship a "framework" of xibs, include files and .a libs to a client without giving them all the source code. I couldn't find a good way to do this with bundles either.
For whatever reason, Apple are being particularly obtuse about this - I can't see a reason for them to be so in the case of static libraries (dynamic libraries fair enough).
My solution for now is to manually create a package folder "Foo" that contains the following subfolders:
"include" -> put .h files here
"res" -> put .xib files here
"lib" -> contains "iphoneos" & "iphonesimulator" subfolders each with libFoo.a
Then zip this up and send to the client. The client then:
Unzips the package where ever they like.
Adds the "res" folder under the resources group.
Changes the following target settings:
Other Linker Flags = -Objc -lfoo
Header Search Paths = /include
Library Search Paths = /lib/$(PLATFORM_NAME)
I can probably automate the package creation with some build steps at my end, but the client is stuck with four slightly fiddly steps to get set up.
I found a perfect solution for this that does all the above automatically and more
https://github.com/kstenerud/iOS-Universal-Framework
Its an xCode plugin
It worked for me like a charm,
It works only for XCode 4 and above
Yes You can. add a xib file in your library as you would do for any normal project. Then in library project target add the xib file in copy Files section along with .a file.
In your main project where you are using the library, drag and drop the xib file where .a file for library is located.
Answer in including Xib files to your static library.
This time we have Xcode 11, you just create a bundle target in addition to your library target. The bundle template is available on macOS. Then from the library code, reference the bundle to be able to reference the nib. You distribute the library with the bundle.
A detailed video about using Xibs with static libraries below:
https://www.youtube.com/watch?v=WQI02KR9kQw
When distributing you could also create an SDK. JSON.framework did this in their SVN, and I successfully replicated this. You can see how this was done in http://hltypes.svn.sf.net/ in the hltypes-ios.xcodeproj and the iOS folder in the project.
Primarily you need to "install" into your build folder, and then you need to copy the specially formatted SDKSettings.plist. Then add the path to the SDK into "Additional SDKs" list in application project. Downside of composite SDKs are the need to restart Xcode 3.x whenever this mini-SDK is updated, and Xcode's insistence on constructing a composite SDK created from Apple's base SDK and your mini-SDK (which means you need to wait quite a bit).
Application project still needs to have .xib and other resources manually added.

Best way to share iphone and mac code between projects

I realise that the view/controller stuff will be different between Mac and IPhone apps but the model code may well be similar/the same. So whats the best way to organise a project(s) so that the model code is/can be shared?
Copy/paste - just duplicate it and manually keep it in sync
Have 2 xcode projects point at the same workarea - one for Mac and one for IPhone and share the code.
Common library - presumably you can't do this (or can you)
Thanks for any tips.
There are a few ways to do this. The first thing you can do is is create a project that builds as a framework on Mac OS X. Since you cannot use frameworks on iPhone, you can make static library target that contains the same code files. That basically works, but the header paths will be different. If you want the header paths to be the the same (i.e. <Myframework/MyFramework.h>) you will need to modify the the install path of the static library headers so that they are copied into "$SDK_ROOT/usr/local/include/MyFramework", and make sure /usr/local/include is an included header search path. You will then need to install the library and headers into each SDK_ROOT.
I started out doing the above, but I found it to be a royal pain. So I ended up doing something that is a variant of #2. Basically, I get the header paths to be equivalent by making a directory named "Externals" in my iPhone project root, then a directory named with the appropriate name ("MyFramework") in the externals folder. That is the folder I copy I drag the framework files into.Findally I add the Externals folder as a system header path (which is admittedly sort of a gross hack). You need to manually add new files to the iPhone project, but I have found that to be less of a pain the installing static libs into my build root.
I'm not sure if the suggestion from the previous answer would work. If you look at my previous question, you'll see that I've failed to load a custom framework on the iPhone even though the framework works fine on Mac.
I would go with method 2.
You could develop your application in JavaScript, CSS, and HTML. You would use the WebView and UIWebView objects on the Mac and the iPhone respectively. You can do pretty much anything you want in the WebView objects, even make calls down to Objective-C.
The QuickConnectiPhone installer, found here https://sourceforge.net/projects/quickconnect/, installs QuickConnectMac and QuickConnectiPhone templates into Xcode.
This way you can quickly create an application in one environment and then migrate the view to the other. In fact the QuickConnect framework is highly modular.
If you don't want to develop in JavaScript the same modular framework is found on the Objective-C side of the templates installed.
It should make it much easier for you to do what you are attempting.