/*
@abstract 获取当前语言环境
*/
+( NSString *)deviceLanguages{
return [[[ NSUserDefaults standardUserDefaults ] objectForKey : @"AppleLanguages" ] objectAtIndex : 0 ];
}
/*
@abstract 获取当前设备 ID
*/
+( NSString *)deviceID{
NSUserDefaults *userDefault = [ NSUserDefaults standardUserDefaults ];
NSString *deviceIDStr = [userDefault valueForKey : @"deviceID" ];
if (!deviceIDStr)
{
NSDateFormatter *formatter = [[ NSDateFormatter alloc ] init ];
[formatter setDateFormat : @"yyyyMMddHHmmssss" ];
NSString *dateTime = [formatter stringFromDate :[ NSDate date ]];
deviceIDStr = [ NSString stringWithFormat : @"%@%@" ,dateTime,[ StaticTools randomCode : 8 ]];
NSLog ( @"%@" ,deviceIDStr);
[userDefault setObject :deviceIDStr forKey : @"deviceID" ];
[userDefault synchronize ];
}
return deviceIDStr;
}
/*
@abstract 获取当前版本号
*/
+ ( NSString *)projectVerson
{
// return [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey];
return [[ NSBundle mainBundle ] objectForInfoDictionaryKey : @"CFBundleShortVersionString" ];
}
/*
@abstract 获取设备型号
*/
+ ( NSString *)phoneModel
{
@abstract 获取当前语言环境
*/
+( NSString *)deviceLanguages{
return [[[ NSUserDefaults standardUserDefaults ] objectForKey : @"AppleLanguages" ] objectAtIndex : 0 ];
}
/*
@abstract 获取当前设备 ID
*/
+( NSString *)deviceID{
NSUserDefaults *userDefault = [ NSUserDefaults standardUserDefaults ];
NSString *deviceIDStr = [userDefault valueForKey : @"deviceID" ];
if (!deviceIDStr)
{
NSDateFormatter *formatter = [[ NSDateFormatter alloc ] init ];
[formatter setDateFormat : @"yyyyMMddHHmmssss" ];
NSString *dateTime = [formatter stringFromDate :[ NSDate date ]];
deviceIDStr = [ NSString stringWithFormat : @"%@%@" ,dateTime,[ StaticTools randomCode : 8 ]];
NSLog ( @"%@" ,deviceIDStr);
[userDefault setObject :deviceIDStr forKey : @"deviceID" ];
[userDefault synchronize ];
}
return deviceIDStr;
}
/*
@abstract 获取当前版本号
*/
+ ( NSString *)projectVerson
{
// return [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey];
return [[ NSBundle mainBundle ] objectForInfoDictionaryKey : @"CFBundleShortVersionString" ];
}
/*
@abstract 获取设备型号
*/
+ ( NSString *)phoneModel
{
// NSString *phoneModel = [[UIDevice currentDevice] model];
struct utsname systemInfo; //系统的获取信息
uname
(&systemInfo);
NSString *deviceString = [ NSString stringWithCString :systemInfo. machine encoding : NSUTF8StringEncoding ];
return deviceString; //iPhone5,2
NSString *deviceString = [ NSString stringWithCString :systemInfo. machine encoding : NSUTF8StringEncoding ];
return deviceString; //iPhone5,2
}
/*
@abstract 获取设备系统版本号
*/
+ ( NSString *)phoneVersion
{
NSString * phoneVersion = [[ UIDevice currentDevice ] systemVersion ];
return phoneVersion;
}
/*
@abstract 获取屏幕尺寸
*/
+ ( NSString *)phoneSize
{
CGRect screenRect = [ UIScreen mainScreen ]. bounds ;
NSString *phoneSizeStr = [ NSString stringWithFormat : @"%.f*%.f" ,screenRect. size . width ,screenRect. size . height ];
return phoneSizeStr;
@abstract 获取设备系统版本号
*/
+ ( NSString *)phoneVersion
{
NSString * phoneVersion = [[ UIDevice currentDevice ] systemVersion ];
return phoneVersion;
}
/*
@abstract 获取屏幕尺寸
*/
+ ( NSString *)phoneSize
{
CGRect screenRect = [ UIScreen mainScreen ]. bounds ;
NSString *phoneSizeStr = [ NSString stringWithFormat : @"%.f*%.f" ,screenRect. size . width ,screenRect. size . height ];
return phoneSizeStr;
}
/*
@abstract 检查网络状态
*/
+ (int)checkNetWork{
NetworkStatus internetStatus = [[Reachability reachabilityForInternetConnection] currentReachabilityStatus];
return internetStatus;
@abstract 检查网络状态
*/
+ (int)checkNetWork{
NetworkStatus internetStatus = [[Reachability reachabilityForInternetConnection] currentReachabilityStatus];
return internetStatus;
}
/*
@abstract 获取手机当前网络类型
*/
+ ( NSString *)networkType
{
NSString * netWorkType = @"" ;
if ([ StaticTools checkNetWork ] > 0 ) // 有网络
{
if ([ StaticTools checkNetWork ] == 1 ) //WWAN
{
if ( IOS7_OR_LATER )
{
CTTelephonyNetworkInfo *telephonyInfo = [ CTTelephonyNetworkInfo new ];
NSString * currenRadioAccessTechnology = telephonyInfo. currentRadioAccessTechnology ;
if ([currenRadioAccessTechnology isEqualToString : CTRadioAccessTechnologyLTE ])
{
netWorkType = @"4G" ;
}
else if ([currenRadioAccessTechnology isEqualToString : CTRadioAccessTechnologyEdge ] || [currenRadioAccessTechnology isEqualToString : CTRadioAccessTechnologyGPRS ])
{
netWorkType = @"2G" ;
} else {
netWorkType = @"3G" ;
}
} else { //ios6 之前
}
} else { //WIFI
netWorkType = @"WIFI" ;
}
} else { // 无网络
netWorkType = @" 无网络 " ;
}
return netWorkType;
}
#pragma mark 文件(夹)操作
/*
@abstract 检查Documents里是否有此文件
*/
+ (BOOL)fileExistsAtPath:(NSString *)fileName{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *DocumentsPath = [documentsDirectory stringByAppendingPathComponent:fileName];
return [fileManager fileExistsAtPath:DocumentsPath];
}
+ (NSString *)getFilePath:(NSString *)fileName{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *DocumentsPath = [documentsDirectory stringByAppendingPathComponent:fileName];
return DocumentsPath;
/*
@abstract 检查Documents里是否有此文件
*/
+ (BOOL)fileExistsAtPath:(NSString *)fileName{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *DocumentsPath = [documentsDirectory stringByAppendingPathComponent:fileName];
return [fileManager fileExistsAtPath:DocumentsPath];
}
+ (NSString *)getFilePath:(NSString *)fileName{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *DocumentsPath = [documentsDirectory stringByAppendingPathComponent:fileName];
return DocumentsPath;
/*
@abstract 校验字符串是否为空
*/
+(BOOL)isEmptyString:(NSString*)string{
if (string == nil ||[string isEqual:[NSNull null]] ) return YES;
//去空格之后判断length是否为0
NSCharacterSet* whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSString* content = [string stringByTrimmingCharactersInSet:whitespace];
if ([content length] == 0) return YES;
return NO;
@abstract 校验字符串是否为空
*/
+(BOOL)isEmptyString:(NSString*)string{
if (string == nil ||[string isEqual:[NSNull null]] ) return YES;
//去空格之后判断length是否为0
NSCharacterSet* whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
NSString* content = [string stringByTrimmingCharactersInSet:whitespace];
if ([content length] == 0) return YES;
return NO;
}
一、过滤字符串开始位置和结束位置的空格
1 NSString *testString = @" my name is wang tianqiao ";
2
3 NSString *cString = [testString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
3 NSString *cString = [testString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
4 NSLog(@"cString is %@",cString);
/*
@abstract 判断输入是否全部都是数字
*/
+ ( BOOL )checkAllIsNumber:( NSString *)psw{
int length = [psw length ];
if ( 0 == length) return NO ;
// 判断是否有汉字
for ( int i = 0 ; i < length; i++) {
NSRange range = NSMakeRange (i, 1 );
NSString *subString = [psw substringWithRange :range];
const char *cString = [subString UTF8String ];
if ( strlen (cString) == 3 )
return NO ;
}
// 判断是否是数字+字母
const char *s=[psw UTF8String ];
for ( int i = 0 ;i < length; i++){
if (s[i] >= 'a' && s[i] <= 'z' )
return NO ;
else if (s[i] >= 'A' && s[i] <= 'Z' )
return NO ;
}
return YES ;
@abstract 判断输入是否全部都是数字
*/
+ ( BOOL )checkAllIsNumber:( NSString *)psw{
int length = [psw length ];
if ( 0 == length) return NO ;
// 判断是否有汉字
for ( int i = 0 ; i < length; i++) {
NSRange range = NSMakeRange (i, 1 );
NSString *subString = [psw substringWithRange :range];
const char *cString = [subString UTF8String ];
if ( strlen (cString) == 3 )
return NO ;
}
// 判断是否是数字+字母
const char *s=[psw UTF8String ];
for ( int i = 0 ;i < length; i++){
if (s[i] >= 'a' && s[i] <= 'z' )
return NO ;
else if (s[i] >= 'A' && s[i] <= 'Z' )
return NO ;
}
return YES ;
}