iphone:基于最难的导航中不显示 iad 横幅?

发布于 2024-12-10 10:11:22 字数 3455 浏览 0 评论 0原文

我已经浏览了 bees4honey、iadsuites 示例(全部三个)以及每个人最喜欢的 raywenderlich 导师。他们都没有帮我展示横幅。我没有大多数导师通常提到的 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];
}

示例如果有人可以帮助我找出我需要在项目中放置“苹果批准的代码”以显示横幅的确切位置,那就太好了。

谢谢=)

I already went through bees4honey, iadsuites samples (all three of them), and everyone's favorite raywenderlich tutor. None of them helped me display the banner. I dont have any xib which most of the tutors usually mention. This is my delegate code

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

I have HomeViewController(for navigation and methods) and HomeView (for the subviews).
sample of my 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

sample code from 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];
}

it would be great if someone can help me find out where exactly I need to put the "apple approved code" in my project to display the banner.

Thanks =)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七度光 2024-12-17 10:11:22

根据我的答案 ADBannerNavigation 中 Apple 的代码,您可以将其精简为检查广告显示的必要部分。我的意思是:

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 的代码中添加即可但将原点更改为可见的东西(苹果建议将其放置在视图之外,然后将其动画化到视图中,这很好,但第一步检查它是否在这里):

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

此时您已经添加了视图中的横幅,因此即使未实现委托方法,它也应该出现。
一旦完成这项工作,您就可以详细说明管理动画的委托方法。

Basing my answser on Apple's code in ADBannerNavigation, you could strip it down to the essential to check the ad appears. I mean :

1) take the code as it is in the app delegate, defining an iAd and a SharedADBannerView, and in 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) the instance therefore exists when your controller comes into view, you could just add in viewDidAppear Apple's code but change the origin to something visible (Apple suggest to place it out of view and then animate it into view, which is fine but in a first step check it is here) :

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

At this point you've added the banner in view so it should appear even if the delegate methods are not implemented.
Once you make this work you can elaborate on the delegate methods to manage the animation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文