1

在崩溃之前,我在 4.3 模拟器上收到此错误。它在 5.1 上运行良好。当我完全取出 iAd 代码时,它在 4.3 上运行良好。应用程序是在 5.1 上使用 arc 设计的。

[LinkViewController bannerView:didFailToReceiveAdWithError:]: message sent to deallocated instance

我在所有异常上都设置了断点。我已经启用了 NSZombie、NSDebug 和 NSMallocStackLogging 来运行它。我怎样才能找到被释放的东西?

这是线程:

Thread 1, Queue : com.apple.main-thread
#0  0x0018e657 in ___forwarding___ ()
#1  0x0018e522 in _CF_forwarding_prep_0 ()
#2  0x005ef0f0 in -[ADBannerView _sanitizeAndForwardErrorToDelegate:] ()
#3  0x0018dc7d in __invoking___ ()
#4  0x0018db51 in -[NSInvocation invoke] ()
#5  0x0018ea04 in ___forwarding___ ()
#6  0x0018e522 in _CF_forwarding_prep_0 ()
#7  0x005f59f9 in -[ADDistributedMessagingCenter messagePort:receivedMessage:withData:] ()
#8  0x005f6012 in ADMessagePortCallBack ()
#9  0x001d4f4c in __CFMessagePortPerform ()
#10 0x001fe944 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#11 0x0015ecf7 in __CFRunLoopDoSource1 ()
#12 0x0015bf83 in __CFRunLoopRun ()
#13 0x0015b840 in CFRunLoopRunSpecific ()
#14 0x0015b761 in CFRunLoopRunInMode ()
#15 0x020331c4 in GSEventRunModal ()
#16 0x02033289 in GSEventRun ()
#17 0x009bbc93 in UIApplicationMain ()
#18 0x00003125 in main at /Developer/Cecilia's Programs/Story/Story/main.m:17
#19 0x000029b5 in start ()

这是我的代码:

- (void) createAdBannerView
{
    Class classAdBannerView = NSClassFromString (@"ADBannerView"); 
    if (classAdBannerView != nil)
    {
        self.adBannerView = [[classAdBannerView alloc] initWithFrame:CGRectZero];
        [_adBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects: ADBannerContentSizeIdentifierLandscape, nil]];
        [_adBannerView setCurrentContentSizeIdentifier: ADBannerContentSizeIdentifierLandscape];
    }

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)     
    {
        [_adBannerView setFrame:CGRectOffset([_adBannerView frame], 0, -32)];
    }       

    else 
    {
        [_adBannerView setFrame:CGRectOffset([_adBannerView frame], 0, -66)];
    }

    [_adBannerView setDelegate:self];
    [self.view addSubview:_adBannerView];  
}

- (void)fixupAdView
{
    if (_adBannerView != nil) 
    {        
        [_adBannerView setCurrentContentSizeIdentifier: ADBannerContentSizeIdentifierLandscape];
        [UIView beginAnimations:@"fixupViews" context:nil];
        if (_adBannerViewIsVisible) 
        {
            CGRect adBannerViewFrame = [_adBannerView frame];
            adBannerViewFrame.origin.x = 0;
            adBannerViewFrame.origin.y = 20;
            [_adBannerView setFrame:adBannerViewFrame];
            CGRect iAdViewFrame = _iAdView.frame;

            if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
            {
                iAdViewFrame.origin.y = 20;
                iAdViewFrame.size.height = self.view.frame.size.height - 32;
                _iAdView.frame = iAdViewFrame;
            }

            else
            {
                iAdViewFrame.origin.y = 20;
                iAdViewFrame.size.height = self.view.frame.size.height - 66;
                _iAdView.frame = iAdViewFrame;
            }
        }

        else
        {
            CGRect adBannerViewFrame = [_adBannerView frame];
            adBannerViewFrame.origin.x = 0;

            if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
            {
                adBannerViewFrame.origin.y = -52;
            }

            else
            {
                adBannerViewFrame.origin.y = -86;
            }

            [_adBannerView setFrame:adBannerViewFrame];
            CGRect iAdViewFrame = _iAdView.frame;
            iAdViewFrame.origin.y = 0;
            iAdViewFrame.size.height = self.view.frame.size.height;
            _iAdView.frame = iAdViewFrame; 
            }

        [UIView commitAnimations];
    }
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner 
{   
    if (!_adBannerViewIsVisible)
    {                
        _adBannerViewIsVisible = YES;
        [self fixupAdView];
    }
 }

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{   
    if (_adBannerViewIsVisible)
    {       
         _adBannerViewIsVisible = NO;
        [self fixupAdView];
    }
}

- (void) viewWillAppear:(BOOL)animated
{
    [self fixupAdView];
}

- (void)viewDidLoad
{
[self createAdBannerView];
}

提前感谢您能给我的任何帮助!

4

0 回答 0