Merge pull request #41172 from naithar/fix/iphone-os-values
[iOS] [4.0] Simplify OS value retrieval
This commit is contained in:
commit
69e995e5af
@ -44,7 +44,6 @@
|
|||||||
|
|
||||||
@interface GodotViewRenderer ()
|
@interface GodotViewRenderer ()
|
||||||
|
|
||||||
@property(assign, nonatomic) BOOL hasFinishedLocaleSetup;
|
|
||||||
@property(assign, nonatomic) BOOL hasFinishedProjectDataSetup;
|
@property(assign, nonatomic) BOOL hasFinishedProjectDataSetup;
|
||||||
@property(assign, nonatomic) BOOL hasStartedMain;
|
@property(assign, nonatomic) BOOL hasStartedMain;
|
||||||
@property(assign, nonatomic) BOOL hasFinishedSetup;
|
@property(assign, nonatomic) BOOL hasFinishedSetup;
|
||||||
@ -58,9 +57,8 @@
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!self.hasFinishedLocaleSetup) {
|
if (!OS::get_singleton()) {
|
||||||
[self setupLocaleAndUUID];
|
exit(0);
|
||||||
return YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!self.hasFinishedProjectDataSetup) {
|
if (!self.hasFinishedProjectDataSetup) {
|
||||||
@ -79,33 +77,6 @@
|
|||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setupLocaleAndUUID {
|
|
||||||
self.hasFinishedLocaleSetup = YES;
|
|
||||||
|
|
||||||
if (!OS::get_singleton()) {
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = [(NSString *)CFUUIDCreateString(NULL, cfuuid) autorelease];
|
|
||||||
CFRelease(cfuuid);
|
|
||||||
[[NSUserDefaults standardUserDefaults] setObject:uuid forKey:@"identifierForVendor"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OSIPhone::get_singleton()->set_unique_id(String::utf8([uuid UTF8String]));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setupProjectData {
|
- (void)setupProjectData {
|
||||||
self.hasFinishedProjectDataSetup = YES;
|
self.hasFinishedProjectDataSetup = YES;
|
||||||
|
|
||||||
|
@ -84,8 +84,6 @@ private:
|
|||||||
virtual void finalize() override;
|
virtual void finalize() override;
|
||||||
|
|
||||||
String user_data_dir;
|
String user_data_dir;
|
||||||
String unique_id;
|
|
||||||
String locale_code;
|
|
||||||
|
|
||||||
bool is_focused = false;
|
bool is_focused = false;
|
||||||
|
|
||||||
@ -118,10 +116,8 @@ public:
|
|||||||
void set_user_data_dir(String p_dir);
|
void set_user_data_dir(String p_dir);
|
||||||
virtual String get_user_data_dir() const override;
|
virtual String get_user_data_dir() const override;
|
||||||
|
|
||||||
void set_locale(String p_locale);
|
|
||||||
virtual String get_locale() const override;
|
virtual String get_locale() const override;
|
||||||
|
|
||||||
void set_unique_id(String p_id);
|
|
||||||
virtual String get_unique_id() const override;
|
virtual String get_unique_id() const override;
|
||||||
|
|
||||||
virtual void vibrate_handheld(int p_duration_ms = 500) override;
|
virtual void vibrate_handheld(int p_duration_ms = 500) override;
|
||||||
|
@ -305,20 +305,20 @@ String OSIPhone::get_user_data_dir() const {
|
|||||||
return user_data_dir;
|
return user_data_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
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("-", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSIPhone::set_unique_id(String p_id) {
|
NSString *localeIdentifier = [[NSLocale currentLocale] localeIdentifier];
|
||||||
unique_id = p_id;
|
return String::utf8([localeIdentifier UTF8String]).replace("-", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
String OSIPhone::get_unique_id() const {
|
String OSIPhone::get_unique_id() const {
|
||||||
return unique_id;
|
NSString *uuid = [UIDevice currentDevice].identifierForVendor.UUIDString;
|
||||||
|
return String::utf8([uuid UTF8String]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSIPhone::vibrate_handheld(int p_duration_ms) {
|
void OSIPhone::vibrate_handheld(int p_duration_ms) {
|
||||||
|
Loading…
Reference in New Issue
Block a user