-[AppController window]: unrecognized selector sent to instance 0x280c24420'

bug显示问题:
最近在编译游戏工程的时候,对接了渠道的SDK,然后老是出现崩溃

Trapped uncaught exception 'NSInvalidArgumentException', reason: '-[AppController window]: unrecognized selector sent to instance 0x280c24420' 

崩溃效果图如下:


image.png

如果出现这个问题,那么首先恭喜你,不是渠道的SDK太旧了,不兼容版本,而是CP游戏工程太老了

解决方法如下:

1:游戏工程里APPcontroller.h文件要进行修改UIWindow
@interface AppController : UIResponder <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate>
{
    RootViewController    *viewController;
    id reachAbilityObj;
    // id jpushObject;
}
//根window
@property (strong, nonatomic) UIWindow *window;

修改后效果图:


image.png
2:游戏工程里APPcontroller.m文件要进行修改对应的APPwindow

下面是我的代码,大家对应的代码不同,自己相对应修改

_window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
//    window = [[UIWindow alloc] initWithFrame: winRect];

    CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [[UIScreen mainScreen] bounds]
                                     pixelFormat: (NSString*)cocos2d::GLViewImpl::_pixelFormat
                                     depthFormat: cocos2d::GLViewImpl::_depthFormat
                              preserveBackbuffer: NO
                                      sharegroup: nil
                                   multiSampling: NO
                                 numberOfSamples: 0 ];

    [eaglView setMultipleTouchEnabled:YES];
    
    // Use RootViewController manage CCEAGLView
    viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
    viewController.wantsFullScreenLayout = YES;
    viewController.view = eaglView;

image.png
3:游戏工程里main修改释放池
#import <UIKit/UIKit.h>
#import "AppController.h"

int main(int argc, char *argv[]) {
    
    @autoreleasepool {
            return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppController class]));
        }
}
image.png

再次编译,即可编译成功,就不会崩溃了!

禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容