1// Copyright 2012 The Chromium Authors 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "base/ios/ios_util.h" 6 7#import <Foundation/Foundation.h> 8#import <UIKit/UIKit.h> 9#include <stddef.h> 10 11#include "base/apple/foundation_util.h" 12#include "base/system/sys_info.h" 13 14namespace { 15 16std::string* g_icudtl_path_override = nullptr; 17 18} // namespace 19 20namespace base::ios { 21 22bool IsRunningOnIOS16OrLater() { 23 static const bool is_running_on_or_later = IsRunningOnOrLater(16, 0, 0); 24 return is_running_on_or_later; 25} 26 27bool IsRunningOnIOS17OrLater() { 28 static const bool is_running_on_or_later = IsRunningOnOrLater(17, 0, 0); 29 return is_running_on_or_later; 30} 31 32bool IsRunningOnOrLater(int32_t major, int32_t minor, int32_t bug_fix) { 33 static const class OSVersion { 34 public: 35 OSVersion() { 36 SysInfo::OperatingSystemVersionNumbers( 37 ¤t_version_[0], ¤t_version_[1], ¤t_version_[2]); 38 } 39 40 bool IsRunningOnOrLater(int32_t version[3]) const { 41 for (size_t i = 0; i < std::size(current_version_); ++i) { 42 if (current_version_[i] != version[i]) 43 return current_version_[i] > version[i]; 44 } 45 return true; 46 } 47 48 private: 49 int32_t current_version_[3]; 50 } kOSVersion; 51 52 int32_t version[3] = {major, minor, bug_fix}; 53 return kOSVersion.IsRunningOnOrLater(version); 54} 55 56bool IsInForcedRTL() { 57 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; 58 return [defaults boolForKey:@"NSForceRightToLeftWritingDirection"]; 59} 60 61void OverridePathOfEmbeddedICU(const char* path) { 62 DCHECK(!g_icudtl_path_override); 63 g_icudtl_path_override = new std::string(path); 64} 65 66FilePath FilePathOfEmbeddedICU() { 67 if (g_icudtl_path_override) { 68 return FilePath(*g_icudtl_path_override); 69 } 70 return FilePath(); 71} 72 73#if !BUILDFLAG(IS_IOS_APP_EXTENSION) 74bool IsMultipleScenesSupported() { 75 if (@available(iOS 13, *)) { 76 return UIApplication.sharedApplication.supportsMultipleScenes; 77 } 78 return false; 79} 80#endif 81 82bool IsApplicationPreWarmed() { 83 return [NSProcessInfo.processInfo.environment objectForKey:@"ActivePrewarm"]; 84} 85 86} // namespace base::ios 87