|
@@ -7,8 +7,7 @@
|
|
//
|
|
//
|
|
|
|
|
|
#import "MYFactoryManager.h"
|
|
#import "MYFactoryManager.h"
|
|
-#import <SystemConfiguration/CaptiveNetwork.h>//get ssid
|
|
|
|
-#import <CommonCrypto/CommonDigest.h>//get MD5
|
|
|
|
|
|
+
|
|
|
|
|
|
@interface MYFactoryManager ()
|
|
@interface MYFactoryManager ()
|
|
@end
|
|
@end
|
|
@@ -49,34 +48,6 @@ static MYFactoryManager * instance;
|
|
view.layer.masksToBounds = YES;
|
|
view.layer.masksToBounds = YES;
|
|
}
|
|
}
|
|
|
|
|
|
-//计算高度
|
|
|
|
-+ (CGFloat)heightForString:(NSString *)string fontSize:(CGFloat)fontSize andWidth:(CGFloat)width{
|
|
|
|
-
|
|
|
|
- if (string != nil&&![string isKindOfClass:[NSNull class]]){
|
|
|
|
-
|
|
|
|
- CGRect rect = [string boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil];
|
|
|
|
- return rect.size.height;
|
|
|
|
-
|
|
|
|
- }else{
|
|
|
|
-
|
|
|
|
- return 20;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//计算文本宽度
|
|
|
|
-+ (CGFloat)widthForString:(NSString *)string fontSize:(CGFloat)fontSize andHeight:(CGFloat)height{
|
|
|
|
-
|
|
|
|
- if (string != nil&&![string isKindOfClass:[NSNull class]]){
|
|
|
|
-
|
|
|
|
- CGRect rect = [string boundingRectWithSize:CGSizeMake(MAXFLOAT, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil];
|
|
|
|
- return rect.size.width;
|
|
|
|
-
|
|
|
|
- }else{
|
|
|
|
- return 50;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
|
|
//正常加载还是打包后sdk加载
|
|
//正常加载还是打包后sdk加载
|
|
+(UIImage*)imageString:(NSString*)imageName{
|
|
+(UIImage*)imageString:(NSString*)imageName{
|
|
@@ -95,1304 +66,24 @@ static MYFactoryManager * instance;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-#pragma mark ------ 发送app group通知
|
|
|
|
-+ (void)postGroupCFNotificaiton:(NSString*)string{
|
|
|
|
-
|
|
|
|
- NSString * notificaitonName = @"OPEN_NOTIFICATION";
|
|
|
|
- CFStringRef strRef = (__bridge CFStringRef)notificaitonName;
|
|
|
|
- CFNotificationCenterRef notification = CFNotificationCenterGetDarwinNotifyCenter ();
|
|
|
|
- //第一种生成参数方法 测试无效
|
|
|
|
-// NSDictionary * ocDict = @{@"key":@"123"};
|
|
|
|
-// CFDictionaryRef dicRef = (__bridge CFDictionaryRef)ocDict;
|
|
|
|
- //第二种 共享沙河数据
|
|
|
|
- NSUserDefaults* userDefault = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.Oujia.AppAndGame"];
|
|
|
|
- [userDefault setObject:string forKey:@"type"];//主副设备 断开的type
|
|
|
|
- [userDefault synchronize];
|
|
|
|
- //之后发送通知
|
|
|
|
- CFNotificationCenterPostNotification(notification, strRef, NULL,nil, YES);
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-#pragma mark -- leon add
|
|
|
|
--(void)comeToBackgroundMode{
|
|
|
|
- //初始化一个后台任务BackgroundTask,这个后台任务的作用就是告诉系统当前app在后台有任务处理,需要时间
|
|
|
|
- UIApplication*app = [UIApplication sharedApplication];
|
|
|
|
- self.bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
|
|
|
|
- [app endBackgroundTask:self.bgTask];
|
|
|
|
- self.bgTask = UIBackgroundTaskInvalid;
|
|
|
|
- }];
|
|
|
|
- //开启定时器 不断向系统请求后台任务执行的时间
|
|
|
|
- NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(applyForMoreTime) userInfo:nil repeats:YES];
|
|
|
|
- [timer fire];
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
--(void)applyForMoreTime{
|
|
|
|
-
|
|
|
|
- //如果系统给的剩余时间小于60秒 就终止当前的后台任务,再重新初始化一个后台任务,重新让系统分配时间,这样一直循环下去,保持APP在后台一直处于active状态。
|
|
|
|
- if ([UIApplication sharedApplication].backgroundTimeRemaining < 30){
|
|
|
|
- [[UIApplication sharedApplication] endBackgroundTask:self.bgTask];
|
|
|
|
- self.bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
|
|
|
|
- [[UIApplication sharedApplication] endBackgroundTask:self.bgTask];
|
|
|
|
- self.bgTask = UIBackgroundTaskInvalid;
|
|
|
|
- }];
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//获取getUserInfo
|
|
|
|
-+(NSString*)getUserInfo{
|
|
|
|
- NSDictionary * jsonDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
|
|
|
|
- NSDictionary * user = jsonDict[@"user"];
|
|
|
|
- if ([user isKindOfClass:[NSNull class]] || user == nil || [user isEqual:[NSNull null]]){
|
|
|
|
- return @"";
|
|
|
|
- }else{
|
|
|
|
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:user options:NSJSONWritingPrettyPrinted error:nil];
|
|
|
|
- NSString * userJsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
- return userJsonString;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//获取token
|
|
|
|
-+(NSString*)getToken{
|
|
|
|
- NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
|
|
|
|
- NSString * token = [urlDict objectForKey:@"token"];
|
|
|
|
- if ([token isKindOfClass:[NSNull class]] || token == nil || [token isEqual:[NSNull null]]){
|
|
|
|
- [PopupView showCusHUDA:@"获取token失败,请从趣动启动"];
|
|
|
|
- return @"";
|
|
|
|
- }else{
|
|
|
|
- return token;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//获取缓存game_id
|
|
|
|
-+(NSString*)getGameId{
|
|
|
|
- NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
|
|
|
|
- NSString * game_id = [urlDict objectForKey:@"game_id"];
|
|
|
|
- if ([game_id isKindOfClass:[NSNull class]] || game_id == nil || [game_id isEqual:[NSNull null]]){
|
|
|
|
- [PopupView showCusHUDA:@"获取id失败,请从趣动启动"];
|
|
|
|
- return @"";
|
|
|
|
- }else{
|
|
|
|
- return game_id;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//获取缓存game_type
|
|
|
|
-+(NSString*)getGameType{
|
|
|
|
- NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
|
|
|
|
- NSString * game_type = [urlDict objectForKey:@"game_type"];
|
|
|
|
- if ([game_type isKindOfClass:[NSNull class]] || game_type == nil || [game_type isEqual:[NSNull null]]){
|
|
|
|
- [PopupView showCusHUDA:@"获取type失败,请从趣动启动"];
|
|
|
|
- return @"";
|
|
|
|
- }else{
|
|
|
|
- return game_type;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//获取缓存mac
|
|
|
|
-+(NSString*)getGameMac{
|
|
|
|
- NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
|
|
|
|
- NSString * mac = [urlDict objectForKey:@"mac"];
|
|
|
|
- if ([mac isKindOfClass:[NSNull class]] || mac == nil || [mac isEqual:[NSNull null]]){
|
|
|
|
-// [PopupView showCusHUDA:@"获取mac失败,请从趣动启动"];
|
|
|
|
- return @"";
|
|
|
|
- }else{
|
|
|
|
- return mac;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-//获取缓存邀请信息
|
|
|
|
-+(NSString*)getInviteUser{
|
|
|
|
- NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
|
|
|
|
- NSDictionary * invite = urlDict[@"invite"];
|
|
|
|
- if ([invite isKindOfClass:[NSNull class]] || invite == nil || [invite isEqual:[NSNull null]]){
|
|
|
|
-// [PopupView showCusHUDA:@"获取getInviteUser失败,请从趣动启动"];
|
|
|
|
- return @"";
|
|
|
|
- }else{
|
|
|
|
- //user字典 -> 字符串 -> Char
|
|
|
|
- NSDictionary * user = [invite objectForKey:@"user"];
|
|
|
|
- NSData * userData = [NSJSONSerialization dataWithJSONObject:user options:NSJSONWritingPrettyPrinted error:nil];
|
|
|
|
- NSString * userString = [[NSString alloc] initWithData:userData encoding:NSUTF8StringEncoding];
|
|
|
|
- return userString;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-+(NSString*)getInviteInfo{
|
|
|
|
-
|
|
|
|
- NSDictionary * urlDict = [IOS_NSUSERDEFAULT objectForKey:IOSSDK_USERINFO];
|
|
|
|
- NSDictionary * invite = urlDict[@"invite"];
|
|
|
|
- if ([invite isKindOfClass:[NSNull class]] || invite == nil || [invite isEqual:[NSNull null]]){
|
|
|
|
-// [PopupView showCusHUDA:@"获取邀请信息失败,请从趣动启动"];
|
|
|
|
- return @"";
|
|
|
|
- }else{
|
|
|
|
- NSString * info = [invite objectForKey:@"info"];
|
|
|
|
- return info;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-//加载xib
|
|
|
|
-- (void)tableViewRegisterNib{
|
|
|
|
-
|
|
|
|
-// BOOL ifSdk = NO;
|
|
|
|
-// if (ifSdk){
|
|
|
|
-// NSBundle *bkBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"IOSToUnityBundle" ofType:@"bundle"]];
|
|
|
|
-// [self.tableView registerNib:[UINib nibWithNibName:@"PeripheralCell" bundle:bkBundle] forCellReuseIdentifier:@"PeripheralCell"];
|
|
|
|
-// }else{
|
|
|
|
-// [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([PeripheralCell class]) bundle:nil] forCellReuseIdentifier:@"PeripheralCell"];
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-////倒计时
|
|
|
|
-//+ (void)countdownWith:(UIButton *)but{
|
|
|
|
-//
|
|
|
|
-// __block int timeout=59; //倒计时时间
|
|
|
|
-// dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
|
|
|
-// dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
|
|
|
|
-// dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
|
|
|
|
-// dispatch_source_set_event_handler(_timer, ^{
|
|
|
|
-// if(timeout<=0){ //倒计时结束,关闭
|
|
|
|
-// dispatch_source_cancel(_timer);
|
|
|
|
-// dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
-// //设置界面的按钮显示 根据自己需求设置
|
|
|
|
-// //设置按钮的样式
|
|
|
|
-// but.titleLabel.font = [UIFont systemFontOfSize:10];
|
|
|
|
-// [but setTitle:@"发送验证码" forState:UIControlStateNormal];
|
|
|
|
-// [but setTitleColor:[UIColor colorWithHexString:@"#BABBBB"] forState:(UIControlStateNormal)];
|
|
|
|
-// but.userInteractionEnabled = YES;
|
|
|
|
-// });
|
|
|
|
-// }else{
|
|
|
|
-//
|
|
|
|
-// int seconds = timeout % 60;
|
|
|
|
-// NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
|
|
|
|
-// dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
-// //设置界面的按钮显示 根据自己需求设置
|
|
|
|
-// but.titleLabel.font = [UIFont systemFontOfSize:10];
|
|
|
|
-// [but setTitle:[NSString stringWithFormat:@"重新发送(%@)",strTime] forState:UIControlStateNormal];
|
|
|
|
-// [but setTitleColor:[UIColor colorWithHexString:@"#BABBBB"] forState:(UIControlStateNormal)];
|
|
|
|
-// but.userInteractionEnabled = NO;
|
|
|
|
-//
|
|
|
|
-// });
|
|
|
|
-// timeout--;
|
|
|
|
-// }
|
|
|
|
-// });
|
|
|
|
-// dispatch_resume(_timer);
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark ---------------------------------------------------------------- 参数判断
|
|
|
|
-////网络链接状态
|
|
|
|
-//+(bool)internetStatus{
|
|
|
|
-//
|
|
|
|
-// Reachability * reachability = [Reachability reachabilityWithHostName:@"www.apple.com"];
|
|
|
|
-// NetworkStatus internetStatus = [reachability currentReachabilityStatus];
|
|
|
|
-// bool net = NO;
|
|
|
|
-// switch (internetStatus){
|
|
|
|
-// case ReachableViaWiFi:
|
|
|
|
-// net = YES;
|
|
|
|
-// break;
|
|
|
|
-// case ReachableViaWWAN:
|
|
|
|
-// net = YES;
|
|
|
|
-// break;
|
|
|
|
-// case NotReachable:
|
|
|
|
-// net = NO;
|
|
|
|
-// [MBProgressHUD showTextMessage:@"当前无网络连接,请检查网络配置!"];
|
|
|
|
-// default:
|
|
|
|
-// break;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// return net;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//+(BOOL)ifLoogIn:(BOOL)tip{
|
|
|
|
-//
|
|
|
|
-// UserInfoModel * userModel = [UserInfoModel getUserInfoModelFormLocal];
|
|
|
|
-// AccessTokenInfo * token = [AccessTokenInfo getAccessTokenModelFormLocal];
|
|
|
|
-// //9aafc5e3-5910-433c-b33c-3e85b1ec8917
|
|
|
|
-// if (userModel.uuid.length!=16||userModel==nil||token.access_token.length!=36||token==nil){//未登录
|
|
|
|
-//
|
|
|
|
-// if (tip == YES){
|
|
|
|
-// [MBProgressHUD showTextMessage:MyLocalizedString(@"Use Smart series equipment, please log in first!")];
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// return NO;
|
|
|
|
-//
|
|
|
|
-// }else{
|
|
|
|
-//
|
|
|
|
-// return YES;
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//#pragma mark ---------------------------------------------------------------- 各类弹窗
|
|
|
|
-////其他网络 提示用户切换网络为luftmed
|
|
|
|
-//+(void)popChooseSSIDListViewController{
|
|
|
|
-//
|
|
|
|
-// //链接失败毛玻璃效果
|
|
|
|
-// PopToSystemViewController * visualEffecVC = [PopToSystemViewController new];
|
|
|
|
-//
|
|
|
|
-// visualEffecVC.closeTask = ^{
|
|
|
|
-//
|
|
|
|
-// NSString * urlStr = [kDefaults objectForKey:@"simulation_api"];
|
|
|
|
-//
|
|
|
|
-// if (urlStr.length<=0){
|
|
|
|
-// urlStr = UIApplicationOpenSettingsURLString;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlStr]]){
|
|
|
|
-//
|
|
|
|
-// if (iOS10){
|
|
|
|
-//
|
|
|
|
-// //iOS10.0以上 使用的操作
|
|
|
|
-// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr] options:@{} completionHandler:nil];
|
|
|
|
-//
|
|
|
|
-// }else{
|
|
|
|
-//
|
|
|
|
-// //iOS10.0以下 使用的操作
|
|
|
|
-// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// };
|
|
|
|
-//
|
|
|
|
-// [[UIApplication sharedApplication].keyWindow addSubview:visualEffecVC.view];
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//#pragma mark ---------------------------------------------------------------- 系统授权类
|
|
|
|
-////申请摄像头授权
|
|
|
|
-//+(BOOL)authorizationCarmen{
|
|
|
|
-//
|
|
|
|
-// NSString *mediaType = AVMediaTypeVideo;
|
|
|
|
-// AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
|
|
|
|
-// if(authStatus ==AVAuthorizationStatusRestricted){
|
|
|
|
-// NSLog(@"Restricted");
|
|
|
|
-// return NO;
|
|
|
|
-//
|
|
|
|
-// }else if(authStatus == AVAuthorizationStatusDenied){
|
|
|
|
-// NSLog(@"Denied");
|
|
|
|
-// //应该是这个,如果不允许的话
|
|
|
|
-// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:MyLocalizedString(@"Tip")
|
|
|
|
-// message:MyLocalizedString(@"Please allow access to the camera in the device \" settings privacy camera -Luftmed\"")
|
|
|
|
-// delegate:self
|
|
|
|
-// cancelButtonTitle:MyLocalizedString(@"Confirm")
|
|
|
|
-// otherButtonTitles:nil];
|
|
|
|
-// [alert show];
|
|
|
|
-// return NO;
|
|
|
|
-//
|
|
|
|
-// }else if(authStatus == AVAuthorizationStatusAuthorized){//允许访问
|
|
|
|
-//
|
|
|
|
-// NSLog(@"Authorized");
|
|
|
|
-// return YES;
|
|
|
|
-//
|
|
|
|
-// }else if(authStatus == AVAuthorizationStatusNotDetermined){
|
|
|
|
-//
|
|
|
|
-// [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
|
|
|
|
-// if(granted){//点击允许访问时调用
|
|
|
|
-//
|
|
|
|
-// //用户明确许可与否,媒体需要捕获,但用户尚未授予或拒绝许可。
|
|
|
|
-// NSLog(@"Granted access to %@", mediaType);
|
|
|
|
-//
|
|
|
|
-// }else{
|
|
|
|
-//
|
|
|
|
-// NSLog(@"Not granted access to %@", mediaType);
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// }];
|
|
|
|
-//
|
|
|
|
-// return NO;
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// return NO;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//#pragma mark ---------------------------------------------------------------- 正则
|
|
|
|
-//+ (BOOL)phoneNum:(NSString *)mobileNum{
|
|
|
|
-//
|
|
|
|
-// if (mobileNum.length != 11){
|
|
|
|
-// return NO;
|
|
|
|
-// }
|
|
|
|
-// /**
|
|
|
|
-// * 手机号码:
|
|
|
|
-// * 13[0-9], 14[5,7], 15[0, 1, 2, 3, 5, 6, 7, 8, 9], 17[0, 1, 6, 7, 8], 18[0-9]
|
|
|
|
-// * 移动号段: 134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188
|
|
|
|
-// * 联通号段: 130,131,132,145,155,156,170,171,172,175,176,185,186
|
|
|
|
-// * 电信号段: 133,149,153,170,173,177,180,181,189
|
|
|
|
-// */
|
|
|
|
-// NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|7[0135678]|8[0-9])\\d{8}$";
|
|
|
|
-// /**
|
|
|
|
-// * 中国移动:China Mobile
|
|
|
|
-// * 134,135,136,137,138,139,147,150,151,152,157,158,159,170,178,182,183,184,187,188
|
|
|
|
-// */
|
|
|
|
-// NSString *CM = @"(^1(3[4-9]|4[7]|5[0-27-9]|7[08]|8[2-478])\\d{8}$";
|
|
|
|
-// /**
|
|
|
|
-// * 中国联通:China Unicom
|
|
|
|
-// * 130,131,132,145,155,156,170,171,172,175,176,185,186
|
|
|
|
-// */
|
|
|
|
-// NSString *CU = @"(^1(3[0-2]|4[5]|5[56]|701256||8[56])\\d{8}$";
|
|
|
|
-// /**
|
|
|
|
-// * 中国电信:China Telecom
|
|
|
|
-// * 133,149,153,170,173,177,180,181,189
|
|
|
|
-// */
|
|
|
|
-// NSString *CT = @"^1(3[3]|4[9]|53|7[037]|8[019])\\d{8}$";
|
|
|
|
-// NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
|
|
|
|
-// NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
|
|
|
|
-// NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
|
|
|
|
-// NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
|
|
|
|
-//
|
|
|
|
-// if (([regextestmobile evaluateWithObject:mobileNum] == YES)
|
|
|
|
-// || ([regextestcm evaluateWithObject:mobileNum] == YES)
|
|
|
|
-// || ([regextestct evaluateWithObject:mobileNum] == YES)
|
|
|
|
-// || ([regextestcu evaluateWithObject:mobileNum] == YES))
|
|
|
|
-// {
|
|
|
|
-// return YES;
|
|
|
|
-//
|
|
|
|
-// }else{
|
|
|
|
-//
|
|
|
|
-// return NO;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-////获取部分显示手机格式
|
|
|
|
-//+ (NSString *)getPhoneText:(NSString *)phoneNum {
|
|
|
|
-// NSString *headStr = [phoneNum substringToIndex:3];//截取掉下标2之前的字符串
|
|
|
|
-// NSString *backStr = [phoneNum substringFromIndex:7];//截取掉下标6之后的字符串
|
|
|
|
-// return [NSString stringWithFormat:@"%@****%@",headStr,backStr];
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark - ***** 检测是否为邮箱
|
|
|
|
-//+ (BOOL)emailNum:(NSString *)emailStr{
|
|
|
|
-//
|
|
|
|
-// NSString *pattern = @"^[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$";
|
|
|
|
-// NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:pattern options:0 error:nil];
|
|
|
|
-// NSArray *results = [regex matchesInString:emailStr options:0 range:NSMakeRange(0, emailStr.length)];
|
|
|
|
-// return results.count > 0;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark ---------------------------------------------------------------- 字符串转字典与字典转字符串
|
|
|
|
-//+ (NSDictionary *)parseJSONStringToNSDictionary:(NSString *)JSONString {
|
|
|
|
-// NSData *JSONData = [JSONString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
-// NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableContainers error:nil];
|
|
|
|
-// return responseJSON;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//+ (NSArray *)parseJSONStringToNSArray:(NSString *)JSONString {
|
|
|
|
-// NSData *JSONData = [JSONString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
-// NSArray *responseJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableContainers error:nil];
|
|
|
|
-// return responseJSON;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//+ (NSString*)arrayToJson:(NSArray *)arr
|
|
|
|
-//{
|
|
|
|
-// NSError *parseError = nil;
|
|
|
|
-// NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:&parseError];
|
|
|
|
-// return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//+ (NSString*)dictionaryToJson:(NSDictionary *)dic{
|
|
|
|
-//
|
|
|
|
-// NSError *parseError = nil;
|
|
|
|
-// NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
|
|
|
|
-// return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//#pragma mark ---------------------------------------------------------------- 时间
|
|
|
|
-////返回当前的日期
|
|
|
|
-//+(NSString*)returnNowDateString{
|
|
|
|
-//
|
|
|
|
-// NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
|
|
|
-// // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
|
|
|
|
-// // [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
|
|
|
|
-// [formatter setDateFormat:@"yyyyMMdd"];
|
|
|
|
-// //现在时间,你可以输出来看下是什么格式
|
|
|
|
-// NSDate *datenow = [NSDate date];
|
|
|
|
-// //----------将nowDateStr按formatter格式转成nsstring
|
|
|
|
-// NSString *nowDateStr = [formatter stringFromDate:datenow];
|
|
|
|
-// NSLog(@"nowDateStr = %@",nowDateStr);
|
|
|
|
-// return nowDateStr;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-////返回当前的时间
|
|
|
|
-//+(NSString*)returnNowTimeString{
|
|
|
|
-//
|
|
|
|
-// NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
|
|
|
-// // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
|
|
|
|
-// // [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
|
|
|
|
-// [formatter setDateFormat:@"HHmmss"];
|
|
|
|
-// //现在时间,你可以输出来看下是什么格式
|
|
|
|
-// NSDate *datenow = [NSDate date];
|
|
|
|
-// //----------将nsdate按formatter格式转成nsstring
|
|
|
|
-// NSString *nowtimeStr = [formatter stringFromDate:datenow];
|
|
|
|
-// NSLog(@"nowtimeStr = %@",nowtimeStr);
|
|
|
|
-// return nowtimeStr;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//+ (NSString *)getStartTimeDate:(NSNumber *)dateTime format:(NSString *)format{
|
|
|
|
-// if (format == nil){
|
|
|
|
-// format = @"yyyy/MM/dd";
|
|
|
|
-// }
|
|
|
|
-// NSString *timeS = @"";
|
|
|
|
-// if ([[MYFactoryManager returnRealValue:dateTime] length] > 3){
|
|
|
|
-// timeS = [dateTime stringValue];
|
|
|
|
-// timeS = [timeS substringToIndex:timeS.length-3];
|
|
|
|
-// NSTimeInterval time= [timeS doubleValue];//因为时差问题要加8小时 == 28800 sec
|
|
|
|
-// NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
|
|
|
|
-// //实例化一个NSDateFormatter对象
|
|
|
|
-// NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
|
-// //设定时间格式,这里可以设置成自己需要的格式 @"yyyy/MM/dd"
|
|
|
|
-// [dateFormatter setDateFormat:format];
|
|
|
|
-// timeS = [dateFormatter stringFromDate: detaildate];
|
|
|
|
-// }
|
|
|
|
-// return timeS;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//+ (NSString *)getRealTime:(NSString *)dateTime format:(NSString *)format{
|
|
|
|
-//
|
|
|
|
-// if (format == nil) {
|
|
|
|
-// format = @"yyyy-MM-dd HH:mm:ss";
|
|
|
|
-// }
|
|
|
|
-// if ([[MYFactoryManager returnRealValue:dateTime] length] > 3) {
|
|
|
|
-// dateTime = [dateTime substringToIndex:dateTime.length-3];
|
|
|
|
-// NSTimeInterval time= [dateTime doubleValue];//因为时差问题要加8小时 == 28800 sec
|
|
|
|
-// NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
|
|
|
|
-// //实例化一个NSDateFormatter对象
|
|
|
|
-// NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
|
-// //设定时间格式,这里可以设置成自己需要的格式 @"yyyy/MM/dd"
|
|
|
|
-// [dateFormatter setDateFormat:format];
|
|
|
|
-// dateTime = [dateFormatter stringFromDate: detaildate];
|
|
|
|
-// }
|
|
|
|
-// return dateTime;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//+ (NSString *)returnRealValue:(id)sendValue {
|
|
|
|
-// if ([sendValue isKindOfClass:[NSNull class]] || sendValue == NULL) {
|
|
|
|
-// return @"";
|
|
|
|
-// }
|
|
|
|
-// if ([sendValue isKindOfClass:[NSNumber class]]) {
|
|
|
|
-// return [sendValue stringValue];
|
|
|
|
-// }
|
|
|
|
-// return sendValue;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-///*处理返回应该显示的时间*/
|
|
|
|
-//+ (NSString *) returnUploadTime:(NSString *)timeStr
|
|
|
|
-//{
|
|
|
|
-// NSTimeInterval time= [timeStr doubleValue];//因为时差问题要加8小时 == 28800 sec
|
|
|
|
-// NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
|
|
|
|
-// //实例化一个NSDateFormatter对象
|
|
|
|
-// NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
|
-// //设定时间格式,这里可以设置成自己需要的格式
|
|
|
|
-// [dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
|
|
|
|
-// NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
|
|
|
|
-// NSDate *datenow = [NSDate date];
|
|
|
|
-// NSDateFormatter * dm = [[NSDateFormatter alloc]init];
|
|
|
|
-// //指定输出的格式 这里格式必须是和上面定义字符串的格式相同,否则输出空
|
|
|
|
-// [dm setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
|
|
|
|
-// NSDate * newdate = [dm dateFromString:currentDateStr];
|
|
|
|
-// long dd = (long)[datenow timeIntervalSince1970] - [newdate timeIntervalSince1970];
|
|
|
|
-// NSString *timeString=@"";
|
|
|
|
-// if (dd/3600<1)
|
|
|
|
-// {
|
|
|
|
-// timeString = [NSString stringWithFormat:@"%ld", dd/60];
|
|
|
|
-// timeString=[NSString stringWithFormat:@"%@分钟前", timeString];
|
|
|
|
-// }
|
|
|
|
-// if (dd/3600>1&&dd/86400<1)
|
|
|
|
-// {
|
|
|
|
-// timeString = [NSString stringWithFormat:@"%ld", dd/3600];
|
|
|
|
-// timeString=[NSString stringWithFormat:@"%@小时前", timeString];
|
|
|
|
-// }
|
|
|
|
-// if (dd/86400>1)
|
|
|
|
-// {
|
|
|
|
-// timeString = [NSString stringWithFormat:@"%ld", dd/86400];
|
|
|
|
-// timeString=[NSString stringWithFormat:@"%@天前", timeString];
|
|
|
|
-// }
|
|
|
|
-// return timeString;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//// 返回时间戳
|
|
|
|
-//+ (NSString *)returnTimestamp:(NSString *)timeStr{
|
|
|
|
-// //实例化一个NSDateFormatter对象
|
|
|
|
-// NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
|
-// //设定时间格式,这里可以设置成自己需要的格式
|
|
|
|
-// [dateFormatter setDateFormat:@"yyyy-MM-dd"];
|
|
|
|
-// NSDate *date = [dateFormatter dateFromString:timeStr];
|
|
|
|
-// NSTimeInterval timeSp = [date timeIntervalSince1970];
|
|
|
|
-// return [NSString stringWithFormat:@"%f",timeSp];
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//#pragma mark ---------------------------------------------------------------------------------------- 勒夫曼德
|
|
|
|
-////16位MD5加密方式 16*2 =32 再截取中间16位
|
|
|
|
-//+ (NSString *)getMd5_16Bit_String:(NSString *)srcString{
|
|
|
|
-//
|
|
|
|
-// const char *cStr = [srcString UTF8String];
|
|
|
|
-// unsigned char digest[CC_MD5_DIGEST_LENGTH];
|
|
|
|
-// CC_MD5( cStr, strlen(cStr), digest );
|
|
|
|
-// NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
|
|
|
|
-// for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++){
|
|
|
|
-// [result appendFormat:@"%02x", digest[i]];
|
|
|
|
-// }
|
|
|
|
-// //32位 加密 取出来
|
|
|
|
-// NSString * result_16 = [[result substringToIndex:24] substringFromIndex:8];//即9~25位
|
|
|
|
-//
|
|
|
|
-// return [result_16 uppercaseString];
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-////将十六进制的字符串转换成NSString则可使用如下方式:
|
|
|
|
-//+ (NSString *)convertHexStrToString:(NSString *)str{
|
|
|
|
-// if (!str || [str length] == 0) {
|
|
|
|
-// return nil;
|
|
|
|
-// }
|
|
|
|
-// NSMutableData *hexData = [[NSMutableData alloc] initWithCapacity:8];
|
|
|
|
-// NSRange range;
|
|
|
|
-// if ([str length] % 2 == 0) {
|
|
|
|
-// range = NSMakeRange(0, 2);
|
|
|
|
-// } else {
|
|
|
|
-// range = NSMakeRange(0, 1);
|
|
|
|
-// }
|
|
|
|
-// for (NSInteger i = range.location; i < [str length]; i += 2) {
|
|
|
|
-// unsigned int anInt;
|
|
|
|
-// NSString *hexCharStr = [str substringWithRange:range];
|
|
|
|
-// NSScanner *scanner = [[NSScanner alloc] initWithString:hexCharStr];
|
|
|
|
-//
|
|
|
|
-// [scanner scanHexInt:&anInt];
|
|
|
|
-// NSData *entity = [[NSData alloc] initWithBytes:&anInt length:1];
|
|
|
|
-// [hexData appendData:entity];
|
|
|
|
-//
|
|
|
|
-// range.location += range.length;
|
|
|
|
-// range.length = 2;
|
|
|
|
-// }
|
|
|
|
-// NSString *string = [[NSString alloc]initWithData:hexData encoding:NSUTF8StringEncoding];
|
|
|
|
-// return string;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-////将NSString转换成十六进制的字符串则可使用如下方式:
|
|
|
|
-//+ (NSString *)convertStringToHexStr:(NSString *)str{
|
|
|
|
-// if (!str || [str length] == 0) {
|
|
|
|
-// return @"";
|
|
|
|
-// }
|
|
|
|
-// NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
-//
|
|
|
|
-// NSMutableString *string = [[NSMutableString alloc] initWithCapacity:[data length]];
|
|
|
|
-//
|
|
|
|
-// [data enumerateByteRangesUsingBlock:^(const void *bytes, NSRange byteRange, BOOL *stop) {
|
|
|
|
-// unsigned char *dataBytes = (unsigned char*)bytes;
|
|
|
|
-// for (NSInteger i = 0; i < byteRange.length; i++) {
|
|
|
|
-// NSString *hexStr = [NSString stringWithFormat:@"%x", (dataBytes[i]) & 0xff];
|
|
|
|
-// if ([hexStr length] == 2) {
|
|
|
|
-// [string appendString:hexStr];
|
|
|
|
-// } else {
|
|
|
|
-// [string appendFormat:@"0%@", hexStr];
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// }];
|
|
|
|
-//
|
|
|
|
-// return string;
|
|
|
|
-//}
|
|
|
|
-///**
|
|
|
|
-// 十六进制转换为二进制
|
|
|
|
-// @return 二进制数
|
|
|
|
-// */
|
|
|
|
-//+ (NSString *)convertDataToHexStr:(NSData *)data
|
|
|
|
-//{
|
|
|
|
-// if (!data || [data length] == 0) {
|
|
|
|
-// return @"";
|
|
|
|
-// }
|
|
|
|
-// NSMutableString *string = [[NSMutableString alloc] initWithCapacity:[data length]];
|
|
|
|
-//
|
|
|
|
-// [data enumerateByteRangesUsingBlock:^(const void *bytes, NSRange byteRange, BOOL *stop) {
|
|
|
|
-// unsigned char *dataBytes = (unsigned char*)bytes;
|
|
|
|
-// for (NSInteger i = 0; i < byteRange.length; i++) {
|
|
|
|
-// NSString *hexStr = [NSString stringWithFormat:@"%x", (dataBytes[i]) & 0xff];
|
|
|
|
-// if ([hexStr length] == 2) {
|
|
|
|
-// [string appendString:hexStr];
|
|
|
|
-// } else {
|
|
|
|
-// [string appendFormat:@"0%@", hexStr];
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// }];
|
|
|
|
-// return string;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark -- 图文混排富文本
|
|
|
|
-//+(NSAttributedString*)labelAttribute:(NSString *)firstLabelText secondLabelText:(NSString *)secondLabelText{
|
|
|
|
-//
|
|
|
|
-// NSString* firstStr ;
|
|
|
|
-// NSString* secondStr ;
|
|
|
|
-// NSString* finalStr ;
|
|
|
|
-//
|
|
|
|
-//// if ([firstLabelText isEqualToString:@"00"]){
|
|
|
|
-////
|
|
|
|
-//// firstStr = [NSString stringWithFormat:@"%@",firstLabelText];
|
|
|
|
-//// secondStr = [NSString stringWithFormat:@"%@",secondLabelText];
|
|
|
|
-//// finalStr = [NSString stringWithFormat:@"%@ %@",firstStr,secondStr];
|
|
|
|
-////
|
|
|
|
-//// }else{
|
|
|
|
-//
|
|
|
|
-// firstStr = [NSString stringWithFormat:@"%@℃",firstLabelText];
|
|
|
|
-// secondStr = [NSString stringWithFormat:@"%@%",secondLabelText];
|
|
|
|
-// finalStr = [NSString stringWithFormat:@"%@ %@",firstStr,secondStr];
|
|
|
|
-//// }
|
|
|
|
-//
|
|
|
|
-// // 1.创建一个富文本
|
|
|
|
-// NSMutableAttributedString *attritube = [[NSMutableAttributedString alloc] initWithString:finalStr];
|
|
|
|
-//
|
|
|
|
-// // 修改富文本中的不同文字的样式
|
|
|
|
-// // 创建带有图片的富文本--1
|
|
|
|
-// NSTextAttachment *temperatureAttch = [[NSTextAttachment alloc] init];
|
|
|
|
-// temperatureAttch.bounds = CGRectMake(0, -3.5, 22, 22);
|
|
|
|
-// temperatureAttch.image = [UIImage imageNamed:@"myair_temperature_img"];
|
|
|
|
-// NSAttributedString *temperatureAttchImage = [NSAttributedString attributedStringWithAttachment:temperatureAttch];
|
|
|
|
-//
|
|
|
|
-// // 创建带有图片的富文本--2
|
|
|
|
-// NSTextAttachment *humidity = [[NSTextAttachment alloc] init];
|
|
|
|
-// humidity.bounds = CGRectMake(0, -3.5, 22, 22);
|
|
|
|
-// humidity.image = [UIImage imageNamed:@"myair_humidity_img"];
|
|
|
|
-// NSAttributedString *humidityImage = [NSAttributedString attributedStringWithAttachment:humidity];
|
|
|
|
-//
|
|
|
|
-// // 用label的attributedText属性来使用富文本
|
|
|
|
-// [attritube insertAttributedString:temperatureAttchImage atIndex:0];// 插入某个位置
|
|
|
|
-// [attritube insertAttributedString:humidityImage atIndex:7];// 插入某个位置
|
|
|
|
-//
|
|
|
|
-// return attritube;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark -- 头部背景视图
|
|
|
|
-//+(NSString*)changePicturesAccordingToPeriods{
|
|
|
|
-// NSString * headImageStr;
|
|
|
|
-// NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; //初始化格式器
|
|
|
|
-// [formatter setDateFormat:@"HH"];//定义时间为这种格式: YYYY-MM-dd hh:mm:ss
|
|
|
|
-// NSString *currentTime = [formatter stringFromDate:[NSDate date]];//将NSDate *对象 转化为 NSString *对象
|
|
|
|
-// NSLog(@"当前时间是----%@", currentTime);//控制台打印出当前时间
|
|
|
|
-//// int time = [currentTime intValue];
|
|
|
|
-//// if(time>=6&&time<12) {
|
|
|
|
-//// NSLog(@"上午");
|
|
|
|
-// headImageStr = @"bg_outdoor_morning_img";
|
|
|
|
-//
|
|
|
|
-//// }else if (time>=12&&time<17){
|
|
|
|
-//// NSLog(@"下午");
|
|
|
|
-//// headImageStr = @"bg_outdoor_afteroom_img";
|
|
|
|
-////
|
|
|
|
-//// }else if (time>=17&&time<19){
|
|
|
|
-//// NSLog(@"傍晚");
|
|
|
|
-//// headImageStr = @"bg_outdoor_dusk_img";
|
|
|
|
-////
|
|
|
|
-//// }else if (time>=19&&time<24){
|
|
|
|
-//// NSLog(@"晚上");
|
|
|
|
-//// headImageStr = @"bg_outdoor_night_img";
|
|
|
|
-////
|
|
|
|
-//// }else if (time>=0&&time<6){
|
|
|
|
-//// NSLog(@"凌晨");
|
|
|
|
-//// headImageStr = @"bg_outdoor_night_img";
|
|
|
|
-////
|
|
|
|
-//// }
|
|
|
|
-//
|
|
|
|
-// return headImageStr;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark -- 定位的城市简体转拼音
|
|
|
|
-//+(NSString *)transform:(NSString *)chinese{
|
|
|
|
-//
|
|
|
|
-// if (chinese!=nil&&chinese.length>0){
|
|
|
|
-// NSMutableString *pinyin = [chinese mutableCopy];
|
|
|
|
-// CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformMandarinLatin, NO);//带音标的拼音
|
|
|
|
-// CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformStripCombiningMarks, NO);//不带音标的拼音
|
|
|
|
-// NSString * strUrl = [pinyin stringByReplacingOccurrencesOfString:@" " withString:@""];
|
|
|
|
-// strUrl = [strUrl stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[strUrl substringToIndex:1] uppercaseString]];
|
|
|
|
-// NSString *finalStr = [strUrl substringToIndex:[strUrl length] - 3];
|
|
|
|
-// NSLog(@"转换过来的拼音的城市名称是:%@", finalStr);
|
|
|
|
-// return finalStr;
|
|
|
|
-// }else{
|
|
|
|
-// return @"No Data";
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark -- 返回机器状态信息
|
|
|
|
-//+(NSString*)returnStallStr:(NSString*)command deviceinfo:(NSString*)deviceInfo{
|
|
|
|
-//
|
|
|
|
-// NSString * deviceStatus ;
|
|
|
|
-// //开关机
|
|
|
|
-// if ([command isEqualToString:@"A0"]) {
|
|
|
|
-//
|
|
|
|
-// if ([deviceInfo isEqualToString:@"00000000"]) {
|
|
|
|
-//
|
|
|
|
-// deviceStatus = @"当前是关机";
|
|
|
|
-//
|
|
|
|
-// }else if ([deviceInfo isEqualToString:@"00000001"]){
|
|
|
|
-//
|
|
|
|
-// deviceStatus = @"当前是开机";
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// //档位
|
|
|
|
-// if ([command isEqualToString:@"A4"]){
|
|
|
|
-//
|
|
|
|
-// deviceStatus = @"当前是Auto档位";
|
|
|
|
-//
|
|
|
|
-// }else if([command isEqualToString:@"A8"]){
|
|
|
|
-//
|
|
|
|
-// deviceStatus = @"当前是Max档位";
|
|
|
|
-//
|
|
|
|
-// }else if([command isEqualToString:@"A9"]){
|
|
|
|
-//
|
|
|
|
-// deviceStatus = @"当前是Sleep档位";
|
|
|
|
-//
|
|
|
|
-// }else if([command isEqualToString:@"A1"]){//机器当前是 1 2 3
|
|
|
|
-//
|
|
|
|
-// if ([deviceInfo isEqualToString:@"00000001"]) {
|
|
|
|
-//
|
|
|
|
-// deviceStatus = @"当前是一档";
|
|
|
|
-//
|
|
|
|
-// }else if ([deviceInfo isEqualToString:@"00000002"]){
|
|
|
|
-//
|
|
|
|
-// deviceStatus = @"当前是二档";
|
|
|
|
-//
|
|
|
|
-// }else if ([deviceInfo isEqualToString:@"00000003"]){
|
|
|
|
-//
|
|
|
|
-//// [SVProgressHUD showSuccessWithStatus:@"当前的档位是三档"];
|
|
|
|
-// deviceStatus = @"当前是三档";
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-// return deviceStatus;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark -- 返回室外天气图片
|
|
|
|
-//+(NSString*)returnWeatherImageStr:(NSString*)deviceInfo{
|
|
|
|
-//
|
|
|
|
-// NSString * imageString;
|
|
|
|
-//
|
|
|
|
-// NSString * weatherStr = [deviceInfo substringWithRange:NSMakeRange(5, 3)];
|
|
|
|
-// NSString*path =[[NSBundle mainBundle] pathForResource:@"weatherImageDict" ofType:@"plist"];
|
|
|
|
-// NSMutableDictionary * dictplist =[[NSMutableDictionary alloc] initWithContentsOfFile:path];
|
|
|
|
-// NSMutableDictionary * airImageDict = dictplist[@"airImageDict"];
|
|
|
|
-//// NSLog(@"path%@",airImageDict);
|
|
|
|
-//
|
|
|
|
-// for (NSString * key in [airImageDict allKeys]){
|
|
|
|
-//
|
|
|
|
-// if ([weatherStr isEqualToString:key]){//获取的天气在图片字典中
|
|
|
|
-// imageString = [key lowercaseString];//转UI图片小写字母
|
|
|
|
-// break;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-// NSLog(@"返回的天气图片 %@ 遍历天气字典结果 %@",weatherStr,imageString);
|
|
|
|
-//
|
|
|
|
-// if (imageString.length==0) {
|
|
|
|
-// imageString = @"w0";
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// return imageString;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark -- 室外天气质量
|
|
|
|
-//+(NSString*)returnOutDoorAqi:(NSInteger)aqiValue{
|
|
|
|
-//
|
|
|
|
-// NSString * aqi;
|
|
|
|
-//
|
|
|
|
-// if (aqiValue>0&& aqiValue<=50){
|
|
|
|
-//
|
|
|
|
-// NSLog(@"优");
|
|
|
|
-// aqi = [NSString stringWithFormat:@"AQI: %@",MyLocalizedString(@"Good")];
|
|
|
|
-//
|
|
|
|
-// }else if (aqiValue>50&& aqiValue<=100){
|
|
|
|
-//
|
|
|
|
-// NSLog(@"良");
|
|
|
|
-// aqi = [NSString stringWithFormat:@"AQI: %@",MyLocalizedString(@"Average")];
|
|
|
|
-//
|
|
|
|
-// }else if (aqiValue>100&& aqiValue<=150){
|
|
|
|
-//
|
|
|
|
-// NSLog(@"轻度污染");
|
|
|
|
-// aqi = [NSString stringWithFormat:@"AQI: %@",MyLocalizedString(@"Pollution")];
|
|
|
|
-//
|
|
|
|
-// }else if (aqiValue>150&& aqiValue<=200){
|
|
|
|
-//
|
|
|
|
-// NSLog(@"中度污染");
|
|
|
|
-// aqi = [NSString stringWithFormat:@"AQI: %@",MyLocalizedString(@"Moderate Pollution")];
|
|
|
|
-//
|
|
|
|
-// }else if (aqiValue>200&& aqiValue<=300){
|
|
|
|
-//
|
|
|
|
-// NSLog(@"重度污染");
|
|
|
|
-// aqi = [NSString stringWithFormat:@"AQI: %@",MyLocalizedString(@"Heavy Pollution")];
|
|
|
|
-//
|
|
|
|
-// }else if (aqiValue>300){
|
|
|
|
-//
|
|
|
|
-// NSLog(@"严重污染");
|
|
|
|
-// aqi = [NSString stringWithFormat:@"AQI: %@",MyLocalizedString(@"Serious Pollution")];
|
|
|
|
|
|
+//#pragma mark ------ 发送app group通知
|
|
|
|
+//+ (void)postGroupCFNotificaiton:(NSString*)string{
|
|
//
|
|
//
|
|
-// }else{
|
|
|
|
-//
|
|
|
|
-// aqi = [NSString stringWithFormat:@"AQI: %@",MyLocalizedString(@"No data")];
|
|
|
|
|
|
+// NSString * notificaitonName = @"OPEN_NOTIFICATION";
|
|
|
|
+// CFStringRef strRef = (__bridge CFStringRef)notificaitonName;
|
|
|
|
+// CFNotificationCenterRef notification = CFNotificationCenterGetDarwinNotifyCenter ();
|
|
|
|
+// //第一种生成参数方法 测试无效
|
|
|
|
+//// NSDictionary * ocDict = @{@"key":@"123"};
|
|
|
|
+//// CFDictionaryRef dicRef = (__bridge CFDictionaryRef)ocDict;
|
|
|
|
+// //第二种 共享沙河数据
|
|
|
|
+// NSUserDefaults* userDefault = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.Oujia.AppAndGame"];
|
|
|
|
+// [userDefault setObject:string forKey:@"type"];//主副设备 断开的type
|
|
|
|
+// [userDefault synchronize];
|
|
|
|
+// //之后发送通知
|
|
|
|
+// CFNotificationCenterPostNotification(notification, strRef, NULL,nil, YES);
|
|
|
|
+// //
|
|
//
|
|
//
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// return aqi;
|
|
|
|
-//
|
|
|
|
//}
|
|
//}
|
|
-//
|
|
|
|
-//#pragma mark --- 验证报文
|
|
|
|
-//+(NSString*)authenticationMessage:(NSString*)MessageConent{
|
|
|
|
-//
|
|
|
|
-// int total = 0;
|
|
|
|
-//
|
|
|
|
-// NSData * data = [MessageConent dataUsingEncoding:NSUTF8StringEncoding];//字符串 UTF-8编码 转换出来的是10进制数据流
|
|
|
|
-//
|
|
|
|
-// Byte * testByteArr = (Byte *)[data bytes];//16进制数据流 转换成Byte数组 数组里面是10进制数据
|
|
|
|
-//
|
|
|
|
-//// NSLog(@"长度是:%ld",[data length]);//一个字符对应一个长度
|
|
|
|
-//
|
|
|
|
-// for(int i=0;i<[data length];i++){//转换出来的是10进制数据流
|
|
|
|
-//
|
|
|
|
-//// printf("testByte = %d\n",testByteArr[i]);
|
|
|
|
-// total = total+testByteArr[i];
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// NSString * back = [MYFactoryManager getHexByDecimal:total];
|
|
|
|
-//
|
|
|
|
-// NSString * finalStr;
|
|
|
|
-//
|
|
|
|
-// //截取后面两位
|
|
|
|
-// if (back.length==4){
|
|
|
|
-// finalStr = [back substringFromIndex:2];
|
|
|
|
-// }else{
|
|
|
|
-// finalStr = [back substringFromIndex:1];
|
|
|
|
-// }
|
|
|
|
-// return finalStr;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-////十进制转换成16进制字符串
|
|
|
|
-//+ (NSString *)getHexByDecimal:(NSInteger)decimal{
|
|
|
|
-// //3819
|
|
|
|
-// NSString *hex =@"";
|
|
|
|
-// NSString *letter;
|
|
|
|
-// NSInteger number;
|
|
|
|
-// for (int i = 0; i<9; i++){
|
|
|
|
-//
|
|
|
|
-// number = decimal % 16;
|
|
|
|
-// decimal = decimal / 16;
|
|
|
|
-// switch (number) {
|
|
|
|
-//
|
|
|
|
-// case 10:
|
|
|
|
-// letter =@"A"; break;
|
|
|
|
-// case 11:
|
|
|
|
-// letter =@"B"; break;
|
|
|
|
-// case 12:
|
|
|
|
-// letter =@"C"; break;
|
|
|
|
-// case 13:
|
|
|
|
-// letter =@"D"; break;
|
|
|
|
-// case 14:
|
|
|
|
-// letter =@"E"; break;
|
|
|
|
-// case 15:
|
|
|
|
-// letter =@"F"; break;
|
|
|
|
-// default:
|
|
|
|
-// letter = [NSString stringWithFormat:@"%ld", number];
|
|
|
|
-// }
|
|
|
|
-// hex = [letter stringByAppendingString:hex];
|
|
|
|
-// if (decimal == 0) {
|
|
|
|
-// break;
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// return hex;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//+ (NSString*)getCurrentSSID{
|
|
|
|
-//
|
|
|
|
-// NSDictionary * ifs = [MYFactoryManager fetchSSIDInfo];;
|
|
|
|
-// NSString *ssid = [ifs objectForKey:@"SSID"];
|
|
|
|
-// if (ssid.length<=0){
|
|
|
|
-// return @"未知网络";
|
|
|
|
-// }else{
|
|
|
|
-// return ssid;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//#pragma mark -- 获取当前链接的wifi - 是不是luftmed
|
|
|
|
-//+ (BOOL)ifConnetLuftmed{
|
|
|
|
-//
|
|
|
|
-// BOOL wifiOK = FALSE;
|
|
|
|
-// NSDictionary *ifs;
|
|
|
|
-// NSString *ssid;
|
|
|
|
-//
|
|
|
|
-// if (!wifiOK){
|
|
|
|
-//
|
|
|
|
-// ifs = [MYFactoryManager fetchSSIDInfo];
|
|
|
|
-// ssid = [ifs objectForKey:@"SSID"];
|
|
|
|
-//
|
|
|
|
-// if(ssid!= nil){
|
|
|
|
-//
|
|
|
|
-// wifiOK= TRUE;
|
|
|
|
-//
|
|
|
|
-// NSString * tails;
|
|
|
|
-// if (ssid.length==12){
|
|
|
|
-// tails = [ssid substringWithRange:NSMakeRange(8, 4)];
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// NSLog(@"当前的SSID是 ========>> %@ %@",ssid,tails);
|
|
|
|
-//
|
|
|
|
-// if (ssid.length == 12&&[self judgePassWordLegal:tails]){
|
|
|
|
-//
|
|
|
|
-// if ([ssid hasPrefix:@"luftmed_"]||[ssid hasPrefix:@"luftmed-"]){//当前连接的网络是 luftmed_wifi 协议三判断是否已经配网
|
|
|
|
-//
|
|
|
|
-// return YES;
|
|
|
|
-//
|
|
|
|
-// }else{
|
|
|
|
-//
|
|
|
|
-// return NO;
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// }else{
|
|
|
|
-//
|
|
|
|
-// return NO;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// }else{
|
|
|
|
-//
|
|
|
|
-// return NO;
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// return NO;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-////是否由数字或者字母组成
|
|
|
|
-//+(BOOL)judgePassWordLegal:(NSString*)ssid{
|
|
|
|
-//
|
|
|
|
-// NSString *regex = @"^[a-z0-9A-Z]*$";
|
|
|
|
-//
|
|
|
|
-// NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
|
|
|
|
-//
|
|
|
|
-// if ([predicate evaluateWithObject:ssid] == YES) {
|
|
|
|
-//
|
|
|
|
-// return YES;
|
|
|
|
-//
|
|
|
|
-// }else{
|
|
|
|
-//
|
|
|
|
-// return NO;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-////是否由数字+字母组成
|
|
|
|
-//+(BOOL)judgePassWordLegalCountOrAZ:(NSString *)ssid{
|
|
|
|
-// BOOL result = false;
|
|
|
|
-// if ([ssid length] == 4){
|
|
|
|
-// // 判断长度大于8位后再接着判断是否同时包含数字和字符
|
|
|
|
-// NSString * regex = @"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$";
|
|
|
|
-// NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
|
|
|
|
-// result = [pred evaluateWithObject:ssid];
|
|
|
|
-// }
|
|
|
|
-// return result;
|
|
|
|
-// NSLog(@"result ===> %@",result?@"YES":@"NO");
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//+(id)fetchSSIDInfo{
|
|
|
|
-//
|
|
|
|
-// NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
|
|
|
|
-//// NSLog(@"Supported interfaces: %@", ifs);
|
|
|
|
-// id info = nil;
|
|
|
|
-// for (NSString *ifnam in ifs) {
|
|
|
|
-//// NSLog(@"遍历到的SSID数据是ifnam--%@",ifnam);
|
|
|
|
-// info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
|
|
|
|
-//// NSLog(@"%@ => %@", ifnam, info);
|
|
|
|
-// if (info && [info count]) { break; }
|
|
|
|
-// }
|
|
|
|
-// return info;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark -------------------------------- 获取UDID
|
|
|
|
-//+(NSString*)getUDIDString{
|
|
|
|
-//
|
|
|
|
-// NSString *identifierStr = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
|
|
|
|
-// NSString * udid = [identifierStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
|
|
|
|
-// NSString * udidString = [udid substringToIndex:16];
|
|
|
|
-//// NSLog(@"udidString = %@",udidString);
|
|
|
|
-// return udidString;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark --------------------------------- 返回PM25对应的文本
|
|
|
|
-//+(NSString*)getPM25ValueText:(NSString*)value{
|
|
|
|
-//
|
|
|
|
-// CGFloat floatValue = [value floatValue];
|
|
|
|
-// NSString * text;
|
|
|
|
-// // 优 0~35μg/m³
|
|
|
|
-// // 良 35~75μg/m³
|
|
|
|
-// // 轻度污染 75~115μg/m³
|
|
|
|
-// // 中度污染 115~150μg/m³
|
|
|
|
-// // 重度污染 150~250μg/m³
|
|
|
|
-// // 严重污染 大于250μg/m³及以上
|
|
|
|
-// if (floatValue>=0&&floatValue<40){//优
|
|
|
|
-// text = MyLocalizedString(@"Good");
|
|
|
|
-// }else if(floatValue>=40&&floatValue<100){//一般
|
|
|
|
-// text = MyLocalizedString(@"Average");
|
|
|
|
-// }else if(floatValue>=100&&floatValue<180){//轻度
|
|
|
|
-// text = MyLocalizedString(@"Pollution");
|
|
|
|
-// }else if(floatValue>=180&&floatValue<250){//重度
|
|
|
|
-// text = MyLocalizedString(@"Moderate Pollution");
|
|
|
|
-// }else if(floatValue>=250&&floatValue<1000){//严重
|
|
|
|
-// text = MyLocalizedString(@"Heavy Pollution");
|
|
|
|
-// }
|
|
|
|
-// return text;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark --- 返回PM25对应的颜色
|
|
|
|
-//+(UIColor*)getPM25ValueColor:(NSString*)value{
|
|
|
|
-// CGFloat floatValue = [value floatValue];
|
|
|
|
-// UIColor * color ;
|
|
|
|
-//// 优 0~35μg/m³
|
|
|
|
-//// 良 35~75μg/m³
|
|
|
|
-//// 轻度污染 75~115μg/m³
|
|
|
|
-//// 中度污染 115~150μg/m³
|
|
|
|
-//// 重度污染 150~250μg/m³
|
|
|
|
-//// 严重污染 大于250μg/m³及以上
|
|
|
|
-// if (floatValue>=0&&floatValue<40){//优
|
|
|
|
-// color = PM25ExcellentColor;
|
|
|
|
-// }else if(floatValue>=40&&floatValue<100){//一般
|
|
|
|
-// color = PM25NormalColor;
|
|
|
|
-// }else if(floatValue>=100&&floatValue<180){//轻度
|
|
|
|
-// color = PM25LightColor;
|
|
|
|
-// }else if(floatValue>=180&&floatValue<250){//重度
|
|
|
|
-// color = PM25SevereColor;
|
|
|
|
-// }else if(floatValue>=250&&floatValue<1000){//严重
|
|
|
|
-// color = PM25SeriousColor;
|
|
|
|
-// }
|
|
|
|
-// return color;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark --- 返回PM25 角度
|
|
|
|
-//+(CGFloat)getPM25TotalAngle:(NSInteger)temp10{
|
|
|
|
-//
|
|
|
|
-// CGFloat totalAngle;
|
|
|
|
-// if (temp10>=0&&temp10<=40){//优秀
|
|
|
|
-// CGFloat progress = temp10 /40.0;
|
|
|
|
-// CGFloat newAngle = progress * 70;
|
|
|
|
-// totalAngle = 55+newAngle;
|
|
|
|
-// }else if(temp10>40&&temp10<=99){//一般
|
|
|
|
-// CGFloat progress = (temp10-40) /60.0;
|
|
|
|
-// CGFloat newAngle = progress * 60;
|
|
|
|
-// totalAngle = 55+70+newAngle;
|
|
|
|
-// }else if(temp10>99&&temp10<=179){//轻度污染
|
|
|
|
-// CGFloat progress = (temp10-100) /80.0;
|
|
|
|
-// CGFloat newAngle = progress * 50;
|
|
|
|
-// totalAngle = 55+130+newAngle;
|
|
|
|
-// }else if(temp10>179&&temp10<=249){//轻度污染
|
|
|
|
-// CGFloat progress = (temp10-180) /70.0;
|
|
|
|
-// CGFloat newAngle = progress * 60;
|
|
|
|
-// totalAngle = 55+180+newAngle;
|
|
|
|
-// }else{//严重
|
|
|
|
-// CGFloat progress = (temp10-250)/750.0;
|
|
|
|
-// CGFloat newAngle = progress * 30;
|
|
|
|
-// totalAngle = 55+220+newAngle;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// return totalAngle;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark --------------------------------- 返回TVOC 文本
|
|
|
|
-//+(NSString*)getTVOCValueText:(NSString*)value{
|
|
|
|
-// NSString * valveString = [NSString stringWithFormat:@"%.2f", [value floatValue]/100];
|
|
|
|
-// CGFloat floatValue = [valveString floatValue];
|
|
|
|
-// NSString * text;
|
|
|
|
-// if (floatValue>=0&&floatValue<2.0){//优
|
|
|
|
-// text = MyLocalizedString(@"Good");
|
|
|
|
-// }else if(floatValue>=2.0&&floatValue<4.0){//一般
|
|
|
|
-// text = MyLocalizedString(@"Average");
|
|
|
|
-// }else if(floatValue>=4.0&&floatValue<6.0){//轻度
|
|
|
|
-// text = MyLocalizedString(@"Pollution");
|
|
|
|
-// }else if(floatValue>=6.0&&floatValue<8.0){//重度
|
|
|
|
-// text = MyLocalizedString(@"Moderate Pollution");
|
|
|
|
-// }else if(floatValue>=8.0&&floatValue<9.9){//严重
|
|
|
|
-// text = MyLocalizedString(@"Heavy Pollution");
|
|
|
|
-// }
|
|
|
|
-// return text;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//#pragma mark --- 返回TVOC 颜色
|
|
|
|
-//+(UIColor*)getTVOCValueColor:(NSString*)value{
|
|
|
|
-//
|
|
|
|
-// NSString * valveString = [NSString stringWithFormat:@"%.2f", [value floatValue]/100];
|
|
|
|
-// CGFloat floatValue = [valveString floatValue];
|
|
|
|
-//// NSLog(@"floatValue = %f",floatValue);
|
|
|
|
-// UIColor * color ;
|
|
|
|
-// if (floatValue>=0&&floatValue<2.0){//优
|
|
|
|
-// color = PM25ExcellentColor;
|
|
|
|
-// }else if(floatValue>=2.0&&floatValue<4.0){//一般
|
|
|
|
-// color = PM25NormalColor;
|
|
|
|
-// }else if(floatValue>=4.0&&floatValue<6.0){//轻度
|
|
|
|
-// color = PM25LightColor;
|
|
|
|
-// }else if(floatValue>=6.0&&floatValue<8.0){//重度
|
|
|
|
-// color = PM25SevereColor;
|
|
|
|
-// }else if(floatValue>=8.0&&floatValue<9.9){//严重
|
|
|
|
-// color = PM25SeriousColor;
|
|
|
|
-// }
|
|
|
|
-// return color;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-////返回TVOC真实值
|
|
|
|
-//+(NSString*)returnRealTVOCValue:(NSString*)value{
|
|
|
|
-//
|
|
|
|
-// NSString * text = [NSString stringWithFormat:@"%.2f", [value floatValue]/100];
|
|
|
|
-//// NSLog(@"text = %@",text);
|
|
|
|
-// NSString * tail = [text substringWithRange:NSMakeRange(3, 1)];
|
|
|
|
-// if ([tail isEqualToString:@"0"]) {
|
|
|
|
-// text = [text substringToIndex:3];
|
|
|
|
-// }
|
|
|
|
-//// NSLog(@"tail = %@",tail);
|
|
|
|
-// if ([text isEqualToString:@"0.0"]) {
|
|
|
|
-// text = @"0";
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// return text;
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-//#pragma mark ---------------------------------------------------------------- 车载相关
|
|
|
|
-//+(NSString*)HardDriveVerificationAlgorithm:(NSString*)string_input{
|
|
|
|
-//
|
|
|
|
-// // NSString * string_input = @"0380000D00007CEC79EEF51F000106";
|
|
|
|
-// //string_input = 指令 + 数据长度 + 流水号 + MAC地址 + 数据
|
|
|
|
-// int i = 0;
|
|
|
|
-// NSMutableArray * stringArr = [NSMutableArray new];
|
|
|
|
-//
|
|
|
|
-// while (i<string_input.length-1) {
|
|
|
|
-//
|
|
|
|
-// NSString * tempStr = [string_input substringWithRange:NSMakeRange(i, 2)];
|
|
|
|
-// NSString * temp10 = [NSString stringWithFormat:@"%lu",strtoul([tempStr UTF8String],0,16)];
|
|
|
|
-// //NSLog(@"转换出来的10进制数字是 %@ %@",tempStr,temp10);
|
|
|
|
-// [stringArr addObject:temp10];
|
|
|
|
-// i = i+2;
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// //取数组内容-》异或校验算法对比
|
|
|
|
-// int sum = 0;
|
|
|
|
-// for (NSString * temp10 in stringArr){
|
|
|
|
-// int temp = [temp10 intValue];
|
|
|
|
-// sum = sum^temp;
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// //转16进制
|
|
|
|
-// NSString * checkCode = [self getHexByDecimal:sum];
|
|
|
|
-//
|
|
|
|
-// NSLog(@"int总和转换出来的16进制的字符串是 %d %@",sum,checkCode);
|
|
|
|
-//
|
|
|
|
-// if (checkCode.length<2){
|
|
|
|
-// checkCode = [NSString stringWithFormat:@"0%@",checkCode];
|
|
|
|
-// return checkCode;
|
|
|
|
-// }else{
|
|
|
|
-// return checkCode;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-////字符串转16进制数据流
|
|
|
|
-//+(NSData *)convertHexStrToData:(NSString *)str{
|
|
|
|
-//
|
|
|
|
-// if (!str || [str length] == 0){
|
|
|
|
-// return nil;
|
|
|
|
-// }
|
|
|
|
-// NSMutableData *hexData = [[NSMutableData alloc] initWithCapacity:8];
|
|
|
|
-// NSRange range;
|
|
|
|
-// if ([str length] % 2 == 0) {
|
|
|
|
-// range = NSMakeRange(0, 2);
|
|
|
|
-// } else {
|
|
|
|
-// range = NSMakeRange(0, 1);
|
|
|
|
-// }
|
|
|
|
-// for (NSInteger i = range.location; i < [str length]; i += 2){
|
|
|
|
-//
|
|
|
|
-// unsigned int anInt;
|
|
|
|
-// NSString *hexCharStr = [str substringWithRange:range];
|
|
|
|
-// NSScanner *scanner = [[NSScanner alloc] initWithString:hexCharStr];
|
|
|
|
-//
|
|
|
|
-// [scanner scanHexInt:&anInt];
|
|
|
|
-// NSData *entity = [[NSData alloc] initWithBytes:&anInt length:1];
|
|
|
|
-// [hexData appendData:entity];
|
|
|
|
-//
|
|
|
|
-// range.location += range.length;
|
|
|
|
-// range.length = 2;
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// NSLog(@"发送数据 字符串转16进制数据流 hexdata: %@", hexData);
|
|
|
|
-// return hexData;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-//+(NSInteger)hexToInt:(NSString*)hex{
|
|
|
|
-//
|
|
|
|
-//// NSLog(@"16转10报错信息 = %@",hex);
|
|
|
|
-// NSString * hexFormatStr = [NSString stringWithFormat:@"%lu",strtoul([hex UTF8String],0,16)];
|
|
|
|
-// NSInteger temp10 = [hexFormatStr integerValue];
|
|
|
|
-// return temp10;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-//
|
|
|
|
-///*!* @brief 把格式化的JSON格式的字符串转换成字典* @param jsonString JSON格式的字符串* @return 返回字典*/
|
|
|
|
-////json格式字符串转字典:
|
|
|
|
-//+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
|
|
|
|
-// if (jsonString == nil) {
|
|
|
|
-// return nil;
|
|
|
|
-// }
|
|
|
|
-// NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];NSError *err;
|
|
|
|
-// NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonDataoptions:NSJSONReadingMutableContainerserror:&err];
|
|
|
|
-// if(err) {
|
|
|
|
-// NSLog(@"json解析失败:%@",err);
|
|
|
|
-// return nil;
|
|
|
|
-//
|
|
|
|
-// }return dic;
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-////字典转json格式字符串:
|
|
|
|
-//+ (NSString*)dictionaryToJson:(NSDictionary *)dic{
|
|
|
|
-// NSError *parseError = nil;
|
|
|
|
-// NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
|
|
|
|
-// return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
|
|
-//
|
|
|
|
-//}
|
|
|
|
-////NSJSONWritingPrettyPrinted 是有换位符的。如果NSJSONWritingPrettyPrinted 是nil 的话 返回的数据是没有 换位符的
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
@end
|