6

ユニバーサル アプリ テンプレートを作成しています。

このテンプレートは、オプションの iAd と、オプションですべての向きをサポートする必要があります。

奇妙なバグを見つけるためだけにソリューションをコーディングしました。特定の状況で、バナーをクリックできませんでした

次に、別のリビジョンを再コーディングし、すべてを整理し、ほとんどのコードを削除して、最小限のテスト ケースの失敗を明らかにしました。

https://github.com/pi-/iAdUniversalTemplate/commit/2c829d268a9452e1a054802e7ccb9cde5de17853

この新しいコードでは、window、uberview (View Controller のビュー)、および ad-banner の 3 つのビューのみです。

したがって、バナーが提供されると、バナーは適切に表示され、自動回転は正常に機能します...それぞれのフレームと境界を記録しましたが、すべてが正常です。

しかし、それはタップに反応しません (まあ、私はシミュレーターにいるのでクリックしてください)

何が間違っている可能性がありますか?プロジェクトから XIB を切り取り、コードからウィンドウとビュー コントローラーを実装する際に、何かを見逃したか、何かを前後に配線したのではないかと疑い始めています。

ジューシーなコード チャンク:

AppDelegate.m

- (BOOL) application: (UIApplication *) application 
didFinishLaunchingWithOptions: (NSDictionary *) launchOptions 
{
    NSLog(@"--> ___PROJECTNAME___AppDelegate:didFinishLaunchingWithOptions...");

    // FIXED: now entry in info.plist hides SB BEFORE launch
    [[UIApplication sharedApplication] setStatusBarHidden: (SHOW_SB ? NO : YES)];

    CGRect appFrame = [UIScreen mainScreen].applicationFrame;

    // windowRect must start at 0, 0
    // if (SHOW_SB == YES), appFrame will be '{{0, 20}, {320, 460}}'
    CGRect windowRect = CGRectMake(0, 0, appFrame.size.width, appFrame.size.height);

    self.window = [[[UIWindow alloc] initWithFrame: windowRect] autorelease];

    self.viewController = [ [ [ ___PROJECTNAME___ViewController alloc ] init ] autorelease ];

    [self.window setRootViewController: viewController];

    // triggers loadView
    [self.window makeKeyAndVisible];

    return YES;
}

iAdVC.m

- (void) loadView 
{       
    self.uberView = [[[UIView alloc] initWithFrame: [UIScreen mainScreen].applicationFrame] autorelease];
    self.uberView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.uberView.autoresizesSubviews = YES;
    self.uberView.clipsToBounds = YES;

    //UIWindow * w = self.view.window;
    //w.clipsToBounds = YES;

    [self setView: uberView];

    showingBanner = NO;
    adBannerView = nil;
    if (IADS_ENABLED)
    {
        NSString * P = ADBannerContentSizeIdentifierPortrait;
        NSString * L = ADBannerContentSizeIdentifierLandscape;

        self.adBannerView = [[[ADBannerView alloc] initWithFrame:CGRectZero] autorelease];

        self.adBannerView.delegate = self;
        self.adBannerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
        self.adBannerView.requiredContentSizeIdentifiers = [NSSet setWithObjects: P, L, nil];
        self.adBannerView.currentContentSizeIdentifier = UIInterfaceOrientationIsPortrait( self.interfaceOrientation ) ? P : L ;

        [uberView addSubview: adBannerView];
    }

    UIWindow * w = [[UIApplication sharedApplication] keyWindow];

    w.userInteractionEnabled = YES;
    self.uberView.userInteractionEnabled = YES;
    self.adBannerView.userInteractionEnabled = YES;

    w.clipsToBounds = YES;
    self.uberView.clipsToBounds = YES;
    self.adBannerView.clipsToBounds = YES;

    w.opaque = YES;
    self.uberView.opaque = YES;
    self.adBannerView.opaque = YES;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - -

#pragma mark Autorotate

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation 
{   
    return YES;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - -

- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) newOrientation 
                                 duration: (NSTimeInterval) duration
{
    bool isLandscape = UIInterfaceOrientationIsLandscape(newOrientation);
    self.adBannerView.currentContentSizeIdentifier = isLandscape ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifierPortrait ;
}


#pragma mark Banner

// - - - - - - - - - - - - - - - - - - - - - - - - - -

- (void) bannerViewDidLoadAd: (ADBannerView *) banner 
{   
    if (! showingBanner)
    {
        showingBanner = YES;
        // ... (optionally animate in)
    }
}


// - - - - - - - - - - - - - - - - - - - - - - - - - -

- (void) bannerView: (ADBannerView *) banner 
didFailToReceiveAdWithError: (NSError *) error
{
    NSLog(@"FAIL");

    if (showingBanner)
    {
        showingBanner = NO;
        // ... (optionally animate out)
    }
}

// - - - - - - - - - - - - - - - - - - - - - - - - - -

-(BOOL) bannerViewActionShouldBegin: (ADBannerView *) banner 
               willLeaveApplication: (BOOL) willLeave
{
    return YES; // doesnt get hit
}

// = = = = = = = = = = = = = = = = = = = = = = = = = = 
4

3 に答える 3

8

これはブラットのバグの雌犬でした

2 つの ITS ヘルプライン インシデントのうちの 1 つを使用することになり、1 週間丸ごと無駄になりました。

uberView の backgroundColor プロパティを nil 以外の任意の値に設定すると、問題が解決します。

これは、XIB マジックによって行われることの 1 つです。

XIB をコードに変換する nib2objc というツールがあります。Apple のデフォルト XIB に含まれているものを実際に確認し、手動で実装できていないものを確認するために、自分でデバッグする必要がある場合、これが次のステップでした。

しかし、これは UIKit のバグです。Apple の ITS 担当者は、そのようなことをファイルするように私に言いました。

于 2011-04-04T05:17:35.350 に答える
2

私も同じ問題を抱えていましたが、スーパービューの背景に [UIColor clearColor] を使用しても解決しませんでした。(これは iOS 4.3.3 上にあります)

すべてのスーパービューには、不透明なカラー セットが必要です。

于 2011-06-01T17:03:21.467 に答える
0

追加することを確認します

self.window.backgroundColor = [UIColor whiteColor];

didFinishLaunchingWithOptions関数では完全に機能します。

于 2012-04-25T21:28:32.270 に答える