UIDevice+VLC.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*****************************************************************************
  2. * UIDevice+VLC
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2017 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Carola Nitz <caro # videolan.org>
  10. *
  11. * Refer to the COPYING file of the official project for license.
  12. *****************************************************************************/
  13. #import "UIDevice+VLC.h"
  14. #import <sys/sysctl.h> // for sysctlbyname
  15. @implementation UIDevice (VLC)
  16. - (NSNumber *)VLCFreeDiskSpace
  17. {
  18. NSNumber *totalSpace;
  19. NSNumber *totalFreeSpace;
  20. NSError *error = nil;
  21. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  22. NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
  23. if (!error) {
  24. totalSpace = [dictionary objectForKey:NSFileSystemSize];
  25. totalFreeSpace = [dictionary objectForKey:NSFileSystemFreeSize];
  26. NSString *totalSize = [NSByteCountFormatter stringFromByteCount:[totalSpace longLongValue] countStyle:NSByteCountFormatterCountStyleFile];
  27. NSString *totalFreeSize = [NSByteCountFormatter stringFromByteCount:[totalFreeSpace longLongValue] countStyle:NSByteCountFormatterCountStyleFile];
  28. APLog(@"Memory Capacity of %@ with %@ Free memory available.", totalSize, totalFreeSize);
  29. } else
  30. APLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %ld", [error domain], (long)[error code]);
  31. return totalFreeSpace;
  32. }
  33. - (BOOL)VLCHasExternalDisplay
  34. {
  35. return ([[UIScreen screens] count] > 1);
  36. }
  37. - (BOOL)isiPhoneX
  38. {
  39. static BOOL isiPhoneX = NO;
  40. static dispatch_once_t onceToken;
  41. dispatch_once(&onceToken, ^{
  42. #if TARGET_IPHONE_SIMULATOR
  43. NSString *model = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"];
  44. #else
  45. struct utsname systemInfo;
  46. uname(&systemInfo);
  47. NSString *model = [NSString stringWithCString:systemInfo.machine
  48. encoding:NSUTF8StringEncoding];
  49. #endif
  50. isiPhoneX = [model isEqualToString:@"iPhone10,3"] || [model isEqualToString:@"iPhone10,6"];
  51. });
  52. return isiPhoneX;
  53. }
  54. @end