网站首页
IOS打包ipa包与js交互动作
发布时间:2020-07-02 11:19查看次数:6719
IOS打包ipa包与js交互动作
主要交换动作 就是视图隐藏于视图展示,通知js语言进行交换
#import "ViewController.h"
@implementation ViewController
static ViewController* g_pIOSMainViewController = nil;
//------------------------------------------------------------------------------
+(ViewController*)GetIOSViewController
{
return g_pIOSMainViewController;
}
//------------------------------------------------------------------------------
-(id)init
{
self = [super init];
if( self != nil )
{
g_pIOSMainViewController = self;
return self;
}
return Nil;
}
//------------------------------------------------------------------------------
- (void)viewDidLoad
{
[super viewDidLoad];
//保持屏幕常亮,可以通过脚本设置
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
self->m_pGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
if (self->m_pGLContext)
{
NSLog(@"iOS OpenGL ES 3.0 context created");
}
else
{
self->m_pGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (self->m_pGLContext)
{
NSLog(@"iOS OpenGL ES 2.0 context created");
}
else
{
NSLog(@"iOS OpenGL ES 2.0 context created failed");
}
}
m_pGLKView = (GLKView *)self.view;
m_pGLKView.context = self->m_pGLContext;
m_pGLKView.drawableDepthFormat = GLKViewDrawableDepthFormat24;
m_pGLKView.drawableStencilFormat = GLKViewDrawableStencilFormat8;
[EAGLContext setCurrentContext:self->m_pGLContext];
self.preferredFramesPerSecond = 10000;
//conchRuntime 初始化ConchRuntime引擎
m_pConchRuntime = [[conchRuntime alloc]initWithView:m_pGLKView EAGLContext:m_pGLContext downloadThreadNum:3];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doSomethingWhenApplicationWillResignActive) name:UIApplicationWillResignActiveNotification object:nil]; //监听是否触发home键挂起程序.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doSomethingWhenApplicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil]; //监听是否重新进入程序.
}
- (void)doSomethingWhenApplicationWillResignActive{
NSLog(@"程序挂起了。8888");
[[conchRuntime GetIOSConchRuntime]runJS:@"platform.hideGame()"];
//do u want to do
}
- (void)doSomethingWhenApplicationDidBecomeActive{
NSLog(@"程序重新激活。8888");
[[conchRuntime GetIOSConchRuntime]runJS:@"platform.showGame()"];
//do u want to do
}
//------------------------------------------------------------------------------
- (void)dealloc
{
[self tearDownGL];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[conchRuntime alloc]runJS:@"platform.closeGame()"];
if ( [EAGLContext currentContext] == self->m_pGLContext )
{
[EAGLContext setCurrentContext:nil];
}
}
//------------------------------------------------------------------------------
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
//conchRuntime 内存警告的时候的处理
[m_pConchRuntime didReceiveMemoryWarning];
}
//------------------------------------------------------------------------------
- (void)tearDownGL
{
[EAGLContext setCurrentContext:self->m_pGLContext];
}
//------------------------------------------------------------------------------
- (void)update
{
}
//------------------------------------------------------------------------------
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
//conchRuntime renderFrame
[m_pConchRuntime renderFrame];
}
//-------------------------------------------------------------------------------
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//conchRuntime touch
[m_pConchRuntime touchesBegan:touches withEvent:event];
}
//-------------------------------------------------------------------------------
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//conchRuntime touch
[m_pConchRuntime touchesMoved:touches withEvent:event];
}
//-------------------------------------------------------------------------------
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//conchRuntime touch
[m_pConchRuntime touchesEnded:touches withEvent:event];
}
//-------------------------------------------------------------------------------
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
//conchRuntime touch
[m_pConchRuntime touchesCancelled:touches withEvent:event];
}
//-------------------------------------------------------------------------------
-(NSUInteger)supportedInterfaceOrientations
{
/*
UIInterfaceOrientationMaskPortrait, ===2
UIInterfaceOrientationMaskPortraitUpsideDown, ===4
UIInterfaceOrientationMaskLandscapeLeft, ===8
UIInterfaceOrientationMaskLandscapeRight, ===16
*/
return [conchConfig GetInstance]->m_nOrientationType;
}
//-------------------------------------------------------------------------------
- (BOOL)shouldAutorotate
{
return YES;//支持转屏
}
@end关键字词:javascript##