IOS接入今日头条广告SDK后,竟然......

如题(问题可复现)

1、IOS接入今日头条广告SDK;

2、播放了今日头条的某些可试玩激励视频广告(例如:98k消灭病毒的广告,该广告为可试玩广告);

3、导致自己的游戏不再渲染,但触摸事件等都等能触发;

@panda 不知是否算creator(或者说头条sdk) 关于 OpenGLES 的设计上的缺陷或bug,
                以及是否有解决方案…

提供信息如下:

CoreAnimation: [EAGLContext renderbufferStorage:fromDrawable:] was called from a non-main thread in an implicit transaction! Note that this may be unsafe without an explicit CATransaction or a call to [CATransaction flush]


Jare 人肉更新:
根据楼下 darklosy 的回复:

这个是头条广告拉取到试玩广告导致的,普通广告没问题,普通广告是看完关闭就回到游戏,试玩广告是看完视频后,有个点击试玩界面,关掉试玩界面后,就ui卡死。临时解决方法是不要拉起试玩广告,广告申请时应该可以设置的

并且经过了小伙伴的确认,目前可玩广告确实存在这样的问题。另外我们也收到过关于穿山甲可玩广告会引起内存泄露的问题,欢迎大家提供进一步协助,谢谢。

请问楼主解决了吗,我也是接入头条sdk视频遇到这个问题,卡了很久

@panda

这样试试,不要在广告的回掉里直接去调用JS层代码,你可以在OC层把回调的状态保存起来,等游戏恢复了,主动去抓取OC层的数据。

我试试

但是这里出现一个问题,穿山甲的广告幕布被吊起时游戏逻辑还在进行
我这边写了一个处理在ios视频加载成功的时候用 cc.game.pause();
在关闭的时候回调js cc.game.resume();
控制游戏的暂停
所以我游戏恢复需要怎么判定

我不知道如何,判定游戏恢复.

我试了一下,不回调js 什么操作都没。
再我关闭视频的时候也卡死
我再想是不是ios播放视频的时候相机渲染广告再回游戏主逻辑的时候没有渲染

这样改试试

  • (void)applicationDidEnterBackground:(UIApplication )application {
    /

    Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
    */
    [self stopIntervalResumeCocos2dx];
    cocos2d::Application::getInstance()->applicationDidEnterBackground();
    [CAAgent onPause];
    }

  • (void)applicationWillEnterForeground:(UIApplication )application {
    /

    Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
    /
    auto glview = (__bridge CCEAGLView
    )(Director::getInstance()->getOpenGLView()->getEAGLView());
    auto currentView = [[[[UIApplication sharedApplication] keyWindow] subviews] lastObject];
    if (glview == currentView) {
    cocos2d::Application::getInstance()->applicationWillEnterForeground();
    }else{
    [self startIntervalResumeCocos2dx];
    }
    [CAAgent onResume];
    }

-(void) startIntervalResumeCocos2dx
{
if(_resumeTimer == nil){
_resumeTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(onTimerResumeCocos2dx:) userInfo:nil repeats:YES];
}
}

-(void) stopIntervalResumeCocos2dx
{
if(_resumeTimer != nil){
[_resumeTimer invalidate];
_resumeTimer = nil;
}
}

-(void) onTimerResumeCocos2dx:(NSTimer )timer
{
auto glview = (__bridge CCEAGLView
)(Director::getInstance()->getOpenGLView()->getEAGLView());
auto currentView = [[[[UIApplication sharedApplication] keyWindow] subviews] lastObject];
if (glview == currentView) {
[self stopIntervalResumeCocos2dx];
cocos2d::Application::getInstance()->applicationWillEnterForeground();
}else{
NSLog(@“当前最顶层不是cocos2dx!”);
}
}

[CAAgent onPause]
这个需要 引入什么还是先声明声明

就是重写了AppController.mm applicationDidEnterBackground和applicationWillEnterForeground,之前应该有这个函数吧

方便加个qq嘛
418079313

之前 applicationDidEnterBackground 没有这个函数么,没有就别加

这个方法是为了解决当applicationWillEnterForeground glview != currentView 然后引擎就不会恢复,然后我启动了一个定时器其检测最上层view==glview时手动调用applicationDidEnterBackground 恢复游戏

我回调中什么都没写 依然会黑屏

有这个函数

这个函数开头加一句[self stopIntervalResumeCocos2dx];

然后applicationWillEnterForeground
if (glview == currentView) {
cocos2d::Application::getInstance()->applicationWillEnterForeground();
}
改为:
if (glview == currentView) {
cocos2d::Application::getInstance()->applicationWillEnterForeground();
}else{
[self startIntervalResumeCocos2dx];
}

我觉得我是少了点儿啥吧