iphone: нет отображения iad баннера в навигации HARDEST? - PullRequest
0 голосов
/ 17 октября 2011

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

- (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];
}

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

Спасибо =)

1 Ответ

1 голос
/ 20 октября 2011

Основываясь на моем ответе на код 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];

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

...