//
|
// Global.m
|
// airtree
|
//
|
// Created by WindShan on 2016/11/14.
|
// Copyright © 2016年 Gloria. All rights reserved.
|
//
|
|
#import "Global.h"
|
|
@implementation Global
|
|
|
NSMutableDictionary * _loginUser;
|
NSString * _curDeviceName;
|
int _curPage;
|
BOOL _bConnectSuccess;
|
NSString * _curReceiveHexValue;
|
|
+ (Global *)global
|
{
|
static Global *s_global = nil;
|
static dispatch_once_t onceToken;
|
dispatch_once(&onceToken, ^{
|
s_global = [[Global alloc] init];
|
});
|
|
return s_global;
|
}
|
|
+ (BOOL)isSystemLowIOS11
|
{
|
UIDevice *device = [UIDevice currentDevice];
|
CGFloat systemVer = [[device systemVersion] floatValue];
|
if (systemVer - IOSBaseVersion11 < -0.001) {
|
return YES;
|
}
|
|
return NO;
|
}
|
|
+ (BOOL)isSystemLowIOS10
|
{
|
UIDevice *device = [UIDevice currentDevice];
|
CGFloat systemVer = [[device systemVersion] floatValue];
|
if (systemVer - IOSBaseVersion10 < -0.001) {
|
return YES;
|
}
|
|
return NO;
|
}
|
|
+ (BOOL)isSystemLowIOS9
|
{
|
UIDevice *device = [UIDevice currentDevice];
|
CGFloat systemVer = [[device systemVersion] floatValue];
|
if (systemVer - IOSBaseVersion9 < -0.001) {
|
return YES;
|
}
|
|
return NO;
|
}
|
|
+ (BOOL)isSystemLowIOS8
|
{
|
UIDevice *device = [UIDevice currentDevice];
|
CGFloat systemVer = [[device systemVersion] floatValue];
|
if (systemVer - IOSBaseVersion8 < -0.001) {
|
return YES;
|
}
|
|
return NO;
|
}
|
|
+ (BOOL)isSystemLowIOS7
|
{
|
UIDevice *device = [UIDevice currentDevice];
|
CGFloat systemVer = [[device systemVersion] floatValue];
|
if (systemVer - IOSBaseVersion7 < -0.001) {
|
return YES;
|
}
|
|
return NO;
|
}
|
|
+ (BOOL)isSystemLowiOS6
|
{
|
UIDevice *device = [UIDevice currentDevice];
|
CGFloat systemVer = [[device systemVersion] floatValue];
|
if (systemVer < IOSBaseVersion6) {
|
return YES;
|
}
|
|
return NO;
|
}
|
|
+ (NSString *)clientVersion
|
{
|
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
|
return [infoDict objectForKey:@"CFBundleShortVersionString"];
|
}
|
|
+(BOOL)isEmptyObject:(id)object
|
{
|
if (object == nil || object == NULL) {
|
return YES;
|
}
|
if ([object isKindOfClass:[NSNull class]]) {
|
return YES;
|
}
|
return NO;
|
}
|
|
|
|
+ (BOOL) isBlankString:(NSString *)string {
|
|
if (string == nil || string == NULL) {
|
|
return YES;
|
|
}
|
|
if ([string isKindOfClass:[NSNull class]]) {
|
|
return YES;
|
|
}
|
|
if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
|
|
return YES;
|
|
}
|
|
return NO;
|
|
}
|
|
|
#pragma mark - 系统提示
|
|
+ (void)alertMessage:(NSString *)message
|
{
|
[Global alertMessageEx:message
|
title:nil
|
okTtitle:@"确定"
|
cancelTitle:nil
|
delegate:nil];
|
}
|
|
+ (void)alertMessageEx:(NSString *)message
|
title:(NSString *)title
|
okTtitle:(NSString *)okTitle
|
cancelTitle:(NSString *)cancelTitle
|
delegate:(id)delegate
|
{
|
UIAlertView *alertView = [[UIAlertView alloc]
|
initWithTitle:title
|
message:message
|
delegate:delegate
|
cancelButtonTitle:cancelTitle
|
otherButtonTitles:okTitle,
|
nil];
|
|
[alertView show];
|
}
|
|
|
+(BaseResModel *)toBaseModel:(id) responseBody
|
{
|
|
//NSMutableDictionary *returnDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:error];
|
|
if(responseBody != nil)
|
{
|
BaseResModel *model = [[BaseResModel alloc] init];
|
NSMutableDictionary * data = [responseBody objectForKey:@"data"];
|
|
if( data.count == 0 )
|
{
|
model.desc = [responseBody objectForKey:@"msg"];
|
model.code = -1;
|
}
|
else
|
{
|
if ([[data allKeys] containsObject:@"code"])
|
{
|
model.code = [[data objectForKey:@"code"] intValue];
|
}
|
else
|
{
|
model.code = -1;
|
}
|
|
model.desc = [data objectForKey:@"msg"];
|
model.content = [data objectForKey:@"info"];
|
}
|
|
return model;
|
}
|
else
|
{
|
return nil;
|
}
|
}
|
|
// 字典转json字符串方法
|
|
-(NSString *)convertToJsonData:(NSDictionary *)dict
|
|
{
|
NSError *error;
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
|
|
NSString *jsonString;
|
|
if (!jsonData) {
|
|
NSLog(@"%@",error);
|
|
}else{
|
|
jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
}
|
|
NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
|
NSRange range = {0,jsonString.length};
|
|
//去掉字符串中的空格
|
[mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
|
|
NSRange range2 = {0,mutStr.length};
|
//去掉字符串中的换行符
|
[mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
|
|
return mutStr;
|
|
}
|
|
+ (NSString *)arrayToJSONString:(NSDictionary *)array
|
|
{
|
NSError *error = nil;
|
// NSMutableArray *muArray = [NSMutableArray array];
|
// for (NSString *userId in array) {
|
// [muArray addObject:[NSString stringWithFormat:@"\"%@\"", userId]];
|
// }
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:array options:NSJSONWritingPrettyPrinted error:&error];
|
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
// NSString *jsonTemp = [jsonString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
|
// NSString *jsonResult = [jsonTemp stringByReplacingOccurrencesOfString:@" " withString:@""];
|
// NSLog(@"json array is: %@", jsonResult);
|
return jsonString;
|
}
|
@end
|