SlideShare a Scribd company logo
cooking With Iad
                              JOnathan Saggau / Noah Gift




Tuesday, September 28, 2010
The Talk in a Nutshell




Tuesday, September 28, 2010
Agenda


                    • iAd Overview
                    • Mobclix and iAd manual Integration
                    • Integrating iAds into an app: Apple’s
                      Core Data Books sample
                    • Demos and other neat stuff



Tuesday, September 28, 2010
Ad Delivery Strategy

                    • Use iAD when it is available
                         • Higher CPM
                         • Better Looking
                    • Use mobclix otherwise
                         • Internationally
                         • on < iOS 4.0 (read: orig. iPhone)


Tuesday, September 28, 2010
Grab The Code



                    • hg clone http://bitbucket.org/
                      jonmarimba/iadcoredatabooks




Tuesday, September 28, 2010
Core Data Books From
                              apple




 hg update --rev 1                      Show default
Tuesday, September 28, 2010
Adding iAd to Core Data Books
                       Adding iAd Framework


         • Adding the
           iAd
           Framework




 hg update --rev 1
Tuesday, September 28, 2010
Adding a Banner
   #import "AddViewController.h"
   #import <iAd/iAd.h>

   @interface RootViewController : UIViewController <NSFetchedResultsControllerDelegate,
                                                      AddViewControllerDelegate,
                                                      ADBannerViewDelegate> {
   !   NSFetchedResultsController *fetchedResultsController;
       NSManagedObjectContext *managedObjectContext;!
       NSManagedObjectContext *addingManagedObjectContext;!
       ADBannerView *iadBanner;

   @private
       BOOL showingIAdBanner;
   }

   @property       (nonatomic,   retain)   NSFetchedResultsController *fetchedResultsController;
   @property       (nonatomic,   retain)   NSManagedObjectContext *managedObjectContext;
   @property       (nonatomic,   retain)   NSManagedObjectContext *addingManagedObjectContext;
   @property       (nonatomic,   retain)   IBOutlet UITableView *tableView;
   @property       (nonatomic,   retain)   ADBannerView *iadBanner;

   - (IBAction)addBook;
   - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;

   @end




Tuesday, September 28, 2010
Adding a Banner
                    • Do it in code if you want to support <
                      iOS 4.0 (original iPhone)
     -(ADBannerView *)iadBanner
     {
         if (!iadBanner)
         {
             Class bannerClass = NSClassFromString(@"ADBannerView");
             if (bannerClass) {
                 iadBanner = [[ADBannerView alloc] initWithFrame:CGRectZero];
                 [iadBanner setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];
                 iadBanner.requiredContentSizeIdentifiers = [NSSet
                                                             setWithObjects:ADBannerContentSizeIdentifier320x50,
                                                             ADBannerContentSizeIdentifier480x32, nil];
                 [self.view addSubview:iadBanner];
                 CGRect viewFrame = [[self view] frame];
                 CGFloat width = viewFrame.size.width;
                 [iadBanner setFrame:CGRectMake(0, self.tableView.frame.size.height,
                                                width, width == 480. ? 32. : 50.)];
                 [iadBanner setDelegate:self];
             }
         }
         return iadBanner;
     }




