AdMob Ad to Landscape Orientation

I checked around the net and found some people looking for this, but nobody who actually posted a code example. So here it is, code to make your Ad Mob ad shift to landscape orientation. My code makes it appear on the bottom, enlarged a little bit, with the device rotated to landscape counter-clockwise.

Add in a UIView called adContainer in your delegate interface declaration, and then update the standard Ad Mob methods as follows.

- (void)showAd 
{	
	adMobAd = [AdMobView requestAdWithDelegate:self]; // start a new ad request
	[adMobAd retain]; // this will be released when it loads (or fails to load)
	adContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 432, 320, 48)];
}
#define degreesToRadians(x) (M_PI * x / 180.0)
 
- (void)didReceiveAd:(AdMobView *)adView 
{
	[adContainer addSubview: adMobAd];
	[window addSubview:adContainer];
	CGAffineTransform makeLandscape = CGAffineTransformMakeRotation(degreesToRadians(90));
	makeLandscape = CGAffineTransformTranslate(makeLandscape, -480/2 + 48/2, 320/2 - 48/2 - 12);
	makeLandscape = CGAffineTransformScale(makeLandscape, 480.0/320, 480.0/320);
	adContainer.transform = makeLandscape;
	autoslider = [NSTimer scheduledTimerWithTimeInterval:AD_REFRESH_PERIOD target:self selector:@selector(refreshAd:) userInfo:nil repeats:YES];
}
- (void)removeAd 
{
	[adMobAd removeFromSuperview];
	[adMobAd release];
	adMobAd = nil;
 
	[adContainer removeFromSuperview];
	[adContainer release];
	adContainer = nil;
}

This was actually my first experience using the CG transforms, so please be gentle if there’s a better way :) .

iPhone App Ad Hoc Distribution Gotchas

I spent more time trying to get Ad Hoc distribution work than any other issue that should have taken 15 minutes. There are a number of things which can go wrong, some of which are ridiculous and Apple will no doubt fix in time, but for now you should know these:

The biggest gotcha: you can not use the “Compress” option in Finder to bundle the Ad Hoc package. It adds files that cause iTunes to freak out. I wrote a quick shell script to bundle everything up and zip it together using the command line zip tool.

mkdir Payload
cp -rp MyApplication.app Payload/
zip -r MyApplication.ipa iTunesArtwork Payload

This way, you can give people the .ipa and .mobileprovision file. Tell them to drag the .mobileprovision into iTunes, and then double click the .ipa. How easy was that?

Another semi-obscure fact: iTunesArtWork is a 512×512 png, named simply ‘iTunesArtwork’ without the extension that needs to be included ONLY with Ad Hoc copies so the icon shows up in the iTunes window. You don’t need to include it, but if you do make sure you only do so when sending out Ad Hoc copies.

One more thing that caught me over and over again: don’t forget to increment the version number in your info.plist file before giving Ad Hoc users a new copy! iTunes is really sneaky about what happens here…in both cases it says the application is already installed, and asks if you want to replace it, but if you try to replace with the same or lower version number, it won’t actually do anything.


If you are getting

Application was not installed on the iPhone because it could not be verified.

then your profile isn’t valid and you should check out this post. This biggest thing to remember is

  1. Delete all the profiles stored in ~/Library/MobileDevice/Provisioning Profile.
  2. Double click your .mobileprovision file and it will get loaded into XCode.
  3. Quit XCode completely. I’m not sure why this is necessary, but often XCode refuses to build unless it starts up with the profile already ready.

Lastly, ensure not only that Entitlements.plist is included in your project (click File, New File, Code Signing, Entitlements), and that get-task-allow is unchecked, but in your “Ad Hoc” build profile (Project, Edit Active Target) expand the list to “All Settings” make sure the “Code Signing Entitlements” field is filled out with your “Entitlements.plist”.

iPhone Development on Jailbroken Device

If you are just starting out on iPhone development, or are considering starting but don’t feel like dropping $99 without getting your hands wet first, then you’ll need to jailbreak your device.

For me, this was great at first as it was far easier to set up than XCode provisioning profiles, and it let me see if I was felt confident enough playing around in Objective C to really take the dive and pay for a developer account.

In case you somehow don’t know where to jailbreak, head to Dev-Team Blog and download the appropriate torrent.

A quick note: I own one of the new Aluminum MacBooks and still have not successfully jailbroken my iPhone using it, due to some error/bug/whatever with the USB drivers failing to put the device into DFU mode. Just find a windows computer to use for 15-25 minutes and use QuickPwn on it.

After you jailbroken your device, you still need to do some tricky steps to get your own compiled iPhone app running on your device. You can find a walkthrough of how to do this here.

iPhone SDK Provisioning Walkthrough

By far the most helpful single resource I found during the long and difficult course of properly signing my code and getting it running on my iPhone is locaded at 24100.net. And the title of the post is very helpful, because those two errors, 0xE800003A and 0xE8000001, are the curse of provisioning on iPhone development.

To sum up my own experience with XCode signing, I learned a few things which have really improved my development experience.

  • I delete provisioning profiles out of XCode as soon as I’m done with them. I will head to ~/Library/MobileDevice/Provisioning Profiles and delete everything in there, and then close XCode.
  • Drag the one .mobileprovision file you want to work with to your XCode icon in the dock, XCode loads it, renames it and puts it back in the above directory, and then I close XCode again. I know, it seems crazy, but XCode gets confused easily, and I’ve found restarting XCode helps.
  • If I’m building for AppStore or Ad Hoc, I literally just load the one provision, clean the entire build (with both checkboxes checked), build it, and then delete the provision profile out of the XCode directory.
  • I spend most of my time with my single development profile sitting in the directory. Even still, XCode spits errors at me sometimes, and a clean build + XCode restart fixes it. I’ve even had to restart my iPhone once when it was still giving me errors after the above steps.