mirror of
https://github.com/blanking003/cx-cocos.git
synced 2025-11-03 12:55:33 +00:00
init
This commit is contained in:
20
cx3-demo/project/cxdemo.ios/ios/AppController.h
Normal file
20
cx3-demo/project/cxdemo.ios/ios/AppController.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "ViewController.h"
|
||||
|
||||
@interface AppController : NSObject <UIApplicationDelegate>
|
||||
|
||||
@property (strong, nonatomic) ViewController* rootViewController; //cocos root view
|
||||
@property (strong, nonatomic) UINavigationController* appViewController; //app root view
|
||||
|
||||
@property (nonatomic) bool isFullScreen;
|
||||
|
||||
+ (AppController *)ins;
|
||||
|
||||
- (void) pushViewController:(UIViewController*)vc animated:(BOOL)animated;
|
||||
- (void) addView:(UIView*)view;
|
||||
- (void) removeLaunchImage;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
169
cx3-demo/project/cxdemo.ios/ios/AppController.mm
Normal file
169
cx3-demo/project/cxdemo.ios/ios/AppController.mm
Normal file
@@ -0,0 +1,169 @@
|
||||
#include "AppController.h"
|
||||
#import "ViewController.h"
|
||||
#include "platform/ios/View.h"
|
||||
|
||||
#include "service/SDKWrapper.h"
|
||||
#include "Game.h"
|
||||
|
||||
@implementation AppController
|
||||
|
||||
Game* game = nullptr;
|
||||
@synthesize window;
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
static AppController* s_sharedAppController;
|
||||
|
||||
+ (AppController*)ins
|
||||
{
|
||||
return s_sharedAppController;
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
||||
{
|
||||
s_sharedAppController = self;
|
||||
|
||||
[[SDKWrapper shared] application:application didFinishLaunchingWithOptions:launchOptions];
|
||||
CGRect bounds = [[UIScreen mainScreen] bounds];
|
||||
self.window = [[UIWindow alloc] initWithFrame: bounds];
|
||||
|
||||
/*
|
||||
appViewController: UINavigationController作为整个app的根视图
|
||||
如需打开一个全屏的原生视图控制器vc就可以这样:
|
||||
[AppController.ins pushViewController:vc animated:YES]; //默认就有右移退出功能
|
||||
|
||||
如需打开一个原生与cocos融合的界面,可以使用:
|
||||
[AppController.ins addSubview:view];
|
||||
*/
|
||||
|
||||
self.rootViewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
|
||||
// self.rootViewController.wantsFullScreenLayout = YES;
|
||||
// [self.window setRootViewController: self.rootViewController];
|
||||
|
||||
self.appViewController = [[UINavigationController alloc] initWithRootViewController:self.rootViewController];
|
||||
self.appViewController.navigationBarHidden = YES;
|
||||
self.appViewController.view = [[View alloc] initWithFrame:bounds];
|
||||
self.appViewController.view.contentScaleFactor = UIScreen.mainScreen.scale;
|
||||
self.appViewController.view.multipleTouchEnabled = false; //是否隐藏系统栏
|
||||
[self.window setRootViewController: self.appViewController];
|
||||
[self.window makeKeyAndVisible];
|
||||
|
||||
//添加图片铺满全屏,LaunchScreen.storyboard中相应设置LaunchImage的content mode缩放方式为Aspect fill,这样图片就看起来没变
|
||||
UIImageView *backgroundView = [[UIImageView alloc] initWithFrame: bounds];
|
||||
backgroundView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
backgroundView.image = [UIImage imageNamed:@"LaunchImage.png"];
|
||||
[self.appViewController.view addSubview:backgroundView];
|
||||
|
||||
//设置系统状态栏是否可见
|
||||
//无效:[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
||||
//在RootViewController.prefersStatusBarHidden方法中设置
|
||||
|
||||
/* updateViewSize方法不存在了
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(statusBarOrientationChanged:)
|
||||
name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
|
||||
*/
|
||||
|
||||
game = new Game(bounds.size.width, bounds.size.height);
|
||||
game->init();
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void) removeLaunchImage
|
||||
{
|
||||
for (UIView* subview in self.appViewController.view.subviews)
|
||||
{
|
||||
if ([subview isKindOfClass:[UIImageView class]])
|
||||
[subview removeFromSuperview];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
- (void)statusBarOrientationChanged:(NSNotification *)notification
|
||||
{
|
||||
CGRect bounds = [UIScreen mainScreen].bounds;
|
||||
float scale = [[UIScreen mainScreen] scale];
|
||||
float width = bounds.size.width * scale;
|
||||
float height = bounds.size.height * scale;
|
||||
game->updateViewSize(width, height);
|
||||
}
|
||||
*/
|
||||
|
||||
-(UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
|
||||
{
|
||||
if (self.isFullScreen)
|
||||
{
|
||||
[self setBarHideStatus:TRUE];
|
||||
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
|
||||
}
|
||||
else
|
||||
{
|
||||
[self setBarHideStatus:FALSE];
|
||||
return UIInterfaceOrientationMaskPortrait;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setBarHideStatus:(bool)status
|
||||
{
|
||||
[self.rootViewController setBarHideStatus:status];
|
||||
}
|
||||
|
||||
- (void)pushViewController:(UIViewController*)vc animated:(BOOL)animated
|
||||
{
|
||||
[self.appViewController pushViewController:vc animated:animated];
|
||||
}
|
||||
|
||||
- (void)addView:(UIView*)view
|
||||
{
|
||||
[self.appViewController.view addSubview:view];
|
||||
}
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
/*
|
||||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
*/
|
||||
[[SDKWrapper shared] applicationWillResignActive:application];
|
||||
game->onPause();
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
/*
|
||||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
*/
|
||||
[[SDKWrapper shared] applicationDidBecomeActive:application];
|
||||
game->onResume();
|
||||
}
|
||||
|
||||
- (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 shared] applicationDidEnterBackground:application];
|
||||
}
|
||||
|
||||
- (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 shared] applicationWillEnterForeground:application];
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
[[SDKWrapper shared] applicationWillTerminate:application];
|
||||
delete game;
|
||||
game = nullptr;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
[[SDKWrapper shared] applicationDidReceiveMemoryWarning:application];
|
||||
cc::EventDispatcher::dispatchMemoryWarningEvent();
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
||||
<device id="retina6_0" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<deployment version="1792" identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="fm7-M6-edp"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="uRH-d6-mvd"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="390" height="844"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" image="LaunchImage.png" id="YCC-wj-Gww" userLabel="LaunchImage">
|
||||
<rect key="frame" x="0.0" y="0.0" width="390" height="844"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
|
||||
</imageView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="50.399999999999999" y="373.15270935960592"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
<image name="LaunchImage.png" width="750" height="1334"/>
|
||||
</resources>
|
||||
</document>
|
||||
58
cx3-demo/project/cxdemo.ios/ios/Info.plist
Normal file
58
cx3-demo/project/cxdemo.ios/ios/Info.plist
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>cx3.demo</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIcons~ipad</key>
|
||||
<dict/>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>NSAppTransportSecurity</key>
|
||||
<dict>
|
||||
<key>NSAllowsArbitraryLoads</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string>需要定位的说明</string>
|
||||
<key>NSPhotoLibraryUsageDescription</key>
|
||||
<string>需要打开相册的说明</string>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIPrerenderedIcon</key>
|
||||
<true/>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<dict>
|
||||
<key>accelerometer</key>
|
||||
<true/>
|
||||
<key>opengles-1</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>UIRequiresFullScreen</key>
|
||||
<true/>
|
||||
<key>UIStatusBarHidden</key>
|
||||
<true/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
cx3-demo/project/cxdemo.ios/ios/LaunchImage.png
Normal file
BIN
cx3-demo/project/cxdemo.ios/ios/LaunchImage.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
8
cx3-demo/project/cxdemo.ios/ios/Prefix.pch
Normal file
8
cx3-demo/project/cxdemo.ios/ios/Prefix.pch
Normal file
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Prefix header for all source files of the 'HelloJavascript' target in the 'HelloJavascript' project
|
||||
//
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
||||
37
cx3-demo/project/cxdemo.ios/ios/ViewController.h
Normal file
37
cx3-demo/project/cxdemo.ios/ios/ViewController.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2013 cocos2d-x.org
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ViewController : UIViewController
|
||||
{
|
||||
bool barHideStatus;
|
||||
}
|
||||
- (void) setBarHideStatus:(bool)hide;
|
||||
- (BOOL) prefersStatusBarHidden;
|
||||
//- (void) removeLaunchImage;
|
||||
|
||||
@end
|
||||
99
cx3-demo/project/cxdemo.ios/ios/ViewController.mm
Normal file
99
cx3-demo/project/cxdemo.ios/ios/ViewController.mm
Normal file
@@ -0,0 +1,99 @@
|
||||
#import "ViewController.h"
|
||||
#include "cocos/bindings/event/EventDispatcher.h"
|
||||
#include "cocos/platform/Device.h"
|
||||
|
||||
//namespace {
|
||||
// cc::Device::Orientation _lastOrientation;
|
||||
//}
|
||||
|
||||
@interface ViewController ()
|
||||
|
||||
@end
|
||||
|
||||
@implementation ViewController
|
||||
|
||||
////blank begin
|
||||
// 下面这个执行不到了,连同removeLaunchImage改到AppController.mm去
|
||||
//- (void)viewWillAppear:(BOOL)animated
|
||||
//{
|
||||
// [super viewWillAppear:animated];
|
||||
//
|
||||
// UIImageView *backgroundView = [[UIImageView alloc] initWithFrame: bounds];
|
||||
// backgroundView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
// backgroundView.image = [UIImage imageNamed:@"LaunchImage.png"];
|
||||
// [self.view addSubview:backView];
|
||||
//}
|
||||
|
||||
//- (void) removeLaunchImage
|
||||
//{
|
||||
// for (UIView* subview in self.view.subviews)
|
||||
// {
|
||||
// if([subview isKindOfClass:[UIImageView class]])
|
||||
// [subview removeFromSuperview];
|
||||
// }
|
||||
//}
|
||||
|
||||
//禁止竖横转屏动画
|
||||
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
|
||||
{
|
||||
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
|
||||
[CATransaction begin];
|
||||
[CATransaction setDisableActions:YES];
|
||||
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context)
|
||||
{
|
||||
|
||||
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context)
|
||||
{
|
||||
[CATransaction commit];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void) setBarHideStatus:(bool)hide
|
||||
{
|
||||
self->barHideStatus = hide;
|
||||
[self setNeedsStatusBarAppearanceUpdate];
|
||||
}
|
||||
|
||||
- (BOOL) prefersStatusBarHidden
|
||||
{
|
||||
return self->barHideStatus;
|
||||
}
|
||||
|
||||
- (BOOL) prefersHomeIndicatorAutoHidden
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
/*
|
||||
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
|
||||
{
|
||||
cc::Device::Orientation orientation = _lastOrientation;
|
||||
// reference: https://developer.apple.com/documentation/uikit/uiinterfaceorientation?language=objc
|
||||
// UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
|
||||
// UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight
|
||||
switch ([UIDevice currentDevice].orientation) {
|
||||
case UIDeviceOrientationPortrait:
|
||||
orientation = cc::Device::Orientation::PORTRAIT;
|
||||
break;
|
||||
case UIDeviceOrientationLandscapeRight:
|
||||
orientation = cc::Device::Orientation::LANDSCAPE_LEFT;
|
||||
break;
|
||||
case UIDeviceOrientationPortraitUpsideDown:
|
||||
orientation = cc::Device::Orientation::PORTRAIT_UPSIDE_DOWN;
|
||||
break;
|
||||
case UIDeviceOrientationLandscapeLeft:
|
||||
orientation = cc::Device::Orientation::LANDSCAPE_RIGHT;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (_lastOrientation != orientation)
|
||||
{
|
||||
cc::EventDispatcher::dispatchOrientationChangeEvent((int) orientation);
|
||||
_lastOrientation = orientation;
|
||||
}
|
||||
}
|
||||
*/
|
||||
////blank end
|
||||
|
||||
@end
|
||||
10
cx3-demo/project/cxdemo.ios/ios/main.m
Normal file
10
cx3-demo/project/cxdemo.ios/ios/main.m
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
|
||||
[pool release];
|
||||
return retVal;
|
||||
}
|
||||
53
cx3-demo/project/cxdemo.ios/ios/service/SDKWrapper.h
Normal file
53
cx3-demo/project/cxdemo.ios/ios/service/SDKWrapper.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SDKDelegate <NSObject>
|
||||
|
||||
@optional
|
||||
- (void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application;
|
||||
- (void)applicationWillResignActive:(UIApplication *)application;
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application;
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application;
|
||||
- (void)applicationWillTerminate:(UIApplication *)application;
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application;
|
||||
|
||||
@end
|
||||
|
||||
@interface SDKWrapper : NSObject
|
||||
@property(nonatomic,strong) NSString *name;
|
||||
+ (instancetype)shared;
|
||||
- (void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application;
|
||||
- (void)applicationWillResignActive:(UIApplication *)application;
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application;
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application;
|
||||
- (void)applicationWillTerminate:(UIApplication *)application;
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
142
cx3-demo/project/cxdemo.ios/ios/service/SDKWrapper.m
Normal file
142
cx3-demo/project/cxdemo.ios/ios/service/SDKWrapper.m
Normal file
@@ -0,0 +1,142 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#import "SDKWrapper.h"
|
||||
|
||||
@interface SDKWrapper ()
|
||||
|
||||
@property (nonatomic, strong) NSArray *serviceInstances;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SDKWrapper
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Singleton
|
||||
|
||||
static SDKWrapper *mInstace = nil;
|
||||
|
||||
+ (instancetype)shared {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
mInstace = [[super allocWithZone:NULL] init];
|
||||
[mInstace initSDKWrapper];
|
||||
});
|
||||
return mInstace;
|
||||
}
|
||||
+ (id)allocWithZone:(struct _NSZone *)zone {
|
||||
return [SDKWrapper shared];
|
||||
}
|
||||
|
||||
+ (id)copyWithZone:(struct _NSZone *)zone {
|
||||
return [SDKWrapper shared];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark private methods
|
||||
- (void)initSDKWrapper {
|
||||
[self loadSDKClass];
|
||||
}
|
||||
|
||||
- (void)loadSDKClass {
|
||||
NSMutableArray *sdks = [NSMutableArray array];
|
||||
@try {
|
||||
NSString *path = [NSString stringWithFormat:@"%@/service.json", [[NSBundle mainBundle] resourcePath]];
|
||||
NSData *data = [NSData dataWithContentsOfFile:path options:NSDataReadingMappedIfSafe error:nil];
|
||||
id obj = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
||||
id dic = obj[@"serviceClasses"];
|
||||
if (dic == nil) @throw [[NSException alloc] initWithName:@"JSON Exception" reason:@"serviceClasses not found" userInfo:nil];
|
||||
for (NSString *str in dic) {
|
||||
NSString *className = [[str componentsSeparatedByString:@"."] lastObject];
|
||||
Class clazz = NSClassFromString(className);
|
||||
if (clazz == nil) @throw [[NSException alloc] initWithName:@"Cass Exception"
|
||||
reason:[NSString stringWithFormat:@"class '%@' not found", className]
|
||||
userInfo:nil];
|
||||
id sdk = [[clazz alloc] init];
|
||||
[sdks addObject:sdk];
|
||||
}
|
||||
} @catch (NSException *e) {
|
||||
}
|
||||
self.serviceInstances = [NSArray arrayWithArray:sdks];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
- (void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
for (id <SDKDelegate> sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(application:didFinishLaunchingWithOptions:)]) {
|
||||
[sdk application:application didFinishLaunchingWithOptions:launchOptions];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
for (id sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(applicationDidBecomeActive:)]) {
|
||||
[sdk applicationDidBecomeActive:application];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
for (id sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(applicationWillResignActive:)]) {
|
||||
[sdk applicationWillResignActive:application];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
for (id sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(applicationDidEnterBackground:)]) {
|
||||
[sdk applicationDidEnterBackground:application];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
for (id sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(applicationWillEnterForeground:)]) {
|
||||
[sdk applicationWillEnterForeground:application];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
for (id sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(applicationWillTerminate:)]) {
|
||||
[sdk applicationWillTerminate:application];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
for (id sdk in self.serviceInstances) {
|
||||
if ([sdk respondsToSelector:@selector(applicationDidReceiveMemoryWarning:)]) {
|
||||
[sdk applicationDidReceiveMemoryWarning:application];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user