views:

217

answers:

1

Hi folks, how can I set up a Universal project which has support for iAd (just in the iPhone app)?

Using the iPhone SDK 4, let's suppose I do the following steps:

  1. Open XCode;
  2. Go to File > New Project ;
  3. Select Window-based application (or whatever), choose Product: Universal (and after choose a name for the project).

It will create a Universal project skeleton with iPhone/iPad groups as usual. Now, I decide to integrate iAd in my iPhone App, so I do the following:

  1. Right-click in the project's group called Frameworks > Add > Existing Frameworks...
  2. Choose iAd.framework > Add

So far, so good. I can simply Build And Run using the Active Executable as Project Name - iPhone Simulator 4.0 and the project runs OK. Suppose I change the Active Executable to Project Name - iPad Simulator 3.2. Although the iAd.framework is still being referenced in the Frameworks successfully (without being marked with the Red color), the App crashed in the iPad simulator and I get the following error message:

dyld: Library not loaded: /System/Library/Frameworks/iAd.framework/iAd Referenced from: /Users/nexia1/Library/Application Support/iPhone Simulator/3.2/Applications/8479EE14-28AA-4628-A668-CCF3FE770628/Untitled.app/Untitled Reason: image not found

Can I use the iAd in such a Universal project? (even that I only references it in my iPhone app).

Thanks in advance

+3  A: 

You need to weak link the framework, and in your code ask if the classes exist.

Apple has a similar example for this: http://developer.apple.com/iphone/library/samplecode/MailComposer/index.html

It is about the in-app mail sheet on 3.0 while still running on 2.x, but you'll get the point.

Eiko
Thanks Eiko, that solved my problem!For simplicity purposes, the steps are as follows: Go into Targets > Select the Target and click Info. In the Linked Libraries selected the iAd.framework and change the Type from Required to Weak.Thanks!
Eduardo Coelho
also check UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone before sending messages to the the ADBannerView or else you might get some crashes
valexa