cocoscreator打包原生ios13锁屏切回来黑屏

/ 默认分类 / 没有评论 / 3200浏览

1、修改cocos2dlibs工程下platform->ios->CCEGALview-ios.mm文件 在swapBuffer方法中添加

  if ([EAGLContext currentContext] != _context) {
        if (![EAGLContext setCurrentContext:_context]) {
            NSLog(@"can not set current context");
        }
    }

2、 在.h文件中添加变量

    BOOL                    _isBackground;

在该文件中添加方法

-(void) setIsBackground:(BOOL) flag
{
_isBackground = flag;
}

在layoutSubviews方法中判断

  if(_isBackground){
    return;
    }

在前后台方法中添加

- (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.
     */
    [[SDKWrapper getInstance] applicationDidEnterBackground:application];
    app->applicationDidEnterBackground();
//     [[TongJi getInstance]houtai];
    NSLog(@"launcing......houtai1111111");

    auto glview = (__bridge CCEAGLView *)cocos2d::Application::getInstance()->getView();
    [glview setIsBackground:YES];
    
}

- (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.
     */
    [[SDKWrapper getInstance] applicationWillEnterForeground:application];
    app->applicationWillEnterForeground();
//    [[TongJi getInstance]qiantai];
    NSLog(@"launcing......qiantai");
    auto glview = (__bridge CCEAGLView *)cocos2d::Application::getInstance()->getView();
    [glview setIsBackground:NO];
}

creator官方修改

 UIApplicationState state = [[UIApplication sharedApplication] applicationState];
    if (state == UIApplicationStateBackground)

https://github.com/cocos-creator/cocos2d-x-lite/pull/1918