Tuesday, September 28, 2010
iAD Delegate Protocol
                       #pragma mark iAD Delegate
                       // This method is invoked each time a banner loads a new advertisement. Once a banner has loaded an
                       ad,
                       // it will display that ad until another ad is available. The delegate might implement this method
                       if
                       // it wished to defer placing the banner in a view hierarchy until the banner has content to
                       display.
                       - (void)bannerViewDidLoadAd:(ADBannerView *)banner;
                       {
                           [self showIAdBanner:YES];
                       }

                       // This method will be invoked when an error has occurred attempting to get advertisement content.
                       // Possible error codes defined as constants in ADManager.h.
                       - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error;
                       {
                           // no iAd adds, so try mobclix
                           [self hideIAdBanner:YES];
                       }

                       // This message will be sent when the user taps on the banner and some action is to be taken.
                       // Actions either display full screen content in a modal session or take the user to a different
                       // application. The delegate may return NO to block the action from taking place, but this
                       // should be avoided if possible because most advertisements pay significantly more when
                       // the action takes place and, over the longer term, repeatedly blocking actions will
                       // decrease the ad inventory available to the application. Applications may wish to pause video,
                       // audio, or other animated content while the advertisement's action executes.
                       - (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave;
                       {
                           return YES;
                       }

                       // This message is sent when a modal action has completed and control is returned to the
                       application.
                       // Games, media playback, and other activities that were paused in response to the beginning
                       // of the action should resume at this point.
                       - (void)bannerViewActionDidFinish:(ADBannerView *)banner;
                       {
                           NSLog(@"bannerViewActionDidFinish");
                       }



Tuesday, September 28, 2010
Modifying the table
                 view’s frame when an ad
                         is shown
        -(CGRect)frameForIAdTable:(BOOL)showingBanner
        {
            CGRect frameForTable = self.view.frame;
            frameForTable.origin.x = frameForTable.origin.y = 0.0;
            if (showingBanner) {
                frameForTable.size.height -= ([self iadBanner].frame.size.height);
            }
            return frameForTable;
        }




Tuesday, September 28, 2010
Showing Banner
           -(void)showIAdBanner:(BOOL)animated
           {
               if (showingIAdBanner) {
                   return;
               }

                 //resets some of the geometry
                 [self.view addSubview:[self iadBanner]];
                 [self hideIAdBanner:NO];

                 if (animated)
                 {
                     [UIView beginAnimations:@"showIAdBanner" context:nil];
                     [UIView setAnimationDelegate:self];
                     [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
                 }

                 CGRect frameForTable = [self frameForIAdTable:YES];
                 [self.tableView setFrame:frameForTable];
                 CGRect frameForBanner = [[self iadBanner] frame];
                 frameForBanner.origin.y = frameForTable.size.height;
                 [[self iadBanner] setFrame:frameForBanner];
                 showingIAdBanner = YES;
                 if (animated)
                 {
                     [UIView commitAnimations];
                 }
           }


Tuesday, September 28, 2010
Hiding Banner
        -(void)hideIAdBanner:(BOOL)animated
        {
            if (animated)
            {
                [UIView beginAnimations:@"hideIAdBanner" context:nil];
                [UIView setAnimationDelegate:self];
                [UIView setAnimationDidStopSelector:@selector
        (animationDidStop:finished:context:)];
            }

                CGRect frameForTable = [self frameForIAdTable:NO];
                [self.tableView setFrame:frameForTable];
                CGRect frameForBanner = [[self iadBanner] frame];
                frameForBanner.origin.y = self.view.frame.size.height + 1;
                [[self iadBanner] setFrame:frameForBanner];
                showingIAdBanner = NO;

                if (animated)
                {
                    [UIView commitAnimations];
                }
        }



Tuesday, September 28, 2010
#protip



                    • killall adlibd
                    • ^ for when the simulator doesn’t seem
                      to want to serve up ads.




Tuesday, September 28, 2010
What happens when
                               There is no iAD?

                    • Internationally (iAD is US only
                      currently)
                    • Fill rate is meh (ish).
                    • Not available on original phone.
                    • You’ll want a supplemental ad service.


 hg update
Tuesday, September 28, 2010
Mobclix


                    • http://mobclix.com/
                    • Largest Mobile Ad Exchange
                    • Advertisers Compete for eyeballs
                    • Decent dough


 hg update --rev 1
Tuesday, September 28, 2010
Adding MobClix to Core Data
                              Books

         • Add the Static Library
         • Other Linker Flags
               • -all_load
               • -ObjC




           hg update
Tuesday, September 28, 2010
Adding a Banner
       #import "AddViewController.h"
       #import <iAd/iAd.h>
       #import "MobclixAds.h"

       @interface RootViewController : UIViewController <NSFetchedResultsControllerDelegate,
       AddViewControllerDelegate,
       ADBannerViewDelegate,
       MobclixAdViewDelegate> {
       ! NSFetchedResultsController *fetchedResultsController;
           NSManagedObjectContext *managedObjectContext;!
           NSManagedObjectContext *addingManagedObjectContext;!
           ADBannerView *iadBanner;
           UIView *mobAdBannerHost;
           MobclixAdView *mobAdBanner;

       @private
           BOOL showingIAdBanner;
           BOOL showingMobAdBanner;
           BOOL mobAdHasContent;
       }

       @property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
       @property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
       @property (nonatomic, retain) NSManagedObjectContext *addingManagedObjectContext;
       @property (nonatomic, retain) IBOutlet UITableView *tableView;
       @property (nonatomic, retain) ADBannerView *iadBanner;
       @property(nonatomic, retain)IBOutlet UIView *mobAdBannerHost;
       @property(nonatomic, retain)IBOutlet MobclixAdView *mobAdBanner;

       - (IBAction)addBook;
       - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;

       @end
Tuesday, September 28, 2010
Adding a Banner in IB




Tuesday, September 28, 2010
MobClix Delegate
                                 Protocol
                       // Advertisement Status Messages
                       - (void)adViewDidFinishLoad:(MobclixAdView*)adView;
                       {
                           [self showMobAdBanner:YES];
                           mobAdHasContent = YES;
                       }
                       - (void)adView:(MobclixAdView*)adView didFailLoadWithError:(NSError*)error;
                       {
                           [self hideMobAdBanner:YES];
                           mobAdHasContent = NO;
                       }

                       // Advertisement Touchthrough Messages
                       - (void)adViewWillTouchThrough:(MobclixAdView*)adView;
                       {

                       }

                       - (void)adViewDidFinishTouchThrough:(MobclixAdView*)adView;
                       {

                       }
                       //- (void)adView:(MobclixAdView*)adView didTouchCustomAdWithString:
                       (NSString*)string;

                       // Keeps ads from automatically taking over the app.
                       - (BOOL)adViewCanAutoplay:(MobclixAdView*)adView;
                       {
                           return NO;
                       }
Tuesday, September 28, 2010
New stuff in iAD
                                delegate methods
               #pragma mark iAD Delegate
               // This method is invoked each time a banner loads a new advertisement. Once a banner has loaded an ad,
               // it will display that ad until another ad is available. The delegate might implement this method if
               // it wished to defer placing the banner in a view hierarchy until the banner has content to display.
               - (void)bannerViewDidLoadAd:(ADBannerView *)banner;
               {
                   [self showIAdBanner:YES];

                     //give full priority to iAd and get rid of the MobClix ad
                     [self hideMobAdBanner:YES];
                     [self.mobAdBanner cancelAd];
                     [self.mobAdBanner pauseAdAutoRefresh];
               }

               // This method will be invoked when an error has occurred attempting to get advertisement content.
               // Possible error codes defined as constants in ADManager.h.
               - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error;
               {
                   // no iAd adds, so try mobclix
                   [self hideIAdBanner:YES];
                   [self.mobAdBanner resumeAdAutoRefresh];
               }




Tuesday, September 28, 2010
Modifying the table
                              view’s frame when a
                              Mobclix ad is shown
         -(CGRect)frameForMobTable:(BOOL)showingBanner
         {
             CGRect frameForTable = self.view.frame;
             frameForTable.origin.x = frameForTable.origin.y = 0.0;
             if (showingBanner) {
                 frameForTable.size.height -= ([self mobAdBannerHost].frame.size.height);
             }
             else if (showingIAdBanner)
             {
                 frameForTable = [self frameForIAdTable:YES];
             }
             return frameForTable;
         }




Tuesday, September 28, 2010
Showing Banner
       -(void)showMobAdBanner:(BOOL)animated;
       {
           if (showingMobAdBanner) {
               return;
           }

                [self.view addSubview:[self mobAdBannerHost]];
             [self hideMobAdBanner:NO];

             if (animated)
             {
                 [UIView beginAnimations:@"showMobAdBanner" context:nil];
                 [UIView setAnimationDelegate:self];
                 [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
             }

             CGRect frameForTable = [self frameForMobTable:YES];
             [self.tableView setFrame:frameForTable];
             CGRect frameForBannerHost = [[self mobAdBannerHost] frame];
             frameForBannerHost.origin.y = frameForTable.size.height;
             frameForBannerHost.origin.x = 0.;
             frameForBannerHost.size.width = self.view.frame.size.width;
             [[self mobAdBannerHost] setFrame:frameForBannerHost];

             CGRect frameForBanner = [self.mobAdBanner frame];
             frameForBanner.origin.x = floorf((frameForBannerHost.size.width - self.mobAdBanner.frame.size.width) * .
       5);
             frameForBanner.origin.y = 5.;
             [self.mobAdBanner setFrame:frameForBanner];

             showingMobAdBanner = YES;

             if (animated)
             {
                 [UIView commitAnimations];
             }
       }
Tuesday, September 28, 2010
Hiding Banner
      -(void)hideMobAdBanner:(BOOL)animated;
      {

             if (animated)
             {
                 [UIView beginAnimations:@"hideMobAdBanner" context:nil];
                 [UIView setAnimationDelegate:self];
                 [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
             }

             CGRect frameForTable = [self frameForMobTable:NO];
             [self.tableView setFrame:frameForTable];
             CGRect frameForBanner = [[self mobAdBannerHost] frame];
             frameForBanner.origin.y = self.view.frame.size.height + 1;
             [[self mobAdBannerHost] setFrame:frameForBanner];
             showingMobAdBanner = NO;

             if (animated)
             {
                 [UIView commitAnimations];
             }
      }




Tuesday, September 28, 2010
Prettification of
                              mobclix banners
               // prettify the mobclix banner a little
               [[mobAdBanner layer] setBorderColor:[[UIColor grayColor] CGColor]];
               [mobAdBannerHost setBackgroundColor:[UIColor colorWithRed:199./255.
                                                                   green:206/255.
                                                                    blue:213/255.
                                                                   alpha:1.]];
               CGFloat scale = 1.0;
               if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
                   scale = [[UIScreen mainScreen] scale];
               }
               if (scale > 1.0)
               {
                   //iPhone 4 looks okay with border width of one, it's sort of meh on the
                   //lower DPI screens.
                   [[mobAdBanner layer] setBorderWidth:1];
                   [[mobAdBanner layer] setCornerRadius:4];
               } else {
                   [[mobAdBanner layer] setBorderWidth:2];
                   [[mobAdBanner layer] setCornerRadius:6];
               }

               [mobAdBanner setClipsToBounds:YES];

               // Drop shadow below table view (this is an ugly way to do it, but it's easier
               // in a way given that we support 3.1.2 through 4.0 at this point.

               UIImage *img = [UIImage imageNamed:@"littleShadow.png"];
               CGRect shadowViewFrame = CGRectMake(0, 0, mobAdBannerHost.frame.size.width, img.size.height);
               UIImageView *shadowView = [[UIImageView alloc] initWithFrame:shadowViewFrame];
               [shadowView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
               [shadowView setImage:img];

               [mobAdBannerHost addSubview:shadowView];
               [mobAdBannerHost bringSubviewToFront:shadowView];
               [shadowView release];

Tuesday, September 28, 2010
Rotatin’

                    • Mobclix ads look awful rotated to
                      landscape
                         • Too tall
                         • Too Narrow
                    • iAD ads look great in landscape
                    • Hide mobclix no matter what in
                      landscape

Tuesday, September 28, 2010
Rotatin’
                    (heh. Get it? Rotatin?)
                    //
                   -    Ov
                      (B err
                  in    O
                     te OL) ide
                       rf     s
                          ac hou to a
                      //    eO      l
                     re Ret     ri dAu llow
                                  e
                       tu     ur nta toro ori
                          rn     n      t      t      e
          }                   (i Y E S i o n a t e T n t a t
                                 nt            {      oI     i
                              in erf for                 nt ons
                                                           er
                                 t
                             in erf aceO supp                  fa oth
                                                                 ce    e
                                te     a
                                   rf ceO rien orte                 Or r t
                                                                      ie    h
                                      ac    r
                                         eO ien tati d or                nt an
                                                                           at    t
                                           ri     t
                                              en ati on = ient                io he
                                                                                n:    d
                                                 ta     o
                                                    ti n = = UI atio               (U efa
                                                                                     II     u
                                                      on     =      I
                                                          ==    UI nte ns               nt lt
                                                                                          er      p
                                                                  D
                                                               UI evi rfac                    fa ort
                                                                                                ce      r
                                                                 De    c
                                                                    vi eOr eOri                     Or ait
                                                                                                      ie
                                                                      ce    i
                                                                         Or ent enta                      nt ori
                                                                                                            at    e
                                                                           ie    a
                                                                              nt tio tion                      io nta
                                                                                                                 n)   ti
                                                                                at    n
                                                                                   io Lan Port                           on
                                                                                                                            .
                                                                                     nL     ds      ra
                                                                                        an     ca      i
                                                                                           ds     pe t |
                                                                                              ca     R
                                                                                                 pe igh |
                                                                                                    Le     t
                                                                                                       ft    |
                                                                                                          ); |




Tuesday, September 28, 2010
Rotatin’
        - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:
        (NSTimeInterval)duration
        {
            if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
            {
                 [self iadBanner].currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32;
                if(showingMobAdBanner)
                 {
                     //Admob ads look awful in landscape. They're too big.
                     //Disable them until we can make them pretty
                     [self hideMobAdBanner:YES];
                     [self.mobAdBanner cancelAd];
                     [self.mobAdBanner pauseAdAutoRefresh];
                 }
            }
            else
            {
                 [self iadBanner].currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
                if(!showingIAdBanner)
                 {
                     [self.mobAdBanner resumeAdAutoRefresh];
                     if (mobAdHasContent)
                     {
                         [self performSelector:@selector(showMobAdBannerAnimated) withObject:nil
        afterDelay:duration+1];
                     }
                 }
            }
        }



Tuesday, September 28, 2010
The End: Questions?




Tuesday, September 28, 2010
Attributions/References

                    • Touchengine Framework: http://
                      code.google.com/p/touchengine/
                    • http://www.flickr.com/photos/
                      71849667@N00/106241586/sizes/z/in/
                      photostream/
                    • http://www.flickr.com/photos/
                      thebusybrain/2632651360/

Tuesday, September 28, 2010

More Related Content

Viewers also liked

De lo análogo a lo digital
De lo análogo a lo digitalDe lo análogo a lo digital
De lo análogo a lo digitalLorenaL0r3n4
 
Balanceiledelse-topleder.4 marts 2015
Balanceiledelse-topleder.4 marts 2015Balanceiledelse-topleder.4 marts 2015
Balanceiledelse-topleder.4 marts 2015Helle Rosdahl Lund
 
Vietnam war vocabulary
Vietnam war vocabularyVietnam war vocabulary
Vietnam war vocabularyKatie
 
Nyhedsmagasinet Balance juni 2015,low res. fra CBAF.dk
Nyhedsmagasinet Balance juni 2015,low res. fra CBAF.dkNyhedsmagasinet Balance juni 2015,low res. fra CBAF.dk
Nyhedsmagasinet Balance juni 2015,low res. fra CBAF.dkHelle Rosdahl Lund
 
produktivitet og fleksibilitet en svær balance, af Helle Rosdahl Lund, HR ...
produktivitet  og fleksibilitet  en svær  balance, af Helle Rosdahl Lund, HR ...produktivitet  og fleksibilitet  en svær  balance, af Helle Rosdahl Lund, HR ...
produktivitet og fleksibilitet en svær balance, af Helle Rosdahl Lund, HR ...Helle Rosdahl Lund
 
“Comunicazione in rete e volontariato digitale: influsso e potenzialità dei s...
“Comunicazione in rete e volontariato digitale: influsso e potenzialità dei s...“Comunicazione in rete e volontariato digitale: influsso e potenzialità dei s...
“Comunicazione in rete e volontariato digitale: influsso e potenzialità dei s...Emanuele Boi
 

Viewers also liked (8)

De lo análogo a lo digital
De lo análogo a lo digitalDe lo análogo a lo digital
De lo análogo a lo digital
 
Drug study form
Drug study formDrug study form
Drug study form
 
Balanceiledelse-topleder.4 marts 2015
Balanceiledelse-topleder.4 marts 2015Balanceiledelse-topleder.4 marts 2015
Balanceiledelse-topleder.4 marts 2015
 
Vietnam war vocabulary
Vietnam war vocabularyVietnam war vocabulary
Vietnam war vocabulary
 
Nyhedsmagasinet Balance juni 2015,low res. fra CBAF.dk
Nyhedsmagasinet Balance juni 2015,low res. fra CBAF.dkNyhedsmagasinet Balance juni 2015,low res. fra CBAF.dk
Nyhedsmagasinet Balance juni 2015,low res. fra CBAF.dk
 
Drug study form
Drug study formDrug study form
Drug study form
 
produktivitet og fleksibilitet en svær balance, af Helle Rosdahl Lund, HR ...
produktivitet  og fleksibilitet  en svær  balance, af Helle Rosdahl Lund, HR ...produktivitet  og fleksibilitet  en svær  balance, af Helle Rosdahl Lund, HR ...
produktivitet og fleksibilitet en svær balance, af Helle Rosdahl Lund, HR ...
 
“Comunicazione in rete e volontariato digitale: influsso e potenzialità dei s...
“Comunicazione in rete e volontariato digitale: influsso e potenzialità dei s...“Comunicazione in rete e volontariato digitale: influsso e potenzialità dei s...
“Comunicazione in rete e volontariato digitale: influsso e potenzialità dei s...
 

Similar to iphonedevcon 2010: Cooking with iAd

Guice tutorial
Guice tutorialGuice tutorial
Guice tutorialAnh Quân
 
303 TANSTAAFL: Using Open Source iPhone UI Code
303 TANSTAAFL: Using Open Source iPhone UI Code303 TANSTAAFL: Using Open Source iPhone UI Code
303 TANSTAAFL: Using Open Source iPhone UI Codejonmarimba
 
Core Animation
Core AnimationCore Animation
Core Animationbdudney
 
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
Session 15  - Working with Image, Scroll, Collection, Picker, and Web ViewSession 15  - Working with Image, Scroll, Collection, Picker, and Web View
Session 15 - Working with Image, Scroll, Collection, Picker, and Web ViewVu Tran Lam
 
Desenvolvimento iOS - Aula 4
Desenvolvimento iOS - Aula 4Desenvolvimento iOS - Aula 4
Desenvolvimento iOS - Aula 4Saulo Arruda
 
Academy PRO: React native - building first scenes
Academy PRO: React native - building first scenesAcademy PRO: React native - building first scenes
Academy PRO: React native - building first scenesBinary Studio
 
Integrating Angular js & three.js
Integrating Angular js & three.jsIntegrating Angular js & three.js
Integrating Angular js & three.jsJosh Staples
 
Desmistificando o Phonegap (Cordova)
Desmistificando o Phonegap (Cordova)Desmistificando o Phonegap (Cordova)
Desmistificando o Phonegap (Cordova)Loiane Groner
 
Displaying additional image types in XMetaL
Displaying additional image types in XMetaLDisplaying additional image types in XMetaL
Displaying additional image types in XMetaLXMetaL
 
Capture image on eye blink
Capture image on eye blinkCapture image on eye blink
Capture image on eye blinkInnovationM
 
MobileConf 2015: Desmistificando o Phonegap (Cordova)
MobileConf 2015: Desmistificando o Phonegap (Cordova)MobileConf 2015: Desmistificando o Phonegap (Cordova)
MobileConf 2015: Desmistificando o Phonegap (Cordova)Loiane Groner
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentanistar sung
 
CocoaHeads Toulouse - Guillaume Cerquant - UIView
CocoaHeads Toulouse - Guillaume Cerquant - UIViewCocoaHeads Toulouse - Guillaume Cerquant - UIView
CocoaHeads Toulouse - Guillaume Cerquant - UIViewCocoaHeads France
 
Top Tips for Android UIs - Getting the Magic on Tablets
Top Tips for Android UIs - Getting the Magic on TabletsTop Tips for Android UIs - Getting the Magic on Tablets
Top Tips for Android UIs - Getting the Magic on TabletsMotorola Mobility - MOTODEV
 

Similar to iphonedevcon 2010: Cooking with iAd (20)

iOS Training Session-3
iOS Training Session-3iOS Training Session-3
iOS Training Session-3
 
IOS APPs Revision
IOS APPs RevisionIOS APPs Revision
IOS APPs Revision
 
Google GIN
Google GINGoogle GIN
Google GIN
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
 
303 TANSTAAFL: Using Open Source iPhone UI Code
303 TANSTAAFL: Using Open Source iPhone UI Code303 TANSTAAFL: Using Open Source iPhone UI Code
303 TANSTAAFL: Using Open Source iPhone UI Code
 
Core Animation
Core AnimationCore Animation
Core Animation
 
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
Session 15  - Working with Image, Scroll, Collection, Picker, and Web ViewSession 15  - Working with Image, Scroll, Collection, Picker, and Web View
Session 15 - Working with Image, Scroll, Collection, Picker, and Web View
 
iOS
iOSiOS
iOS
 
Desenvolvimento iOS - Aula 4
Desenvolvimento iOS - Aula 4Desenvolvimento iOS - Aula 4
Desenvolvimento iOS - Aula 4
 
I os 11
I os 11I os 11
I os 11
 
Koin
KoinKoin
Koin
 
Academy PRO: React native - building first scenes
Academy PRO: React native - building first scenesAcademy PRO: React native - building first scenes
Academy PRO: React native - building first scenes
 
Integrating Angular js & three.js
Integrating Angular js & three.jsIntegrating Angular js & three.js
Integrating Angular js & three.js
 
Desmistificando o Phonegap (Cordova)
Desmistificando o Phonegap (Cordova)Desmistificando o Phonegap (Cordova)
Desmistificando o Phonegap (Cordova)
 
Displaying additional image types in XMetaL
Displaying additional image types in XMetaLDisplaying additional image types in XMetaL
Displaying additional image types in XMetaL
 
Capture image on eye blink
Capture image on eye blinkCapture image on eye blink
Capture image on eye blink
 
MobileConf 2015: Desmistificando o Phonegap (Cordova)
MobileConf 2015: Desmistificando o Phonegap (Cordova)MobileConf 2015: Desmistificando o Phonegap (Cordova)
MobileConf 2015: Desmistificando o Phonegap (Cordova)
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app development
 
CocoaHeads Toulouse - Guillaume Cerquant - UIView
CocoaHeads Toulouse - Guillaume Cerquant - UIViewCocoaHeads Toulouse - Guillaume Cerquant - UIView
CocoaHeads Toulouse - Guillaume Cerquant - UIView
 
Top Tips for Android UIs - Getting the Magic on Tablets
Top Tips for Android UIs - Getting the Magic on TabletsTop Tips for Android UIs - Getting the Magic on Tablets
Top Tips for Android UIs - Getting the Magic on Tablets
 

More from Lecturer UC Davis & Northwestern (8)

Sentiment analysis for Business Analytics
Sentiment analysis for Business AnalyticsSentiment analysis for Business Analytics
Sentiment analysis for Business Analytics
 
Social power and_influence_in_the_nba_gitpro
Social power and_influence_in_the_nba_gitproSocial power and_influence_in_the_nba_gitpro
Social power and_influence_in_the_nba_gitpro
 
Erlang factory slides
Erlang factory slidesErlang factory slides
Erlang factory slides
 
iphone and Google App Engine
iphone and Google App Engineiphone and Google App Engine
iphone and Google App Engine
 
Favorite X Code4 Features
Favorite X Code4 FeaturesFavorite X Code4 Features
Favorite X Code4 Features
 
RabbitMQ Plugins Talk
RabbitMQ Plugins TalkRabbitMQ Plugins Talk
RabbitMQ Plugins Talk
 
PyCon 2011: IronPython Command Line
PyCon 2011:  IronPython Command LinePyCon 2011:  IronPython Command Line
PyCon 2011: IronPython Command Line
 
Pycon 2008: Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *NixPycon 2008:  Python Command-line Tools *Nix
Pycon 2008: Python Command-line Tools *Nix
 

Recently uploaded

In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsExpeed Software
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka DoktorováCzechDreamin
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIES VE
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxAbida Shariff
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoTAnalytics
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀DianaGray10
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupCatarinaPereira64715
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesThousandEyes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backElena Simperl
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...Elena Simperl
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
 

Recently uploaded (20)

In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 

iphonedevcon 2010: Cooking with iAd

  • 1. cooking With Iad JOnathan Saggau / Noah Gift Tuesday, September 28, 2010
  • 2. The Talk in a Nutshell Tuesday, September 28, 2010
  • 3. Agenda • iAd Overview • Mobclix and iAd manual Integration • Integrating iAds into an app: Apple’s Core Data Books sample • Demos and other neat stuff Tuesday, September 28, 2010
  • 4. Ad Delivery Strategy • Use iAD when it is available • Higher CPM • Better Looking • Use mobclix otherwise • Internationally • on < iOS 4.0 (read: orig. iPhone) Tuesday, September 28, 2010
  • 5. Grab The Code • hg clone http://bitbucket.org/ jonmarimba/iadcoredatabooks Tuesday, September 28, 2010
  • 6. Core Data Books From apple hg update --rev 1 Show default Tuesday, September 28, 2010
  • 7. Adding iAd to Core Data Books Adding iAd Framework • Adding the iAd Framework hg update --rev 1 Tuesday, September 28, 2010
  • 8. Adding a Banner #import "AddViewController.h" #import <iAd/iAd.h> @interface RootViewController : UIViewController <NSFetchedResultsControllerDelegate, AddViewControllerDelegate, ADBannerViewDelegate> { ! NSFetchedResultsController *fetchedResultsController; NSManagedObjectContext *managedObjectContext;! NSManagedObjectContext *addingManagedObjectContext;! ADBannerView *iadBanner; @private BOOL showingIAdBanner; } @property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController; @property (nonatomic, retain) NSManagedObjectContext *managedObjectContext; @property (nonatomic, retain) NSManagedObjectContext *addingManagedObjectContext; @property (nonatomic, retain) IBOutlet UITableView *tableView; @property (nonatomic, retain) ADBannerView *iadBanner; - (IBAction)addBook; - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath; @end Tuesday, September 28, 2010
  • 9. Adding a Banner • Do it in code if you want to support < iOS 4.0 (original iPhone) -(ADBannerView *)iadBanner { if (!iadBanner) { Class bannerClass = NSClassFromString(@"ADBannerView"); if (bannerClass) { iadBanner = [[ADBannerView alloc] initWithFrame:CGRectZero]; [iadBanner setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin]; iadBanner.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil]; [self.view addSubview:iadBanner]; CGRect viewFrame = [[self view] frame]; CGFloat width = viewFrame.size.width; [iadBanner setFrame:CGRectMake(0, self.tableView.frame.size.height, width, width == 480. ? 32. : 50.)]; [iadBanner setDelegate:self]; } } return iadBanner; } Tuesday, September 28, 2010
  • 10. iAD Delegate Protocol #pragma mark iAD Delegate // This method is invoked each time a banner loads a new advertisement. Once a banner has loaded an ad, // it will display that ad until another ad is available. The delegate might implement this method if // it wished to defer placing the banner in a view hierarchy until the banner has content to display. - (void)bannerViewDidLoadAd:(ADBannerView *)banner; { [self showIAdBanner:YES]; } // This method will be invoked when an error has occurred attempting to get advertisement content. // Possible error codes defined as constants in ADManager.h. - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error; { // no iAd adds, so try mobclix [self hideIAdBanner:YES]; } // This message will be sent when the user taps on the banner and some action is to be taken. // Actions either display full screen content in a modal session or take the user to a different // application. The delegate may return NO to block the action from taking place, but this // should be avoided if possible because most advertisements pay significantly more when // the action takes place and, over the longer term, repeatedly blocking actions will // decrease the ad inventory available to the application. Applications may wish to pause video, // audio, or other animated content while the advertisement's action executes. - (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave; { return YES; } // This message is sent when a modal action has completed and control is returned to the application. // Games, media playback, and other activities that were paused in response to the beginning // of the action should resume at this point. - (void)bannerViewActionDidFinish:(ADBannerView *)banner; { NSLog(@"bannerViewActionDidFinish"); } Tuesday, September 28, 2010
  • 11. Modifying the table view’s frame when an ad is shown -(CGRect)frameForIAdTable:(BOOL)showingBanner { CGRect frameForTable = self.view.frame; frameForTable.origin.x = frameForTable.origin.y = 0.0; if (showingBanner) { frameForTable.size.height -= ([self iadBanner].frame.size.height); } return frameForTable; } Tuesday, September 28, 2010
  • 12. Showing Banner -(void)showIAdBanner:(BOOL)animated { if (showingIAdBanner) { return; } //resets some of the geometry [self.view addSubview:[self iadBanner]]; [self hideIAdBanner:NO]; if (animated) { [UIView beginAnimations:@"showIAdBanner" context:nil]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; } CGRect frameForTable = [self frameForIAdTable:YES]; [self.tableView setFrame:frameForTable]; CGRect frameForBanner = [[self iadBanner] frame]; frameForBanner.origin.y = frameForTable.size.height; [[self iadBanner] setFrame:frameForBanner]; showingIAdBanner = YES; if (animated) { [UIView commitAnimations]; } } Tuesday, September 28, 2010
  • 13. Hiding Banner -(void)hideIAdBanner:(BOOL)animated { if (animated) { [UIView beginAnimations:@"hideIAdBanner" context:nil]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector (animationDidStop:finished:context:)]; } CGRect frameForTable = [self frameForIAdTable:NO]; [self.tableView setFrame:frameForTable]; CGRect frameForBanner = [[self iadBanner] frame]; frameForBanner.origin.y = self.view.frame.size.height + 1; [[self iadBanner] setFrame:frameForBanner]; showingIAdBanner = NO; if (animated) { [UIView commitAnimations]; } } Tuesday, September 28, 2010
  • 14. #protip • killall adlibd • ^ for when the simulator doesn’t seem to want to serve up ads. Tuesday, September 28, 2010
  • 15. What happens when There is no iAD? • Internationally (iAD is US only currently) • Fill rate is meh (ish). • Not available on original phone. • You’ll want a supplemental ad service. hg update Tuesday, September 28, 2010
  • 16. Mobclix • http://mobclix.com/ • Largest Mobile Ad Exchange • Advertisers Compete for eyeballs • Decent dough hg update --rev 1 Tuesday, September 28, 2010
  • 17. Adding MobClix to Core Data Books • Add the Static Library • Other Linker Flags • -all_load • -ObjC hg update Tuesday, September 28, 2010
  • 18. Adding a Banner #import "AddViewController.h" #import <iAd/iAd.h> #import "MobclixAds.h" @interface RootViewController : UIViewController <NSFetchedResultsControllerDelegate, AddViewControllerDelegate, ADBannerViewDelegate, MobclixAdViewDelegate> { ! NSFetchedResultsController *fetchedResultsController; NSManagedObjectContext *managedObjectContext;! NSManagedObjectContext *addingManagedObjectContext;! ADBannerView *iadBanner; UIView *mobAdBannerHost; MobclixAdView *mobAdBanner; @private BOOL showingIAdBanner; BOOL showingMobAdBanner; BOOL mobAdHasContent; } @property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController; @property (nonatomic, retain) NSManagedObjectContext *managedObjectContext; @property (nonatomic, retain) NSManagedObjectContext *addingManagedObjectContext; @property (nonatomic, retain) IBOutlet UITableView *tableView; @property (nonatomic, retain) ADBannerView *iadBanner; @property(nonatomic, retain)IBOutlet UIView *mobAdBannerHost; @property(nonatomic, retain)IBOutlet MobclixAdView *mobAdBanner; - (IBAction)addBook; - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath; @end Tuesday, September 28, 2010
  • 19. Adding a Banner in IB Tuesday, September 28, 2010
  • 20. MobClix Delegate Protocol // Advertisement Status Messages - (void)adViewDidFinishLoad:(MobclixAdView*)adView; { [self showMobAdBanner:YES]; mobAdHasContent = YES; } - (void)adView:(MobclixAdView*)adView didFailLoadWithError:(NSError*)error; { [self hideMobAdBanner:YES]; mobAdHasContent = NO; } // Advertisement Touchthrough Messages - (void)adViewWillTouchThrough:(MobclixAdView*)adView; { } - (void)adViewDidFinishTouchThrough:(MobclixAdView*)adView; { } //- (void)adView:(MobclixAdView*)adView didTouchCustomAdWithString: (NSString*)string; // Keeps ads from automatically taking over the app. - (BOOL)adViewCanAutoplay:(MobclixAdView*)adView; { return NO; } Tuesday, September 28, 2010
  • 21. New stuff in iAD delegate methods #pragma mark iAD Delegate // This method is invoked each time a banner loads a new advertisement. Once a banner has loaded an ad, // it will display that ad until another ad is available. The delegate might implement this method if // it wished to defer placing the banner in a view hierarchy until the banner has content to display. - (void)bannerViewDidLoadAd:(ADBannerView *)banner; { [self showIAdBanner:YES]; //give full priority to iAd and get rid of the MobClix ad [self hideMobAdBanner:YES]; [self.mobAdBanner cancelAd]; [self.mobAdBanner pauseAdAutoRefresh]; } // This method will be invoked when an error has occurred attempting to get advertisement content. // Possible error codes defined as constants in ADManager.h. - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error; { // no iAd adds, so try mobclix [self hideIAdBanner:YES]; [self.mobAdBanner resumeAdAutoRefresh]; } Tuesday, September 28, 2010
  • 22. Modifying the table view’s frame when a Mobclix ad is shown -(CGRect)frameForMobTable:(BOOL)showingBanner { CGRect frameForTable = self.view.frame; frameForTable.origin.x = frameForTable.origin.y = 0.0; if (showingBanner) { frameForTable.size.height -= ([self mobAdBannerHost].frame.size.height); } else if (showingIAdBanner) { frameForTable = [self frameForIAdTable:YES]; } return frameForTable; } Tuesday, September 28, 2010
  • 23. Showing Banner -(void)showMobAdBanner:(BOOL)animated; { if (showingMobAdBanner) { return; } [self.view addSubview:[self mobAdBannerHost]]; [self hideMobAdBanner:NO]; if (animated) { [UIView beginAnimations:@"showMobAdBanner" context:nil]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; } CGRect frameForTable = [self frameForMobTable:YES]; [self.tableView setFrame:frameForTable]; CGRect frameForBannerHost = [[self mobAdBannerHost] frame]; frameForBannerHost.origin.y = frameForTable.size.height; frameForBannerHost.origin.x = 0.; frameForBannerHost.size.width = self.view.frame.size.width; [[self mobAdBannerHost] setFrame:frameForBannerHost]; CGRect frameForBanner = [self.mobAdBanner frame]; frameForBanner.origin.x = floorf((frameForBannerHost.size.width - self.mobAdBanner.frame.size.width) * . 5); frameForBanner.origin.y = 5.; [self.mobAdBanner setFrame:frameForBanner]; showingMobAdBanner = YES; if (animated) { [UIView commitAnimations]; } } Tuesday, September 28, 2010
  • 24. Hiding Banner -(void)hideMobAdBanner:(BOOL)animated; { if (animated) { [UIView beginAnimations:@"hideMobAdBanner" context:nil]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; } CGRect frameForTable = [self frameForMobTable:NO]; [self.tableView setFrame:frameForTable]; CGRect frameForBanner = [[self mobAdBannerHost] frame]; frameForBanner.origin.y = self.view.frame.size.height + 1; [[self mobAdBannerHost] setFrame:frameForBanner]; showingMobAdBanner = NO; if (animated) { [UIView commitAnimations]; } } Tuesday, September 28, 2010
  • 25. Prettification of mobclix banners // prettify the mobclix banner a little [[mobAdBanner layer] setBorderColor:[[UIColor grayColor] CGColor]]; [mobAdBannerHost setBackgroundColor:[UIColor colorWithRed:199./255. green:206/255. blue:213/255. alpha:1.]]; CGFloat scale = 1.0; if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { scale = [[UIScreen mainScreen] scale]; } if (scale > 1.0) { //iPhone 4 looks okay with border width of one, it's sort of meh on the //lower DPI screens. [[mobAdBanner layer] setBorderWidth:1]; [[mobAdBanner layer] setCornerRadius:4]; } else { [[mobAdBanner layer] setBorderWidth:2]; [[mobAdBanner layer] setCornerRadius:6]; } [mobAdBanner setClipsToBounds:YES]; // Drop shadow below table view (this is an ugly way to do it, but it's easier // in a way given that we support 3.1.2 through 4.0 at this point. UIImage *img = [UIImage imageNamed:@"littleShadow.png"]; CGRect shadowViewFrame = CGRectMake(0, 0, mobAdBannerHost.frame.size.width, img.size.height); UIImageView *shadowView = [[UIImageView alloc] initWithFrame:shadowViewFrame]; [shadowView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; [shadowView setImage:img]; [mobAdBannerHost addSubview:shadowView]; [mobAdBannerHost bringSubviewToFront:shadowView]; [shadowView release]; Tuesday, September 28, 2010
  • 26. Rotatin’ • Mobclix ads look awful rotated to landscape • Too tall • Too Narrow • iAD ads look great in landscape • Hide mobclix no matter what in landscape Tuesday, September 28, 2010
  • 27. Rotatin’ (heh. Get it? Rotatin?) // - Ov (B err in O te OL) ide rf s ac hou to a // eO l re Ret ri dAu llow e tu ur nta toro ori rn n t t e } (i Y E S i o n a t e T n t a t nt { oI i in erf for nt ons er t in erf aceO supp fa oth ce e te a rf ceO rien orte Or r t ie h ac r eO ien tati d or nt an at t ri t en ati on = ient io he n: d ta o ti n = = UI atio (U efa II u on = I == UI nte ns nt lt er p D UI evi rfac fa ort ce r De c vi eOr eOri Or ait ie ce i Or ent enta nt ori at e ie a nt tio tion io nta n) ti at n io Lan Port on . nL ds ra an ca i ds pe t | ca R pe igh | Le t ft | ); | Tuesday, September 28, 2010
  • 28. Rotatin’ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration: (NSTimeInterval)duration { if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) { [self iadBanner].currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32; if(showingMobAdBanner) { //Admob ads look awful in landscape. They're too big. //Disable them until we can make them pretty [self hideMobAdBanner:YES]; [self.mobAdBanner cancelAd]; [self.mobAdBanner pauseAdAutoRefresh]; } } else { [self iadBanner].currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50; if(!showingIAdBanner) { [self.mobAdBanner resumeAdAutoRefresh]; if (mobAdHasContent) { [self performSelector:@selector(showMobAdBannerAnimated) withObject:nil afterDelay:duration+1]; } } } } Tuesday, September 28, 2010
  • 29. The End: Questions? Tuesday, September 28, 2010
  • 30. Attributions/References • Touchengine Framework: http:// code.google.com/p/touchengine/ • http://www.flickr.com/photos/ 71849667@N00/106241586/sizes/z/in/ photostream/ • http://www.flickr.com/photos/ thebusybrain/2632651360/ Tuesday, September 28, 2010