从非主线程调用了CoreAnimation:[EAGLContext renderbufferStorage:fromDrawable:]

时间:2018-07-26 11:53:30

标签: ios objective-c uiwebview

在我的音乐应用程序中,当我尝试显示广告时(我正在使用Triton SDK),有时应用程序崩溃了,并给了我这个错误:

CoreAnimation:[EAGLContext renderbufferStorage:fromDrawable:]是在隐式事务中从非主线程调用的!请注意,如果没有显式的CATransaction或调用[CATransaction flush],这可能是不安全的。

我的广告同时包含横幅广告和音频MP3,请任何人帮助我。

以下是连续播放的流式歌曲代码:-

- (void) configureAudioStremaing {

if ([Singletone sharedSingletone].playMusic == NO) {



    NSError *setCategoryError = nil;

    NSError *activationError = nil;

    [[AVAudioSession sharedInstance] setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&activationError];



    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&setCategoryError];

    [app beginReceivingRemoteControlEvents];



}



else {



    NSError *setCategoryError = nil;

    NSError *activationError = nil;


    [[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&activationError];

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&setCategoryError];

        [app beginReceivingRemoteControlEvents];


}

当Ad显示仅在主线程中调用的所有函数时,仍调用以下函数,有时我还是遇到崩溃问题:-

//for banner view



- (void) showAdbanner {



[Singletone sharedSingletone].impressionUrlCalled = NO;

[[Singletone sharedSingletone].bannerView removeFromSuperview];



BOOL adFrameFound = NO;



for (int i = 0; i < [[Singletone sharedSingletone].ad.companionBanners count]; i++) {



    TDCompanionBanner *banner = [[Singletone sharedSingletone].ad.companionBanners objectAtIndex:i];



    if (banner.width == 300 && banner.height == 250) {

        [Singletone sharedSingletone].bannerView = [[TDBannerView alloc] initWithWidth:banner.width andHeight:banner.height];

        adFrameFound = YES;

        break;

    }

}



if (adFrameFound == NO) {

    [Singletone sharedSingletone].bannerView = [[TDBannerView alloc] initWithWidth:300 andHeight:250];

}



if (songProgressView!=nil) {

    [Singletone sharedSingletone].bannerView.translatesAutoresizingMaskIntoConstraints = NO;

    [Singletone sharedSingletone].bannerView.backgroundColor = [blackColor colorWithAlphaComponent:0.5];

    [self.view addSubview:[Singletone sharedSingletone].bannerView];



    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:[Singletone sharedSingletone].bannerView

                                                          attribute:NSLayoutAttributeTop

                                                          relatedBy:NSLayoutRelationEqual

                                                          toItem:songProgressView

                                                          attribute:NSLayoutAttributeBottom

                                                         multiplier:1.0 constant:0.0]];



    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:[Singletone sharedSingletone].bannerView

                                                          attribute:NSLayoutAttributeCenterX

                                                          relatedBy:NSLayoutRelationEqual

                                                             toItem:self.view

                                                          attribute:NSLayoutAttributeCenterX

                                                         multiplier:1.0 constant:0.0]];

    [[Singletone sharedSingletone].bannerView presentAd:[Singletone sharedSingletone].ad];

    }

}

我从crashlystics获得此报告:

http://prntscr.com/kbl58s

1 个答案:

答案 0 :(得分:0)

尝试一下

dispatch_async(dispatch_get_main_queue(), ^{

// put your code here to be call
});