AutorÃa | Ultima modificación | Ver Log |
// Copyright 2019 Google//// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.#include "Crashlytics/Shared/FIRCLSFABHost.h"#if TARGET_OS_WATCH#import <WatchKit/WatchKit.h>#elif TARGET_OS_IPHONE#import <UIKit/UIKit.h>#endif#include <sys/sysctl.h>#define FIRCLS_HOST_SYSCTL_BUFFER_SIZE (128)#pragma mark - OS Versions#pragma mark Privatestatic NSString *FIRCLSHostSysctlEntry(const char *sysctlKey) {char buffer[FIRCLS_HOST_SYSCTL_BUFFER_SIZE];size_t bufferSize = FIRCLS_HOST_SYSCTL_BUFFER_SIZE;if (sysctlbyname(sysctlKey, buffer, &bufferSize, NULL, 0) != 0) {return nil;}return [NSString stringWithUTF8String:buffer];}#pragma mark PublicNSOperatingSystemVersion FIRCLSHostGetOSVersion(void) {// works on macos(10.10), ios(8.0), watchos(2.0), tvos(9.0)if ([NSProcessInfo.processInfo respondsToSelector:@selector(operatingSystemVersion)]) {return [NSProcessInfo.processInfo operatingSystemVersion];}NSOperatingSystemVersion version = {0, 0, 0};#if TARGET_OS_IPHONE#if TARGET_OS_WATCHNSString *versionString = [[WKInterfaceDevice currentDevice] systemVersion];#elseNSString *versionString = [[UIDevice currentDevice] systemVersion];#endifNSArray *parts = [versionString componentsSeparatedByString:@"."];if (parts.count > 0) {version.majorVersion = [[parts objectAtIndex:0] integerValue];}if ([parts count] > 1) {version.minorVersion = [[parts objectAtIndex:1] integerValue];}if ([parts count] > 2) {version.patchVersion = [[parts objectAtIndex:2] integerValue];}#endifreturn version;}NSString *FIRCLSHostOSBuildVersion(void) {return FIRCLSHostSysctlEntry("kern.osversion");}NSString *FIRCLSHostOSDisplayVersion(void) {NSOperatingSystemVersion version = FIRCLSHostGetOSVersion();return [NSString stringWithFormat:@"%ld.%ld.%ld", (long)version.majorVersion,(long)version.minorVersion, (long)version.patchVersion];}#pragma mark - Host Models#pragma mark PublicNSString *FIRCLSHostModelInfo(void) {NSString *model = nil;#if TARGET_OS_SIMULATOR#if TARGET_OS_WATCHmodel = @"watchOS Simulator";#elif TARGET_OS_TVmodel = @"tvOS Simulator";#elif TARGET_OS_IPHONEswitch ([[UIDevice currentDevice] userInterfaceIdiom]) {case UIUserInterfaceIdiomPhone:model = @"iOS Simulator (iPhone)";break;case UIUserInterfaceIdiomPad:model = @"iOS Simulator (iPad)";break;default:model = @"iOS Simulator (Unknown)";break;}#endif#elif TARGET_OS_EMBEDDEDmodel = FIRCLSHostSysctlEntry("hw.machine");#elsemodel = FIRCLSHostSysctlEntry("hw.model");#endifreturn model;}