os_ios.mm 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /**************************************************************************/
  2. /* os_ios.mm */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifdef IOS_ENABLED
  31. #include "os_ios.h"
  32. #import "app_delegate.h"
  33. #include "core/config/project_settings.h"
  34. #include "core/io/dir_access.h"
  35. #include "core/io/file_access.h"
  36. #include "core/io/file_access_pack.h"
  37. #include "display_server_ios.h"
  38. #include "drivers/unix/syslog_logger.h"
  39. #import "godot_view.h"
  40. #include "main/main.h"
  41. #import "view_controller.h"
  42. #import <AudioToolbox/AudioServices.h>
  43. #import <CoreText/CoreText.h>
  44. #import <UIKit/UIKit.h>
  45. #import <dlfcn.h>
  46. #include <sys/sysctl.h>
  47. #if defined(VULKAN_ENABLED)
  48. #include "servers/rendering/renderer_rd/renderer_compositor_rd.h"
  49. #import <QuartzCore/CAMetalLayer.h>
  50. #ifdef USE_VOLK
  51. #include <volk.h>
  52. #else
  53. #include <vulkan/vulkan.h>
  54. #endif
  55. #endif
  56. // Initialization order between compilation units is not guaranteed,
  57. // so we use this as a hack to ensure certain code is called before
  58. // everything else, but after all units are initialized.
  59. typedef void (*init_callback)();
  60. static init_callback *ios_init_callbacks = nullptr;
  61. static int ios_init_callbacks_count = 0;
  62. static int ios_init_callbacks_capacity = 0;
  63. HashMap<String, void *> OS_IOS::dynamic_symbol_lookup_table;
  64. void add_ios_init_callback(init_callback cb) {
  65. if (ios_init_callbacks_count == ios_init_callbacks_capacity) {
  66. void *new_ptr = realloc(ios_init_callbacks, sizeof(cb) * 32);
  67. if (new_ptr) {
  68. ios_init_callbacks = (init_callback *)(new_ptr);
  69. ios_init_callbacks_capacity += 32;
  70. }
  71. }
  72. if (ios_init_callbacks_capacity > ios_init_callbacks_count) {
  73. ios_init_callbacks[ios_init_callbacks_count] = cb;
  74. ++ios_init_callbacks_count;
  75. }
  76. }
  77. void register_dynamic_symbol(char *name, void *address) {
  78. OS_IOS::dynamic_symbol_lookup_table[String(name)] = address;
  79. }
  80. OS_IOS *OS_IOS::get_singleton() {
  81. return (OS_IOS *)OS::get_singleton();
  82. }
  83. OS_IOS::OS_IOS() {
  84. for (int i = 0; i < ios_init_callbacks_count; ++i) {
  85. ios_init_callbacks[i]();
  86. }
  87. free(ios_init_callbacks);
  88. ios_init_callbacks = nullptr;
  89. ios_init_callbacks_count = 0;
  90. ios_init_callbacks_capacity = 0;
  91. main_loop = nullptr;
  92. Vector<Logger *> loggers;
  93. loggers.push_back(memnew(SyslogLogger));
  94. #ifdef DEBUG_ENABLED
  95. // it seems iOS app's stdout/stderr is only obtainable if you launch it from
  96. // Xcode
  97. loggers.push_back(memnew(StdLogger));
  98. #endif
  99. _set_logger(memnew(CompositeLogger(loggers)));
  100. AudioDriverManager::add_driver(&audio_driver);
  101. DisplayServerIOS::register_ios_driver();
  102. }
  103. OS_IOS::~OS_IOS() {}
  104. void OS_IOS::alert(const String &p_alert, const String &p_title) {
  105. const CharString utf8_alert = p_alert.utf8();
  106. const CharString utf8_title = p_title.utf8();
  107. iOS::alert(utf8_alert.get_data(), utf8_title.get_data());
  108. }
  109. void OS_IOS::initialize_core() {
  110. OS_Unix::initialize_core();
  111. }
  112. void OS_IOS::initialize() {
  113. initialize_core();
  114. }
  115. void OS_IOS::initialize_modules() {
  116. ios = memnew(iOS);
  117. Engine::get_singleton()->add_singleton(Engine::Singleton("iOS", ios));
  118. joypad_ios = memnew(JoypadIOS);
  119. }
  120. void OS_IOS::deinitialize_modules() {
  121. if (joypad_ios) {
  122. memdelete(joypad_ios);
  123. }
  124. if (ios) {
  125. memdelete(ios);
  126. }
  127. }
  128. void OS_IOS::set_main_loop(MainLoop *p_main_loop) {
  129. main_loop = p_main_loop;
  130. if (main_loop) {
  131. main_loop->initialize();
  132. }
  133. }
  134. MainLoop *OS_IOS::get_main_loop() const {
  135. return main_loop;
  136. }
  137. void OS_IOS::delete_main_loop() {
  138. if (main_loop) {
  139. main_loop->finalize();
  140. memdelete(main_loop);
  141. }
  142. main_loop = nullptr;
  143. }
  144. bool OS_IOS::iterate() {
  145. if (!main_loop) {
  146. return true;
  147. }
  148. if (DisplayServer::get_singleton()) {
  149. DisplayServer::get_singleton()->process_events();
  150. }
  151. return Main::iteration();
  152. }
  153. void OS_IOS::start() {
  154. Main::start();
  155. if (joypad_ios) {
  156. joypad_ios->start_processing();
  157. }
  158. }
  159. void OS_IOS::finalize() {
  160. deinitialize_modules();
  161. // Already gets called
  162. //delete_main_loop();
  163. }
  164. // MARK: Dynamic Libraries
  165. _FORCE_INLINE_ String OS_IOS::get_framework_executable(const String &p_path) {
  166. Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  167. // Read framework bundle to get executable name.
  168. NSURL *url = [NSURL fileURLWithPath:@(p_path.utf8().get_data())];
  169. NSBundle *bundle = [NSBundle bundleWithURL:url];
  170. if (bundle) {
  171. String exe_path = String::utf8([[bundle executablePath] UTF8String]);
  172. if (da->file_exists(exe_path)) {
  173. return exe_path;
  174. }
  175. }
  176. // Try default executable name (invalid framework).
  177. if (da->dir_exists(p_path) && da->file_exists(p_path.path_join(p_path.get_file().get_basename()))) {
  178. return p_path.path_join(p_path.get_file().get_basename());
  179. }
  180. // Not a framework, try loading as .dylib.
  181. return p_path;
  182. }
  183. Error OS_IOS::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path, String *r_resolved_path) {
  184. if (p_path.length() == 0) {
  185. // Static xcframework.
  186. p_library_handle = RTLD_SELF;
  187. if (r_resolved_path != nullptr) {
  188. *r_resolved_path = p_path;
  189. }
  190. return OK;
  191. }
  192. String path = get_framework_executable(p_path);
  193. if (!FileAccess::exists(path)) {
  194. // Load .dylib or framework from within the executable path.
  195. path = get_framework_executable(get_executable_path().get_base_dir().path_join(p_path.get_file()));
  196. }
  197. if (!FileAccess::exists(path)) {
  198. // Load .dylib or framework from a standard iOS location.
  199. path = get_framework_executable(get_executable_path().get_base_dir().path_join("Frameworks").path_join(p_path.get_file()));
  200. }
  201. p_library_handle = dlopen(path.utf8().get_data(), RTLD_NOW);
  202. ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ", error: " + dlerror() + ".");
  203. if (r_resolved_path != nullptr) {
  204. *r_resolved_path = path;
  205. }
  206. return OK;
  207. }
  208. Error OS_IOS::close_dynamic_library(void *p_library_handle) {
  209. if (p_library_handle == RTLD_SELF) {
  210. return OK;
  211. }
  212. return OS_Unix::close_dynamic_library(p_library_handle);
  213. }
  214. Error OS_IOS::get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional) {
  215. if (p_library_handle == RTLD_SELF) {
  216. void **ptr = OS_IOS::dynamic_symbol_lookup_table.getptr(p_name);
  217. if (ptr) {
  218. p_symbol_handle = *ptr;
  219. return OK;
  220. }
  221. }
  222. return OS_Unix::get_dynamic_library_symbol_handle(p_library_handle, p_name, p_symbol_handle, p_optional);
  223. }
  224. String OS_IOS::get_name() const {
  225. return "iOS";
  226. }
  227. String OS_IOS::get_distribution_name() const {
  228. return get_name();
  229. }
  230. String OS_IOS::get_version() const {
  231. NSOperatingSystemVersion ver = [NSProcessInfo processInfo].operatingSystemVersion;
  232. return vformat("%d.%d.%d", (int64_t)ver.majorVersion, (int64_t)ver.minorVersion, (int64_t)ver.patchVersion);
  233. }
  234. String OS_IOS::get_model_name() const {
  235. String model = ios->get_model();
  236. if (model != "") {
  237. return model;
  238. }
  239. return OS_Unix::get_model_name();
  240. }
  241. Error OS_IOS::shell_open(String p_uri) {
  242. NSString *urlPath = [[NSString alloc] initWithUTF8String:p_uri.utf8().get_data()];
  243. NSURL *url = [NSURL URLWithString:urlPath];
  244. if (![[UIApplication sharedApplication] canOpenURL:url]) {
  245. return ERR_CANT_OPEN;
  246. }
  247. printf("opening url %s\n", p_uri.utf8().get_data());
  248. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
  249. return OK;
  250. }
  251. String OS_IOS::get_user_data_dir() const {
  252. static String ret;
  253. if (ret.is_empty()) {
  254. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  255. if (paths && [paths count] >= 1) {
  256. ret.parse_utf8([[paths firstObject] UTF8String]);
  257. }
  258. }
  259. return ret;
  260. }
  261. String OS_IOS::get_cache_path() const {
  262. static String ret;
  263. if (ret.is_empty()) {
  264. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  265. if (paths && [paths count] >= 1) {
  266. ret.parse_utf8([[paths firstObject] UTF8String]);
  267. }
  268. }
  269. return ret;
  270. }
  271. String OS_IOS::get_locale() const {
  272. NSString *preferedLanguage = [NSLocale preferredLanguages].firstObject;
  273. if (preferedLanguage) {
  274. return String::utf8([preferedLanguage UTF8String]).replace("-", "_");
  275. }
  276. NSString *localeIdentifier = [[NSLocale currentLocale] localeIdentifier];
  277. return String::utf8([localeIdentifier UTF8String]).replace("-", "_");
  278. }
  279. String OS_IOS::get_unique_id() const {
  280. NSString *uuid = [UIDevice currentDevice].identifierForVendor.UUIDString;
  281. return String::utf8([uuid UTF8String]);
  282. }
  283. String OS_IOS::get_processor_name() const {
  284. char buffer[256];
  285. size_t buffer_len = 256;
  286. if (sysctlbyname("machdep.cpu.brand_string", &buffer, &buffer_len, NULL, 0) == 0) {
  287. return String::utf8(buffer, buffer_len);
  288. }
  289. ERR_FAIL_V_MSG("", String("Couldn't get the CPU model name. Returning an empty string."));
  290. }
  291. Vector<String> OS_IOS::get_system_fonts() const {
  292. HashSet<String> font_names;
  293. CFArrayRef fonts = CTFontManagerCopyAvailableFontFamilyNames();
  294. if (fonts) {
  295. for (CFIndex i = 0; i < CFArrayGetCount(fonts); i++) {
  296. CFStringRef cf_name = (CFStringRef)CFArrayGetValueAtIndex(fonts, i);
  297. if (cf_name && (CFStringGetLength(cf_name) > 0) && (CFStringCompare(cf_name, CFSTR("LastResort"), kCFCompareCaseInsensitive) != kCFCompareEqualTo) && (CFStringGetCharacterAtIndex(cf_name, 0) != '.')) {
  298. NSString *ns_name = (__bridge NSString *)cf_name;
  299. font_names.insert(String::utf8([ns_name UTF8String]));
  300. }
  301. }
  302. CFRelease(fonts);
  303. }
  304. Vector<String> ret;
  305. for (const String &E : font_names) {
  306. ret.push_back(E);
  307. }
  308. return ret;
  309. }
  310. String OS_IOS::_get_default_fontname(const String &p_font_name) const {
  311. String font_name = p_font_name;
  312. if (font_name.to_lower() == "sans-serif") {
  313. font_name = "Helvetica";
  314. } else if (font_name.to_lower() == "serif") {
  315. font_name = "Times";
  316. } else if (font_name.to_lower() == "monospace") {
  317. font_name = "Courier";
  318. } else if (font_name.to_lower() == "fantasy") {
  319. font_name = "Papyrus";
  320. } else if (font_name.to_lower() == "cursive") {
  321. font_name = "Apple Chancery";
  322. };
  323. return font_name;
  324. }
  325. CGFloat OS_IOS::_weight_to_ct(int p_weight) const {
  326. if (p_weight < 150) {
  327. return -0.80;
  328. } else if (p_weight < 250) {
  329. return -0.60;
  330. } else if (p_weight < 350) {
  331. return -0.40;
  332. } else if (p_weight < 450) {
  333. return 0.0;
  334. } else if (p_weight < 550) {
  335. return 0.23;
  336. } else if (p_weight < 650) {
  337. return 0.30;
  338. } else if (p_weight < 750) {
  339. return 0.40;
  340. } else if (p_weight < 850) {
  341. return 0.56;
  342. } else if (p_weight < 925) {
  343. return 0.62;
  344. } else {
  345. return 1.00;
  346. }
  347. }
  348. CGFloat OS_IOS::_stretch_to_ct(int p_stretch) const {
  349. if (p_stretch < 56) {
  350. return -0.5;
  351. } else if (p_stretch < 69) {
  352. return -0.37;
  353. } else if (p_stretch < 81) {
  354. return -0.25;
  355. } else if (p_stretch < 93) {
  356. return -0.13;
  357. } else if (p_stretch < 106) {
  358. return 0.0;
  359. } else if (p_stretch < 137) {
  360. return 0.13;
  361. } else if (p_stretch < 144) {
  362. return 0.25;
  363. } else if (p_stretch < 162) {
  364. return 0.37;
  365. } else {
  366. return 0.5;
  367. }
  368. }
  369. Vector<String> OS_IOS::get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale, const String &p_script, int p_weight, int p_stretch, bool p_italic) const {
  370. Vector<String> ret;
  371. String font_name = _get_default_fontname(p_font_name);
  372. CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, font_name.utf8().get_data(), kCFStringEncodingUTF8);
  373. CTFontSymbolicTraits traits = 0;
  374. if (p_weight >= 700) {
  375. traits |= kCTFontBoldTrait;
  376. }
  377. if (p_italic) {
  378. traits |= kCTFontItalicTrait;
  379. }
  380. if (p_stretch < 100) {
  381. traits |= kCTFontCondensedTrait;
  382. } else if (p_stretch > 100) {
  383. traits |= kCTFontExpandedTrait;
  384. }
  385. CFNumberRef sym_traits = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &traits);
  386. CFMutableDictionaryRef traits_dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, nullptr, nullptr);
  387. CFDictionaryAddValue(traits_dict, kCTFontSymbolicTrait, sym_traits);
  388. CGFloat weight = _weight_to_ct(p_weight);
  389. CFNumberRef font_weight = CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &weight);
  390. CFDictionaryAddValue(traits_dict, kCTFontWeightTrait, font_weight);
  391. CGFloat stretch = _stretch_to_ct(p_stretch);
  392. CFNumberRef font_stretch = CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &stretch);
  393. CFDictionaryAddValue(traits_dict, kCTFontWidthTrait, font_stretch);
  394. CFMutableDictionaryRef attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, nullptr, nullptr);
  395. CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, name);
  396. CFDictionaryAddValue(attributes, kCTFontTraitsAttribute, traits_dict);
  397. CTFontDescriptorRef font = CTFontDescriptorCreateWithAttributes(attributes);
  398. if (font) {
  399. CTFontRef family = CTFontCreateWithFontDescriptor(font, 0, nullptr);
  400. CFStringRef string = CFStringCreateWithCString(kCFAllocatorDefault, p_text.utf8().get_data(), kCFStringEncodingUTF8);
  401. CFRange range = CFRangeMake(0, CFStringGetLength(string));
  402. CTFontRef fallback_family = CTFontCreateForString(family, string, range);
  403. if (fallback_family) {
  404. CTFontDescriptorRef fallback_font = CTFontCopyFontDescriptor(fallback_family);
  405. if (fallback_font) {
  406. CFURLRef url = (CFURLRef)CTFontDescriptorCopyAttribute(fallback_font, kCTFontURLAttribute);
  407. if (url) {
  408. NSString *font_path = [NSString stringWithString:[(__bridge NSURL *)url path]];
  409. ret.push_back(String::utf8([font_path UTF8String]));
  410. CFRelease(url);
  411. }
  412. CFRelease(fallback_font);
  413. }
  414. CFRelease(fallback_family);
  415. }
  416. CFRelease(string);
  417. CFRelease(font);
  418. }
  419. CFRelease(attributes);
  420. CFRelease(traits_dict);
  421. CFRelease(sym_traits);
  422. CFRelease(font_stretch);
  423. CFRelease(font_weight);
  424. CFRelease(name);
  425. return ret;
  426. }
  427. String OS_IOS::get_system_font_path(const String &p_font_name, int p_weight, int p_stretch, bool p_italic) const {
  428. String ret;
  429. String font_name = _get_default_fontname(p_font_name);
  430. CFStringRef name = CFStringCreateWithCString(kCFAllocatorDefault, font_name.utf8().get_data(), kCFStringEncodingUTF8);
  431. CTFontSymbolicTraits traits = 0;
  432. if (p_weight >= 700) {
  433. traits |= kCTFontBoldTrait;
  434. }
  435. if (p_italic) {
  436. traits |= kCTFontItalicTrait;
  437. }
  438. if (p_stretch < 100) {
  439. traits |= kCTFontCondensedTrait;
  440. } else if (p_stretch > 100) {
  441. traits |= kCTFontExpandedTrait;
  442. }
  443. CFNumberRef sym_traits = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &traits);
  444. CFMutableDictionaryRef traits_dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, nullptr, nullptr);
  445. CFDictionaryAddValue(traits_dict, kCTFontSymbolicTrait, sym_traits);
  446. CGFloat weight = _weight_to_ct(p_weight);
  447. CFNumberRef font_weight = CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &weight);
  448. CFDictionaryAddValue(traits_dict, kCTFontWeightTrait, font_weight);
  449. CGFloat stretch = _stretch_to_ct(p_stretch);
  450. CFNumberRef font_stretch = CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &stretch);
  451. CFDictionaryAddValue(traits_dict, kCTFontWidthTrait, font_stretch);
  452. CFMutableDictionaryRef attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, nullptr, nullptr);
  453. CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, name);
  454. CFDictionaryAddValue(attributes, kCTFontTraitsAttribute, traits_dict);
  455. CTFontDescriptorRef font = CTFontDescriptorCreateWithAttributes(attributes);
  456. if (font) {
  457. CFURLRef url = (CFURLRef)CTFontDescriptorCopyAttribute(font, kCTFontURLAttribute);
  458. if (url) {
  459. NSString *font_path = [NSString stringWithString:[(__bridge NSURL *)url path]];
  460. ret = String::utf8([font_path UTF8String]);
  461. CFRelease(url);
  462. }
  463. CFRelease(font);
  464. }
  465. CFRelease(attributes);
  466. CFRelease(traits_dict);
  467. CFRelease(sym_traits);
  468. CFRelease(font_stretch);
  469. CFRelease(font_weight);
  470. CFRelease(name);
  471. return ret;
  472. }
  473. void OS_IOS::vibrate_handheld(int p_duration_ms) {
  474. if (ios->supports_haptic_engine()) {
  475. ios->vibrate_haptic_engine((float)p_duration_ms / 1000.f);
  476. } else {
  477. // iOS <13 does not support duration for vibration
  478. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
  479. }
  480. }
  481. bool OS_IOS::_check_internal_feature_support(const String &p_feature) {
  482. if (p_feature == "system_fonts") {
  483. return true;
  484. }
  485. if (p_feature == "mobile") {
  486. return true;
  487. }
  488. return false;
  489. }
  490. void OS_IOS::on_focus_out() {
  491. if (is_focused) {
  492. is_focused = false;
  493. if (DisplayServerIOS::get_singleton()) {
  494. DisplayServerIOS::get_singleton()->send_window_event(DisplayServer::WINDOW_EVENT_FOCUS_OUT);
  495. }
  496. [AppDelegate.viewController.godotView stopRendering];
  497. audio_driver.stop();
  498. }
  499. }
  500. void OS_IOS::on_focus_in() {
  501. if (!is_focused) {
  502. is_focused = true;
  503. if (DisplayServerIOS::get_singleton()) {
  504. DisplayServerIOS::get_singleton()->send_window_event(DisplayServer::WINDOW_EVENT_FOCUS_IN);
  505. }
  506. [AppDelegate.viewController.godotView startRendering];
  507. audio_driver.start();
  508. }
  509. }
  510. #endif // IOS_ENABLED