summaryrefslogtreecommitdiffstats
path: root/base/sys_info_ios.mm
diff options
context:
space:
mode:
Diffstat (limited to 'base/sys_info_ios.mm')
-rw-r--r--base/sys_info_ios.mm47
1 files changed, 28 insertions, 19 deletions
diff --git a/base/sys_info_ios.mm b/base/sys_info_ios.mm
index 1ee0e54..7863f6b 100644
--- a/base/sys_info_ios.mm
+++ b/base/sys_info_ios.mm
@@ -18,16 +18,28 @@ namespace base {
// static
std::string SysInfo::OperatingSystemName() {
- base::mac::ScopedNSAutoreleasePool pool;
+ static dispatch_once_t get_system_name_once;
+ static std::string* system_name;
+ dispatch_once(&get_system_name_once, ^{
+ base::mac::ScopedNSAutoreleasePool pool;
+ system_name = new std::string(
+ SysNSStringToUTF8([[UIDevice currentDevice] systemName]));
+ });
// Examples of returned value: 'iPhone OS' on iPad 5.1.1
// and iPhone 5.1.1.
- return SysNSStringToUTF8([[UIDevice currentDevice] systemName]);
+ return *system_name;
}
// static
std::string SysInfo::OperatingSystemVersion() {
- base::mac::ScopedNSAutoreleasePool pool;
- return SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]);
+ static dispatch_once_t get_system_version_once;
+ static std::string* system_version;
+ dispatch_once(&get_system_version_once, ^{
+ base::mac::ScopedNSAutoreleasePool pool;
+ system_version = new std::string(
+ SysNSStringToUTF8([[UIDevice currentDevice] systemVersion]));
+ });
+ return *system_version;
}
// static
@@ -35,21 +47,18 @@ void SysInfo::OperatingSystemVersionNumbers(int32* major_version,
int32* minor_version,
int32* bugfix_version) {
base::mac::ScopedNSAutoreleasePool pool;
- NSString* version = [[UIDevice currentDevice] systemVersion];
- NSArray* version_info = [version componentsSeparatedByString:@"."];
- NSUInteger length = [version_info count];
-
- *major_version = [[version_info objectAtIndex:0] intValue];
-
- if (length >= 2)
- *minor_version = [[version_info objectAtIndex:1] intValue];
- else
- *minor_version = 0;
-
- if (length >= 3)
- *bugfix_version = [[version_info objectAtIndex:2] intValue];
- else
- *bugfix_version = 0;
+ std::string system_version = OperatingSystemVersion();
+ if (!system_version.empty()) {
+ // Try to parse out the version numbers from the string.
+ int num_read = sscanf(system_version.c_str(), "%d.%d.%d", major_version,
+ minor_version, bugfix_version);
+ if (num_read < 1)
+ *major_version = 0;
+ if (num_read < 2)
+ *minor_version = 0;
+ if (num_read < 3)
+ *bugfix_version = 0;
+ }
}
// static