diff --git a/Sources/Core/Platform/PlatformInfoDelegator.hpp b/Sources/Core/Platform/PlatformInfoDelegator.hpp index 27182b0..46ecec7 100644 --- a/Sources/Core/Platform/PlatformInfoDelegator.hpp +++ b/Sources/Core/Platform/PlatformInfoDelegator.hpp @@ -16,9 +16,15 @@ namespace platform { class PlatformInfoDelegator : public interface::PlatformInfoDelegator { public: + PlatformInfoDelegator(); + ~PlatformInfoDelegator(); std::string GetPlatform() const override; std::string GetOsInfo() const override; std::string GetModelName() const override; + std::string GetSdkVersion() const override; +private: + class Impl; + std::unique_ptr impl_; }; } // namespace platform diff --git a/Sources/Core/Platform/PlatformInfoDelegator.mm b/Sources/Core/Platform/PlatformInfoDelegator.mm index b006b5b..f780449 100644 --- a/Sources/Core/Platform/PlatformInfoDelegator.mm +++ b/Sources/Core/Platform/PlatformInfoDelegator.mm @@ -12,25 +12,72 @@ #import #include "NSString+StdString.h" +#include "skyway/global/interface/logger.hpp" + +@interface PlatformDelegator : NSObject + +@property(nonatomic, readonly) NSString* platform; +@property(nonatomic, readonly) NSString* osInfo; +@property(nonatomic, readonly) NSString* modelName; +@property(nonatomic, readonly) NSString* sdkVersion; + +- (id)init; + +@end + +@implementation PlatformDelegator + +- (id)init { + if (self = [super init]) { + _platform = @"ios"; + + // os + NSString* systemName = [UIDevice currentDevice].systemName; + NSString* systemVersion = [UIDevice currentDevice].systemVersion; + _osInfo = [NSString stringWithFormat:@"%@ %@", systemName, systemVersion]; + + // model + struct utsname systemInfo; + uname(&systemInfo); + _modelName = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; + + // sdk version + NSBundle* bundle = [NSBundle bundleForClass:self.class]; + _sdkVersion = [bundle infoDictionary][@"CFBundleShortVersionString"]; + } + return self; +} + +@end namespace skyway { namespace platform { -std::string PlatformInfoDelegator::GetPlatform() const { return "ios"; } +class PlatformInfoDelegator::Impl { +public: + Impl() : delegator_([[PlatformDelegator alloc] init]) {} + PlatformDelegator* delegator_; +}; + +PlatformInfoDelegator::PlatformInfoDelegator() + : impl_(std::make_unique()) {} + +PlatformInfoDelegator::~PlatformInfoDelegator(){SKW_TRACE("~PlatformInfoDelegator")} + +std::string PlatformInfoDelegator::GetPlatform() const { + return [NSString stdStringForString:impl_->delegator_.platform]; +} std::string PlatformInfoDelegator::GetOsInfo() const { - NSString* systemName = [UIDevice currentDevice].systemName; - NSString* systemVersion = [UIDevice currentDevice].systemVersion; - NSString* osInfo = [NSString stringWithFormat:@"%@ %@", systemName, systemVersion]; - return [NSString stdStringForString:osInfo]; + return [NSString stdStringForString:impl_->delegator_.osInfo]; } std::string PlatformInfoDelegator::GetModelName() const { - struct utsname systemInfo; - uname(&systemInfo); - NSString* modelName = [NSString stringWithCString:systemInfo.machine - encoding:NSUTF8StringEncoding]; - return [NSString stdStringForString:modelName]; + return [NSString stdStringForString:impl_->delegator_.modelName]; +} + +std::string PlatformInfoDelegator::GetSdkVersion() const { + return [NSString stdStringForString:impl_->delegator_.sdkVersion]; } } // namespace platform