I have a third party API that I am trying to integrate into my iOS Universal application. The API works fine if ran on a device but throws me a compile time link error when trying to run it on the simulator. So, is there a way I can skip their static library linking if I run on the simulator?
Thanks
Actually, It's a lot easier than I thought.
Step 1: Add the linker flags -ObjC and -all_load to your target. This tells the objc runtime that even if we don't reference a class in code, it will still load it into memory.
Step 2: In your code, you can do this:
Class cls = NSClassFromString(#"SomeClassInStaticLibrary");
if (cls == nil)
{
// on the simulator
}
else
{
// on the device, use the class like usual
id myInstance = [[cls alloc] init];
}
Unfortunately, you have to refer to everything as an id, because if you include the headers, you WILL get a linker error.
Its a bit of a hack, but it works.
What you can do is build the Static Library as a FAT one. Compiling for both architectures armv and i386 to run in the simulator.
You can find more information about this here,
http://mark.aufflick.com/blog/2010/11/18/making-a-fat-static-library-for-ios-device-and-simulator
You can control this setting in the Xcode (4.3) Build Settings tab of your target. Where it talks about "Other Linker Flags" you can add a conditional setting (click and hold the lower right "+" icon that says "Add Build Setting" by default). Here you can specify the library to link using normal -l/-L linker flags but only for builds specified as "Any iOS SDK", but don't add this flag for "Any iOS Simulator SDK".
Related
I want to know if my Xcode iPhone project is using ARC, and I can't remember if I ticked that box when creating the project.
How can I get this information?
Select your project, then Build Settings. Look for Objective-C Automatic Reference Counting in the Apple LLVM Compiler - Language section. Make sure you select the target; while you can set this in the project, the target can override it.
(You can also use the search bar in Build Settings for OBJC_ARC.)
Keep in mind, too, that you can turn ARC on or off on a per file basis in build phases.
Or, just try something like this in code:
[[[NSObject alloc] init] autorelease]
If you get an error:
ARC forbids explicit message send of 'autorelease'
Then you're using ARC.
You can also require ARC from a source code file by checking for it:
#if !__has_feature(objc_arc)
#error This file must be built with ARC.
// You can turn on ARC for only this file by adding -fobjc-arc to the build phase.
#endif
Just search for Automatic in your target's build settings:
I'm attempting to upload my first app to the app store using xcode 4.3, but can't get past this error... "application executable is missing a required architecture. At least one of the following architectures must be present: armv7" I looked up the issue. Their are several post on stackoverflow addressing the issue, but none of the suggestions listed worked. I attempted to add armv6 and armv7 to the build settings, but the errors still persist. Any suggestions would be welcomed. Thanks.
screen shot here..
http://dl.dropbox.com/u/2813968/Build%20Settings.png
For Xcode 4.5 at least, set the deployment target to at least iOS 4.3 and that will resolve it. Earlier versions of iOS and armv6 are almost extinct.
Make sure that these settings match your Target and not just your Project settings.
1) Left-click project icon (blue icon, under "Run" button).
2) Next to the project icon (to the right of it), left-click on project name under "PROJECT" (White background).
3)Select tab "Build Settings" and look for tab "Build Active Architecture Only" -----change to -----no
Hi i am using iAd Banner in my test aap.It works fine with 4.0 Sdk but when i went with SDK 3.0 or before ,it crashes without showing anything.I read that weaklink will help me regarding this problem but as per my thinking it crashes when it doesn't find the framework.I do not even know that how to use Weak-link.Please help me to fix this problem.
Expand the Targets directory, right click , and choose “Get Info”. Click the Build tab, make sure “All Configurations” is selected, and navigate to Linking\Other Linker Flags. Double click on that entry, click the “+” button, and type “-weak_framework iAd”.
When allocating your ADBannerView, first check to see if the OS version supports it:
if(NSClassFromString(#"AdBannerView")) {
//Allocate ADBannerView here
}
Then in the build settings of your target, add -weak_framework iAd to Other Linker Flags in the Linking section.
Edited as per Jonathans recommendation.
Just a Hello world app.
I create a view-based appllication named it Hello World.
then save ,build and
I double click the app under products.
cause the error:
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Crashed Thread: 0
Dyld Error Message:
Library not loaded: /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics
Referenced from: /Users/myname/Documents/Control Fun/build/Debug-iphonesimulator/Control Fun.app/Control Fun
Reason: image not found
I googled and tyied many ideas.Unluckily I can't slove it.
Thanks in advance!
You can't run iOS apps directly on Mac OS X. You either have to run a build compiled for the simulator within the iOS Simulator, or a build for the device directly on your iPhone, iPod touch or iPad.
When you double-click the item in Xcode's Products group, you're essentially trying to launch the app directly. Just hit "Build and Run" instead and it should launch in the iOS Simulator or on an attached device, depending on your settings.
Btw: if this really is an iOS related question, you should remove or replace the "cocoa" tag from your OP. Cocoa is Mac, Cocoa Touch is iOS.
Plz check you project has CoreGraphics.framework. It would be defaulty included..but you might remove it by mistake.
You can check included frameworks on "General Tap" of project info.
You probably haven't included the CoreGraphics framework. To add it in do the following :
Click on HelloWorld (ie ur project name) in the Project Navigator.
Click on HelloWorld under the Targets in the Project Editor.
Open "Build Settings" tab, and select "Link Binary With Libraries"
Now, you should see 3 libraries (at a minimum) in this section. They should be : UIKit.framework, Foundation.framework, CoreGraphics.framework
(Note: In some cases the order is important so click and drag them into the order above)
Incase any of those 3 libraries are missing :
Click the '+' (ie ADD) button and type in the name of the missing library. Select it, and hit add. Now run the project again and let me know if you have any more errors :D
Check out my blog for a simple tutorial on making your first iOS app : It teaches you Interface Builder, buttons, methods, etc : http://techtalktone.wordpress.com/2011/11/26/hello-world/
Is it possible to have an Xcode project file which contains both the Cocoa (MacOSX) and CocoaTouch (iPhone) versions of a component?
I thought I was getting close until I realized that you need to set "Base SDK for All Configurations" in the Project Settings in order for the cross-compiler to be called (and for any CocoaTouch frameworks to be found and properly handled by Xcode).
Since that is a project-wide setting, I don't know how I can have both MacOSX and iPhoneOS targets in the same project file.
Specifying:
SDKROOT = iphoneos3.0
in an xcconfig file (used by iPhone-only targets) did not seem to work.
Yes, you can, but there are some glitches.
Okay first off, you can override any Base SDK in several ways. One is that you can on the gear at the bottom of the inspector and "Add Build Setting Condition" which lets you conditionalize any build settings based on things like the target architecture, etc.
Second, even if you have a project wide setting, it can been overriden per target. So if you have seperate targets you can just add an SDKROOT to the to the various targets with their SDKROOT.
Third, the SDK selected in the popup in your Xcode window overrides evertyhing else. So if you have something besides "Base SDK" in that popup it will get used. Also, if you do switch that (lets say from "Base SDK" to "iPhone Simulator") and then you switch targets to a target that does not support the currently selected SDK it will appear to deselect, but it doesn't actually correctly autorevert the Base SDK, you need to reselect it in the pop up.
I still can't consistently get multiple archs building together properly as part of an aggregate (for instance, having an OS X target that preprocesses some resource built so that it can be used as a build phase in a later target building an iPhone app).