iphone: не отображать баннер iad в навигационной системе СЛОЖНЕЕ ВСЕГО?

#iphone #navigation #iad #banner

#iPhone #навигация #iad #баннер

Вопрос:

Я уже просмотрел образцы bees4honey, iadsuites (все три из них) и всеми любимого raywenderlich tutor. Ни один из них не помог мне отобразить баннер. У меня нет xib, о котором обычно упоминают большинство преподавателей. Это мой код делегата

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after app launch
    // Create the window object
    UIWindow *localWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Assign the localWindow to the AppDelegate window, then release the local window
    self.window = localWindow;
    [localWindow release];

    // Setup the first view controller
    HomeViewController *homeViewController = [[HomeViewController alloc] init];

    // Initialise the navigation controller with the first view controller as its root view controller
    navigationController = [[UINavigationController alloc] initWithRootViewController:homeViewController];

        [navigationController.navigationBar setBarStyle:UIBarStyleBlack];

    [navigationController.navigationBar setTintColor:[UIColor blackColor]];
            //[navigationController setNavigationBarHidden:YES];


        [HomeViewController release];



    // Add the navigation controller as a subview of our window
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];

    return YES;
}
  

У меня есть HomeViewController (для навигации и методов) и HomeView (для вложенных представлений).
пример моего homeviewcontroller.m

 #pragma mark -
#pragma mark Initialisation

- (id)init {
    self = [super init];
    if (self) {
        self.title = @"Home";

        UIView *homeView = [[HomeView alloc] initWithParentViewController:self];
        self.view = homeView;

        [homeView release];
    }
    return self;
}

#pragma mark -
#pragma mark Action Methods

- (void)button3Action {...........rest of code below as method for the button located in HomeView.m
  

пример кода из Homeview.m

 // Private Methods
@interface HomeView()
- (void)loadButton3;

@end

@implementation HomeView

#pragma mark -
#pragma mark Initialization

- (id)initWithParentViewController:(HomeViewController *)parent {
    if ((self = [super init])) {
        // Update this to initialize the view with your own frame size
        // The design has specified that there is to be no status bar present,
        // please hide the status bar.
        [self setFrame:CGRectMake(0, 0, 320, 480)];

        // Assign the reference back to the parent view controller
        refParentViewController = parent;

        // Set the view background color
        [self setBackgroundColor:[UIColor lightGrayColor]];

        // Load subview methods
        [self loadButton3];

    }
    return self;
}

#pragma mark -
#pragma mark Load Subview Methods

- (void)loadButton3 {
    UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button3 setTitle:@"Is that counterfeit product?" forState:UIControlStateNormal];
    [button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button3 setBackgroundColor:[UIColor clearColor]];
                button3.titleLabel.font = [UIFont fontWithName:@"MarkerFelt-Thin" size:25];
    [button3 addTarget:refParentViewController action:@selector(button3Action) forControlEvents:UIControlEventTouchUpInside];
    [button3 setFrame:CGRectMake(5, 375, 310, 31)];
    [self addSubview:button3];
}
  

было бы здорово, если бы кто-нибудь мог помочь мне выяснить, где именно мне нужно поместить «одобренный apple код» в мой проект для отображения баннера.

Спасибо =)

Ответ №1:

Основываясь на моем ответе на коде Apple в ADBannerNavigation, вы можете сократить его до необходимого, чтобы проверить, появляется ли реклама. Я имею в виду :

1) возьмите код таким, какой он есть в делегате приложения, определяя iAd и SharedADBannerView, а также в appdelegate.m :

 adBanner = [[ADBannerView alloc] initWithFrame:CGRectZero];

// Set the autoresizing mask so that the banner is pinned to the bottom
self.adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;

// Since we support all orientations, support portrait and landscape content sizes.
// If you only supported landscape or portrait, you could remove the other from this set
self.adBanner.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];
  

2) следовательно, экземпляр существует, когда ваш контроллер появляется в поле зрения, вы можете просто добавить в viewDidAppear код Apple, но изменить источник на что-то видимое (Apple предлагает убрать его из поля зрения, а затем анимировать его в поле зрения, что нормально, но на первом шаге проверьте, что он здесь) :

     ADBannerView *adBanner = SharedAdBannerView;

// Depending on our orientation when this method is called, we set our initial content size.
// If you only support portrait or landscape orientations, then you can remove this check and
// select either ADBannerContentSizeIdentifierPortrait (if portrait only) or ADBannerContentSizeIdentifierLandscape (if landscape only).
NSString *contentSize;
contentSize = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifierLandscape;


// Calculate the intial location for the banner.
// We want this banner to be at the bottom of the view controller, but placed
// offscreen to ensure that the user won't see the banner until its ready.
// We'll be informed when we have an ad to show because -bannerViewDidLoadAd: will be called.
CGRect frame;
frame.size = [ADBannerView sizeFromBannerContentSizeIdentifier:contentSize];
frame.origin = CGPointMake(0.0f, 100)); // CHANGE TO APPLE'S CODE

// Now set the banner view's frame
adBanner.frame = frame;

// Set the delegate to self, so that we are notified of ad responses.
adBanner.delegate = self;

// Set the autoresizing mask so that the banner is pinned to the bottom
adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;

// Since we support all orientations in this view controller, support portrait and landscape content sizes.
// If you only supported landscape or portrait, you could remove the other from this set
adBanner.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];

// At this point the ad banner is now be visible and looking for an ad.
[self.view addSubview:adBanner];
  

На этом этапе вы добавили баннер в поле зрения, поэтому он должен отображаться, даже если методы делегирования не реализованы.
После того, как вы выполните эту работу, вы можете уточнить методы делегирования для управления анимацией.