2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2023-06-11 13:08:08 +08:00
|
|
|
#import "Application.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2023-06-11 13:08:08 +08:00
|
|
|
#import "math/Math.h"
|
|
|
|
#import "platform/ios/DirectorCaller-ios.h"
|
|
|
|
#import "base/Utils.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
Application* Application::sm_pSharedApplication = nullptr;
|
|
|
|
|
|
|
|
Application::Application()
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_ASSERT(!sm_pSharedApplication);
|
2019-11-23 20:27:39 +08:00
|
|
|
sm_pSharedApplication = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Application::~Application()
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_ASSERT(this == sm_pSharedApplication);
|
2019-11-23 20:27:39 +08:00
|
|
|
sm_pSharedApplication = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Application::run()
|
|
|
|
{
|
|
|
|
if (applicationDidFinishLaunching())
|
|
|
|
{
|
|
|
|
[[CCDirectorCaller sharedDirectorCaller] startMainLoop];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-30 21:04:00 +08:00
|
|
|
void Application::setAnimationInterval(float interval)
|
|
|
|
{
|
|
|
|
[[CCDirectorCaller sharedDirectorCaller] setAnimationInterval:interval];
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// static member function
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
Application* Application::getInstance()
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_ASSERT(sm_pSharedApplication);
|
2019-11-23 20:27:39 +08:00
|
|
|
return sm_pSharedApplication;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
const char* Application::getCurrentLanguageCode()
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
static char code[3] = {0};
|
|
|
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSArray* languages = [defaults objectForKey:@"AppleLanguages"];
|
|
|
|
NSString* currentLanguage = [languages objectAtIndex:0];
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
// get the current language code.(such as English is "en", Chinese is "zh" and so on)
|
2021-12-31 12:12:40 +08:00
|
|
|
NSDictionary* temp = [NSLocale componentsFromLocaleIdentifier:currentLanguage];
|
|
|
|
NSString* languageCode = [temp objectForKey:NSLocaleLanguageCode];
|
2019-11-23 20:27:39 +08:00
|
|
|
[languageCode getCString:code maxLength:3 encoding:NSASCIIStringEncoding];
|
2021-12-31 12:12:40 +08:00
|
|
|
code[2] = '\0';
|
2019-11-23 20:27:39 +08:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
LanguageType Application::getCurrentLanguage()
|
|
|
|
{
|
|
|
|
// get the current language and country config
|
2021-12-31 12:12:40 +08:00
|
|
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSArray* languages = [defaults objectForKey:@"AppleLanguages"];
|
|
|
|
NSString* currentLanguage = [languages objectAtIndex:0];
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
// get the current language code.(such as English is "en", Chinese is "zh" and so on)
|
2021-12-31 12:12:40 +08:00
|
|
|
NSDictionary* temp = [NSLocale componentsFromLocaleIdentifier:currentLanguage];
|
|
|
|
NSString* languageCode = [temp objectForKey:NSLocaleLanguageCode];
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
return utils::getLanguageTypeByISO2([languageCode UTF8String]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Application::Platform Application::getTargetPlatform()
|
|
|
|
{
|
2023-09-11 19:37:49 +08:00
|
|
|
#if TARGET_OS_IOS
|
2022-06-20 01:49:50 +08:00
|
|
|
return Platform::iOS;
|
2023-09-11 19:37:49 +08:00
|
|
|
#else /*elif TARGET_OS_TV*/
|
|
|
|
return Platform::tvOS;
|
|
|
|
#endif
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
std::string Application::getVersion()
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
NSString* version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
|
2021-12-31 12:12:40 +08:00
|
|
|
if (version)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
return [version UTF8String];
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
bool Application::openURL(std::string_view url)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
NSString* msg = [NSString stringWithCString:url.data() encoding:NSUTF8StringEncoding];
|
|
|
|
NSURL* nsUrl = [NSURL URLWithString:msg];
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
id application = [UIApplication sharedApplication];
|
2021-12-31 12:12:40 +08:00
|
|
|
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)])
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
[application openURL:nsUrl options:@{} completionHandler:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return [application openURL:nsUrl];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void Application::applicationScreenSizeChanged(int newWidth, int newHeight) {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|