仓库中添加内置的demo

This commit is contained in:
gongxh
2025-07-28 14:26:19 +08:00
parent 43446f031d
commit 65be0498cc
414 changed files with 14456 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
/****************************************************************************
Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You
shall not use Cocos Creator software for developing other software or tools
that's used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to
you.
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.
****************************************************************************/
#pragma once
#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

View 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