diff --git a/native/cocos/platform/ios/Application-ios.mm b/native/cocos/platform/ios/Application-ios.mm index 312780a014..6b021bcb03 100644 --- a/native/cocos/platform/ios/Application-ios.mm +++ b/native/cocos/platform/ios/Application-ios.mm @@ -30,11 +30,11 @@ #import #include -#include "base/Scheduler.h" +#include "audio/include/AudioEngine.h" #include "base/AutoreleasePool.h" +#include "base/Scheduler.h" #include "bindings/event/EventDispatcher.h" #include "bindings/jswrapper/SeApi.h" -#include "audio/include/AudioEngine.h" #include "platform/Device.h" #include "pipeline/Define.h" @@ -43,8 +43,8 @@ @interface MyTimer : NSObject { cc::Application *_app; - CADisplayLink *_displayLink; - int _fps; + CADisplayLink * _displayLink; + int _fps; } - (instancetype)initWithApp:(cc::Application *)app fps:(int)fps; - (void)start; @@ -57,9 +57,9 @@ - (instancetype)initWithApp:(cc::Application *)app fps:(int)fps { if (self = [super init]) { - _fps = fps; - _app = app; - _displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(renderScene:)]; + _fps = fps; + _app = app; + _displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(renderScene:)]; _displayLink.preferredFramesPerSecond = _fps; } return self; @@ -104,8 +104,8 @@ namespace { //set window.innerWidth/innerHeight in css pixel units uintptr_t windowHandle = reinterpret_cast(UIApplication.sharedApplication.delegate.window.rootViewController.view); std::stringstream commandBuf; - commandBuf << "window.innerWidth = " << viewLogicalSize.x - << "; window.innerHeight = " << viewLogicalSize.y + commandBuf << "window.innerWidth = " << viewLogicalSize.x + << "; window.innerHeight = " << viewLogicalSize.y << "; window.nativeWidth= " << nativeWidth << "; window.nativeHeight = " << nativeHeight << "; window.windowHandler = " << windowHandle << ";"; @@ -134,7 +134,7 @@ std::shared_ptr Application::_scheduler = nullptr; Application::Application(int width, int height) { Application::_instance = this; - _scheduler = std::make_shared(); + _scheduler = std::make_shared(); EventDispatcher::init(); _viewLogicalSize.x = width; _viewLogicalSize.y = height; @@ -160,23 +160,23 @@ Application::~Application() { } std::string Application::getCurrentLanguageCode() const { - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSArray *languages = [defaults objectForKey:@"AppleLanguages"]; - NSString *currentLanguage = [languages objectAtIndex:0]; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSArray * languages = [defaults objectForKey:@"AppleLanguages"]; + NSString * currentLanguage = [languages objectAtIndex:0]; return [currentLanguage UTF8String]; } bool Application::isDisplayStats() { se::AutoHandleScope hs; - se::Value ret; - char commandBuf[100] = "cc.debug.isDisplayStats();"; + se::Value ret; + char commandBuf[100] = "cc.debug.isDisplayStats();"; se::ScriptEngine::getInstance()->evalString(commandBuf, 100, &ret); return ret.toBoolean(); } void Application::setDisplayStats(bool isShow) { se::AutoHandleScope hs; - char commandBuf[100] = {0}; + char commandBuf[100] = {0}; sprintf(commandBuf, "cc.debug.setDisplayStats(%s);", isShow ? "true" : "false"); se::ScriptEngine::getInstance()->evalString(commandBuf); } @@ -186,13 +186,13 @@ void Application::setCursorEnabled(bool value) { Application::LanguageType Application::getCurrentLanguage() const { // get the current language and country config - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - NSArray *languages = [defaults objectForKey:@"AppleLanguages"]; - NSString *currentLanguage = [languages objectAtIndex:0]; + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSArray * languages = [defaults objectForKey:@"AppleLanguages"]; + NSString * currentLanguage = [languages objectAtIndex:0]; // get the current language code.(such as English is "en", Chinese is "zh" and so on) - NSDictionary *temp = [NSLocale componentsFromLocaleIdentifier:currentLanguage]; - NSString *languageCode = [temp objectForKey:NSLocaleLanguageCode]; + NSDictionary *temp = [NSLocale componentsFromLocaleIdentifier:currentLanguage]; + NSString * languageCode = [temp objectForKey:NSLocaleLanguageCode]; if ([languageCode isEqualToString:@"zh"]) return LanguageType::CHINESE; if ([languageCode isEqualToString:@"en"]) return LanguageType::ENGLISH; @@ -224,18 +224,20 @@ Application::Platform Application::getPlatform() const { } bool Application::openURL(const std::string &url) { - NSString *msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding]; - NSURL *nsUrl = [NSURL URLWithString:msg]; - __block BOOL flag = false; - [[UIApplication sharedApplication] openURL:nsUrl options:@{} completionHandler:^(BOOL success) { - flag = success; - }]; + NSString * msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding]; + NSURL * nsUrl = [NSURL URLWithString:msg]; + __block BOOL flag = false; + [[UIApplication sharedApplication] openURL:nsUrl + options:@{} + completionHandler:^(BOOL success) { + flag = success; + }]; return flag; } void Application::copyTextToClipboard(const std::string &text) { UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; - pasteboard.string = [NSString stringWithCString:text.c_str() encoding:NSUTF8StringEncoding]; + pasteboard.string = [NSString stringWithCString:text.c_str() encoding:NSUTF8StringEncoding]; } bool Application::init() { diff --git a/native/cocos/platform/ios/View.mm b/native/cocos/platform/ios/View.mm index ac84f04cb8..7ca048bca6 100644 --- a/native/cocos/platform/ios/View.mm +++ b/native/cocos/platform/ios/View.mm @@ -24,9 +24,9 @@ ****************************************************************************/ #import "View.h" +#include #include "bindings/event/EventDispatcher.h" #include "platform/Application.h" -#include namespace { void dispatchEvents(cc::TouchEvent &touchEvent, NSSet *touches) { @@ -60,15 +60,16 @@ void dispatchEvents(cc::TouchEvent &touchEvent, NSSet *touches) { #ifdef CC_USE_METAL if (self = [super initWithFrame:frame]) { self.preventTouch = FALSE; - - int pixelRatio = [[UIScreen mainScreen] scale]; - CGSize size = CGSizeMake(frame.size.width * pixelRatio, frame.size.height * pixelRatio); + + float pixelRatio = [[UIScreen mainScreen] nativeScale]; + CGSize size = CGSizeMake(static_cast(frame.size.width * pixelRatio), + static_cast(frame.size.height * pixelRatio)); self.contentScaleFactor = pixelRatio; // Config metal layer - CAMetalLayer *layer = (CAMetalLayer*)self.layer; - layer.pixelFormat = MTLPixelFormatBGRA8Unorm; + CAMetalLayer *layer = (CAMetalLayer *)self.layer; + layer.pixelFormat = MTLPixelFormatBGRA8Unorm; layer.device = self.device = MTLCreateSystemDefaultDevice(); - layer.drawableSize = size; + layer.drawableSize = size; } #else if (self = [super initWithFrame:frame]) {