Util.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // Util.m
  3. // Miaxis
  4. //
  5. // Created by tongjun on 14-3-5.
  6. // Copyright (c) 2014年 tongjun. All rights reserved.
  7. //
  8. #import "Util.h"
  9. #import <RealReachability/RealReachability.h>
  10. @implementation Util
  11. //判断网络是否连接
  12. + (BOOL) connectedToNetWork{
  13. [GLobalRealReachability startNotifier];
  14. ReachabilityStatus status = [GLobalRealReachability currentReachabilityStatus];
  15. [GLobalRealReachability stopNotifier];
  16. return status ? YES : NO;
  17. //需要确保该host地址可以被ping探测到。此操作为可选,默认的目标host地址为www.baidu.com
  18. //GLobalRealReachability.hostForPing = @"www.baidu.com";
  19. //手动设置自动探测间隔(autoCheckInterval,单位为分钟).此处根据应用的实时性要求来设置自动探测的间隔,实时性要求较高时可适当调低此参数,但不建议设置为1.0以下
  20. //GLobalRealReachability.autoCheckInterval = 2.0f;
  21. //----------------------------这一块先埋伏在这里吧-----------------------@lee
  22. // [GLobalRealReachability reachabilityWithBlock:^(ReachabilityStatus status)
  23. // {
  24. // switch (status)
  25. // {
  26. // case RealStatusUnknown:
  27. // {
  28. // //NSLog(@"Unknown");
  29. // break;
  30. // }
  31. //
  32. // case RealStatusNotReachable:
  33. // {
  34. // //NSLog(@"NotReachable");
  35. // break;
  36. // }
  37. //
  38. // case RealStatusViaWiFi:
  39. // {
  40. // //NSLog(@"wifi");
  41. // break;
  42. // }
  43. //
  44. // case RealStatusViaWWAN:
  45. // {
  46. // //NSLog(@"ViaWWAN");
  47. // WWANAccessType accessType = [GLobalRealReachability currentWWANtype];
  48. // if (accessType == WWANType2G)
  49. // {
  50. // //NSLog(@"RealReachabilityStatus2G");
  51. // }
  52. // else if (accessType == WWANType3G)
  53. // {
  54. // //NSLog(@"RealReachabilityStatus3G");
  55. // }
  56. // else if (accessType == WWANType4G)
  57. // {
  58. // //NSLog(@"RealReachabilityStatus4G");
  59. // }
  60. // else
  61. // {
  62. // //NSLog(@"Unknown RealReachability WWAN Status, might be iOS6");
  63. // }
  64. //
  65. //
  66. // break;
  67. // }
  68. // default:
  69. // break;
  70. // }
  71. // }];
  72. }
  73. +(NSString *)getAnswerByTen:(NSInteger)value
  74. {
  75. NSMutableString *string = [NSMutableString string];
  76. while (value)
  77. {
  78. [string insertString:(value & 1)? @"1": @"0" atIndex:0];
  79. value /= 2;
  80. }
  81. if (string.length==5) {
  82. string=[NSMutableString stringWithFormat:@"000%@",string];
  83. }else if(string.length==6){
  84. string=[NSMutableString stringWithFormat:@"00%@",string];
  85. }else if(string.length==7){
  86. string=[NSMutableString stringWithFormat:@"0%@",string];
  87. }else{
  88. string=string;
  89. }
  90. NSMutableString *answer=[[NSMutableString alloc]init];
  91. if (string.length >= 5) {
  92. if ([[string substringWithRange:NSMakeRange(3, 1)]intValue]==1) {
  93. [answer appendString:@"A"];
  94. }
  95. }
  96. if (string.length >= 4) {
  97. if ([[string substringWithRange:NSMakeRange(2, 1)]intValue]==1) {
  98. [answer appendString:@"B"];
  99. }
  100. }
  101. if (string.length >= 3) {
  102. if ([[string substringWithRange:NSMakeRange(1, 1)]intValue]==1) {
  103. [answer appendString:@"C"];
  104. }
  105. }
  106. if (string.length >= 2) {
  107. if ([[string substringWithRange:NSMakeRange(0, 1)]intValue]==1) {
  108. [answer appendString:@"D"];
  109. }
  110. }
  111. return [answer copy];
  112. }
  113. @end