2011-03-02 17:05:22 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2016-03-21 20:12:58 +08:00
|
|
|
|
2022-07-09 01:23:11 +08:00
|
|
|
https://axis-project.github.io/
|
2016-03-21 20:12:58 +08:00
|
|
|
|
2011-03-02 17:05:22 +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:
|
2016-03-21 20:12:58 +08:00
|
|
|
|
2011-03-02 17:05:22 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2016-03-21 20:12:58 +08:00
|
|
|
|
2011-03-02 17:05:22 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2012-04-25 17:33:28 +08:00
|
|
|
#import "CCApplication.h"
|
2011-03-02 17:05:22 +08:00
|
|
|
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2021-10-24 11:07:54 +08:00
|
|
|
#import "math/CCMath.h"
|
2016-03-21 20:12:58 +08:00
|
|
|
#import "platform/ios/CCDirectorCaller-ios.h"
|
2018-02-11 09:19:47 +08:00
|
|
|
#import "base/ccUtils.h"
|
2011-03-02 17:05:22 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2011-03-02 17:05:22 +08:00
|
|
|
|
2016-06-23 11:39:23 +08:00
|
|
|
Application* Application::sm_pSharedApplication = nullptr;
|
2011-03-02 17:05:22 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Application::Application()
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(!sm_pSharedApplication);
|
2011-03-02 17:05:22 +08:00
|
|
|
sm_pSharedApplication = this;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Application::~Application()
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(this == sm_pSharedApplication);
|
2011-03-02 17:05:22 +08:00
|
|
|
sm_pSharedApplication = 0;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
int Application::run()
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2016-03-21 20:12:58 +08:00
|
|
|
if (applicationDidFinishLaunching())
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2013-06-21 08:46:22 +08:00
|
|
|
[[CCDirectorCaller sharedDirectorCaller] startMainLoop];
|
2011-03-02 17:05:22 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-30 21:04:00 +08:00
|
|
|
void Application::setAnimationInterval(float interval)
|
|
|
|
{
|
|
|
|
[[CCDirectorCaller sharedDirectorCaller] setAnimationInterval:interval];
|
|
|
|
}
|
2011-03-02 17:05:22 +08:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// static member function
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-07-15 16:24:42 +08:00
|
|
|
Application* Application::getInstance()
|
2011-03-02 17:05:22 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(sm_pSharedApplication);
|
2012-08-21 15:28:43 +08:00
|
|
|
return sm_pSharedApplication;
|
2011-03-02 17:05:22 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 11:00:34 +08:00
|
|
|
const char* Application::getCurrentLanguageCode()
|
2014-03-18 02:34:21 +08:00
|
|
|
{
|
2021-12-28 11:00:34 +08:00
|
|
|
static char code[3] = {0};
|
|
|
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSArray* languages = [defaults objectForKey:@"AppleLanguages"];
|
|
|
|
NSString* currentLanguage = [languages objectAtIndex:0];
|
2016-03-21 20:12:58 +08:00
|
|
|
|
2014-03-18 02:34:21 +08:00
|
|
|
// get the current language code.(such as English is "en", Chinese is "zh" and so on)
|
2021-12-28 11:00:34 +08:00
|
|
|
NSDictionary* temp = [NSLocale componentsFromLocaleIdentifier:currentLanguage];
|
|
|
|
NSString* languageCode = [temp objectForKey:NSLocaleLanguageCode];
|
2014-10-11 15:19:20 +08:00
|
|
|
[languageCode getCString:code maxLength:3 encoding:NSASCIIStringEncoding];
|
2021-12-28 11:00:34 +08:00
|
|
|
code[2] = '\0';
|
2014-03-18 02:34:21 +08:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2013-07-26 17:29:06 +08:00
|
|
|
LanguageType Application::getCurrentLanguage()
|
2011-06-17 10:49:02 +08:00
|
|
|
{
|
|
|
|
// get the current language and country config
|
2021-12-28 11:00:34 +08:00
|
|
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSArray* languages = [defaults objectForKey:@"AppleLanguages"];
|
|
|
|
NSString* currentLanguage = [languages objectAtIndex:0];
|
2016-03-21 20:12:58 +08:00
|
|
|
|
2011-06-17 10:49:02 +08:00
|
|
|
// get the current language code.(such as English is "en", Chinese is "zh" and so on)
|
2021-12-28 11:00:34 +08:00
|
|
|
NSDictionary* temp = [NSLocale componentsFromLocaleIdentifier:currentLanguage];
|
|
|
|
NSString* languageCode = [temp objectForKey:NSLocaleLanguageCode];
|
2016-03-21 20:12:58 +08:00
|
|
|
|
2018-02-11 09:19:47 +08:00
|
|
|
return utils::getLanguageTypeByISO2([languageCode UTF8String]);
|
2011-06-17 10:49:02 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 17:29:06 +08:00
|
|
|
Application::Platform Application::getTargetPlatform()
|
2012-06-11 14:36:25 +08:00
|
|
|
{
|
2022-06-17 22:18:26 +08:00
|
|
|
return Platform::iOS;
|
2012-08-08 17:42:04 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 11:00:34 +08:00
|
|
|
std::string Application::getVersion()
|
|
|
|
{
|
2015-10-29 01:57:57 +08:00
|
|
|
NSString* version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
|
2021-12-28 11:00:34 +08:00
|
|
|
if (version)
|
|
|
|
{
|
2015-10-29 01:57:57 +08:00
|
|
|
return [version UTF8String];
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2021-12-28 11:17:53 +08:00
|
|
|
bool Application::openURL(std::string_view url)
|
2014-09-09 16:07:33 +08:00
|
|
|
{
|
2021-12-28 18:21:18 +08:00
|
|
|
NSString* msg = [NSString stringWithCString:url.data() encoding:NSUTF8StringEncoding];
|
2021-12-28 11:00:34 +08:00
|
|
|
NSURL* nsUrl = [NSURL URLWithString:msg];
|
|
|
|
|
2019-10-25 16:40:30 +08:00
|
|
|
id application = [UIApplication sharedApplication];
|
2021-12-28 11:00:34 +08:00
|
|
|
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)])
|
2019-10-25 16:40:30 +08:00
|
|
|
{
|
|
|
|
[application openURL:nsUrl options:@{} completionHandler:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return [application openURL:nsUrl];
|
|
|
|
}
|
2014-09-09 16:07:33 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 11:00:34 +08:00
|
|
|
void Application::applicationScreenSizeChanged(int newWidth, int newHeight) {}
|
2013-10-23 16:29:59 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|