QNSystem.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // QNSystem.m
  3. // QiniuSDK
  4. //
  5. // Created by bailong on 15/10/13.
  6. // Copyright © 2015年 Qiniu. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #if __IPHONE_OS_VERSION_MIN_REQUIRED
  10. #import <MobileCoreServices/MobileCoreServices.h>
  11. #import <UIKit/UIKit.h>
  12. #else
  13. #import <CoreServices/CoreServices.h>
  14. #endif
  15. BOOL hasNSURLSession() {
  16. #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED)
  17. float sysVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
  18. if (sysVersion < 7.0) {
  19. return NO;
  20. }
  21. #else
  22. NSOperatingSystemVersion sysVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
  23. if (sysVersion.majorVersion < 10) {
  24. return NO;
  25. } else if (sysVersion.majorVersion == 10) {
  26. return sysVersion.minorVersion >= 9;
  27. }
  28. #endif
  29. return YES;
  30. }
  31. BOOL hasAts() {
  32. #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED)
  33. float sysVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
  34. if (sysVersion < 9.0) {
  35. return NO;
  36. }
  37. #else
  38. NSOperatingSystemVersion sysVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
  39. if (sysVersion.majorVersion < 10) {
  40. return NO;
  41. } else if (sysVersion.majorVersion == 10) {
  42. return sysVersion.minorVersion >= 11;
  43. }
  44. #endif
  45. return YES;
  46. }
  47. BOOL allowsArbitraryLoads() {
  48. if (!hasAts()) {
  49. return YES;
  50. }
  51. // for unit test
  52. NSDictionary* d = [[NSBundle mainBundle] infoDictionary];
  53. if (d == nil || d.count == 0) {
  54. return YES;
  55. }
  56. NSDictionary* sec = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSAppTransportSecurity"];
  57. if (sec == nil) {
  58. return NO;
  59. }
  60. NSNumber* ats = [sec objectForKey:@"NSAllowsArbitraryLoads"];
  61. if (ats == nil) {
  62. return NO;
  63. }
  64. return ats.boolValue;
  65. }
  66. BOOL isIpV6FullySupported() {
  67. #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED)
  68. float sysVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
  69. if (sysVersion < 9.0) {
  70. return NO;
  71. }
  72. #else
  73. NSOperatingSystemVersion sysVersion = [[NSProcessInfo processInfo] operatingSystemVersion];
  74. if (sysVersion.majorVersion < 10) {
  75. return NO;
  76. } else if (sysVersion.majorVersion == 10) {
  77. return sysVersion.minorVersion >= 11;
  78. }
  79. #endif
  80. return YES;
  81. }