ios sdk中调用的对外接口方法

//
//  QiPaiSDKManager.m
//  libcocos2d Mac
//
//  Created by ios_001 on 2018/8/20.
//

#import "QiPaiSDKManager.h"

#import "cocos2d.h"
#import "AppDelegate.h"
#import "RootViewController.h"
#import "platform/ios/CCEAGLView-ios.h"

#ifdef CC_FIX_ARTIFACTS_BY_STRECHING_TEXEL_TMX
#include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
#else
#include "scripting/js-bindings/manual/ScriptingCore.h"
#endif
#ifndef HAVE_INSPECTOR
#include "ScriptingCore.h"
#endif

//#import "cocos-analytics/CAAgent.h"

@interface QiPaiSDKManager()

//@synthesize window;
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIImageView *bgImageView;
@property (strong, nonatomic) NSString *userID;
@property (nonatomic) int gameID;
@property (nonatomic) BOOL isNormalExitGame;
@end

using namespace cocos2d;

Application* app = nullptr;

@implementation QiPaiSDKManager
// cocos2d application instance
//static AppDelegate* s_sharedApplication = nullptr;

+ (QiPaiSDKManager *)sharedManager {
   static QiPaiSDKManager *_sharedManager = nil;
   
   static dispatch_once_t onceToken;
   dispatch_once(&onceToken, ^{
       _sharedManager = [[self alloc] init];
   });
   
   return _sharedManager;
}

-(void)startAPPLaunchConfigWithWindow:(UIWindow *)window userID:(NSString *) userID gameID:(NSString *) gameID
{
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationUnknown] forKey:@"orientation"];
            [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeRight] forKey:@"orientation"];
     _isNormalExitGame = NO;
    self.userID = userID;
    self.gameID = [gameID intValue];
//    if(_viewController && _viewController.view.hidden){
    if(self.window && self.window.hidden){
        self.bgImageView.hidden = NO;
        app->applicationWillEnterForeground();
        se::ScriptEngine::getInstance()->evalString("switchScene('loading')");
        _viewController.view.hidden = NO;
        self.window.hidden = NO;
        return;
    }
      
   // Add the view controller's view to the window and display.
   float scale = [[UIScreen mainScreen] scale];
   CGRect bounds = [[UIScreen mainScreen] bounds];
//   window = [[UIWindow alloc] initWithFrame: bounds];
    self.window = window;
   
   // cocos2d application instance
   app = new AppDelegate(bounds.size.width * scale, bounds.size.height * scale);
   app->setMultitouch(true);
    
   
   // Use RootViewController to manage CCEAGLView
   _viewController = [[RootViewController alloc]init];
#ifdef NSFoundationVersionNumber_iOS_7_0
   _viewController.automaticallyAdjustsScrollViewInsets = NO;
   _viewController.extendedLayoutIncludesOpaqueBars = NO;
   _viewController.edgesForExtendedLayout = UIRectEdgeAll;
    
    
    self.bgImageView =[[UIImageView alloc]init];
    [_bgImageView setImage:[UIImage imageNamed:@"bg.png"]];
        //根据需求添加约束最好
        _bgImageView.frame = [[UIScreen mainScreen] bounds];
        _bgImageView.backgroundColor=[UIColor greenColor];
        [_viewController.view addSubview:_bgImageView];
//    NSLog(@"_viewController.prefersStatusBarHidden ====%@",_viewController.prefersStatusBarHidden);

#else
   _viewController.wantsFullScreenLayout = YES;
#endif
   
//   UINavigationController *rootNavigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
   
   ///*
    // Set RootViewController to window
    if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
    {
        // warning: addSubView doesn't work on iOS6
        [window addSubview: _viewController.view];
    }
    else
    {
        // use this method on ios6
        [window setRootViewController:_viewController];
    }
    NSLog(@"[[UIDevice currentDevice].systemVersion floatValue]===%f",[[UIDevice currentDevice].systemVersion floatValue]);
    //*/
   [window makeKeyAndVisible];
   [[UIApplication sharedApplication] setStatusBarHidden:YES];
    
   //run the cocos2d-x game scene
   app->start();
}

