iOS: simplify OS values retrieval

This commit is contained in:
Sergey Minakov 2020-08-10 16:16:13 +03:00
parent 23b553ba06
commit 8a8f0a3b79
4 changed files with 13 additions and 42 deletions

View file

@ -4,7 +4,7 @@ Import("env")
iphone_lib = [ iphone_lib = [
"godot_iphone.cpp", "godot_iphone.cpp",
"os_iphone.cpp", "os_iphone.mm",
"semaphore_iphone.cpp", "semaphore_iphone.cpp",
"gl_view.mm", "gl_view.mm",
"main.m", "main.m",

View file

@ -438,30 +438,6 @@ static int frame_count = 0;
}; };
++frame_count; ++frame_count;
NSString *locale_code = [[NSLocale currentLocale] localeIdentifier];
OSIPhone::get_singleton()->set_locale(
String::utf8([locale_code UTF8String]));
NSString *uuid;
if ([[UIDevice currentDevice]
respondsToSelector:@selector(identifierForVendor)]) {
uuid = [UIDevice currentDevice].identifierForVendor.UUIDString;
} else {
// before iOS 6, so just generate an identifier and store it
uuid = [[NSUserDefaults standardUserDefaults]
objectForKey:@"identiferForVendor"];
if (!uuid) {
CFUUIDRef cfuuid = CFUUIDCreate(NULL);
uuid = (__bridge_transfer NSString *)CFUUIDCreateString(NULL, cfuuid);
CFRelease(cfuuid);
[[NSUserDefaults standardUserDefaults]
setObject:uuid
forKey:@"identifierForVendor"];
}
}
OSIPhone::get_singleton()->set_unique_id(String::utf8([uuid UTF8String]));
}; break; }; break;
case 1: { case 1: {

View file

@ -109,8 +109,6 @@ private:
void queue_event(const Ref<InputEvent> &p_event); void queue_event(const Ref<InputEvent> &p_event);
String data_dir; String data_dir;
String unique_id;
String locale_code;
InputDefault *input; InputDefault *input;
@ -183,10 +181,8 @@ public:
String get_user_data_dir() const; String get_user_data_dir() const;
void set_locale(String p_locale);
String get_locale() const; String get_locale() const;
void set_unique_id(String p_id);
String get_unique_id() const; String get_unique_id() const;
virtual Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); virtual Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);

View file

@ -1,5 +1,5 @@
/*************************************************************************/ /*************************************************************************/
/* os_iphone.cpp */ /* os_iphone.mm */
/*************************************************************************/ /*************************************************************************/
/* This file is part of: */ /* This file is part of: */
/* GODOT ENGINE */ /* GODOT ENGINE */
@ -47,6 +47,7 @@
#include "semaphore_iphone.h" #include "semaphore_iphone.h"
#import <UIKit/UIKit.h>
#include <dlfcn.h> #include <dlfcn.h>
int OSIPhone::get_video_driver_count() const { int OSIPhone::get_video_driver_count() const {
@ -81,14 +82,9 @@ void OSIPhone::set_data_dir(String p_dir) {
memdelete(da); memdelete(da);
}; };
void OSIPhone::set_unique_id(String p_id) {
unique_id = p_id;
};
String OSIPhone::get_unique_id() const { String OSIPhone::get_unique_id() const {
NSString *uuid = [UIDevice currentDevice].identifierForVendor.UUIDString;
return unique_id; return String::utf8([uuid UTF8String]);
}; };
void OSIPhone::initialize_core() { void OSIPhone::initialize_core() {
@ -542,12 +538,15 @@ bool OSIPhone::has_touchscreen_ui_hint() const {
return true; return true;
} }
void OSIPhone::set_locale(String p_locale) {
locale_code = p_locale;
}
String OSIPhone::get_locale() const { String OSIPhone::get_locale() const {
return locale_code; NSString *preferedLanguage = [NSLocale preferredLanguages].firstObject;
if (preferedLanguage) {
return String::utf8([preferedLanguage UTF8String]).replace("-", "_");
}
NSString *localeIdentifier = [[NSLocale currentLocale] localeIdentifier];
return String::utf8([localeIdentifier UTF8String]).replace("-", "_");
} }
extern bool _play_video(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); extern bool _play_video(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);