-(void)startAPPLaunchInfoConfigWithWindow:(UIWindow *)window
{
   self.window = window;
   
   // Add the view controller's view to the window and display.
   float scale = [[UIScreen mainScreen] scale];
   CGRect bounds = [[UIScreen mainScreen] bounds];
   //window = [[UIWindow alloc] initWithFrame: bounds];
   
   // cocos2d application instance
   app = new AppDelegate(bounds.size.width * scale, bounds.size.height * scale);
   app->setMultitouch(true);
   
   // Use RootViewController to manage CCEAGLView
   _viewController = [[RootViewController alloc]init];
#ifdef NSFoundationVersionNumber_iOS_7_0
   _viewController.automaticallyAdjustsScrollViewInsets = NO;
   _viewController.extendedLayoutIncludesOpaqueBars = NO;
   _viewController.edgesForExtendedLayout = UIRectEdgeAll;
#else
   _viewController.wantsFullScreenLayout = YES;
#endif
   /*
   // Set RootViewController to window
   if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
   {
       // warning: addSubView doesn't work on iOS6
       [window addSubview: _viewController.view];
   }
   else
   {
       // use this method on ios6
       [window setRootViewController:_viewController];
   }
   */
   
   //[window makeKeyAndVisible];
   
   //run the cocos2d-x game scene
   app->start();
}

-(void)enterCocosRootViewController
{
    NSLog(@"QiPaiSDKManager enterCocosRootViewController");
   UINavigationController *rootNavigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
   
   // Set RootViewController to window
   if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
   {
       // warning: addSubView doesn't work on iOS6
       [self.window addSubview: _viewController.view];
   }
   else
   {
       // use this method on ios6
       [self.window setRootViewController:_viewController];
//       [_window setRootViewController:rootNavigationController];
   }
   
   [self.window makeKeyAndVisible];
}

-(void)applicationWillResignActive
{
   NSLog(@"QiPaiSDKManager applicationWillResignActive");
}

-(void)applicationDidBecomeActive
{
   NSLog(@"QiPaiSDKManager applicationDidBecomeActive");
}

-(void)applicationDidEnterBackground
{
   app->applicationDidEnterBackground();
}

-(void)applicationWillEnterForeground
{
   
   app->applicationWillEnterForeground();
}

-(void)applicationWillTerminate
{
   
   delete app;
   app = nil;
}

-(void)pushViewController:(UIViewController *)viewController
{
   [_viewController.navigationController pushViewController:viewController animated:YES];
}

#pragma mark Call JS

-(void)runJS:(NSString *) js
{
   se::ScriptEngine::getInstance()->evalString([js UTF8String]);
}

#pragma mark C++ Call Native

-(void)exceptionCallbackLocation:(NSString *) location message:(NSString *) message stack:(NSString *) stack
{
   
   NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:3];
   [dic setObject:location?location:@"" forKey:@"location"];
   [dic setObject:message?message:@"" forKey:@"message"];
   [dic setObject:stack?stack:@"" forKey:@"stack"];
    
   [[NSNotificationCenter defaultCenter] postNotificationName:EXCEPTIONNOTIFICATION object:dic userInfo:nil];
}

+ (NSInteger)SDKVersion
{
    NSLog(@"当前版号2");
    return 1;
}
+ (int)getEnterGameId
{
    NSLog(@"当前gameID=%d",[QiPaiSDKManager sharedManager].gameID);
    return [QiPaiSDKManager sharedManager].gameID;
}
+ (NSString*)getEnterUserId
{


    NSLog(@"当前userID=%@",[QiPaiSDKManager sharedManager].userID);
    return [QiPaiSDKManager sharedManager].userID;
}
+ (void)HideLoading
{
    [QiPaiSDKManager sharedManager].bgImageView.hidden = YES;
    NSLog(@"隐藏loading");
}
/*
 是否正常退出的游戏
 */
+ (Boolean)IsNormalExitGame
{
    NSLog(@"isNormalExitGame==%d",[QiPaiSDKManager sharedManager].isNormalExitGame);
    return [QiPaiSDKManager sharedManager].isNormalExitGame;
}

+(void)apkFinish
{
    [QiPaiSDKManager sharedManager].isNormalExitGame = YES;
//    [QiPaiSDKManager sharedManager].viewController.view.hidden = YES;
    [QiPaiSDKManager sharedManager].window.hidden = YES;
//    se::ScriptEngine::getInstance()->evalString("manualHideGame()");
    [[QiPaiSDKManager sharedManager] endGame];
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationUnknown] forKey:@"orientation"];
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"];
    NSString *s = @"NitificationCallback exit game";
    [[NSNotificationCenter defaultCenter]
        postNotificationName:@"QiPaiExitGame"
                      object:s];
    NSLog(@"正常退出游戏,返回主程序APP");
}
-(void)endGame
{
    app->applicationDidEnterBackground();
}
#pragma mark -只支持横屏
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window
{
//return UIInterfaceOrientationMaskLandscape : UIInterfaceOrientationMaskAll;
    return UIInterfaceOrientationMaskLandscape;
}
BOOL isPhone(void)
{
    return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone;
}
+(void)QiPaiLog:(NSString *) log
{
    NSLog(@"%@",log);
}
@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

游鱼_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值