这几天看项目,把俺旁边小哥哥的一个工具类相中了,希望对大家有所帮助哦~~~~~~~~~

 //
// PLZ_Tool.h
// //
// Created by penglaizhi on 2017/7/3.
// Copyright © 2017年 yst-fll. All rights reserved.
// #import <Foundation/Foundation.h>
#import <ifaddrs.h>
#import <arpa/inet.h>
#import <net/if.h> #define IOS_CELLULAR @"pdp_ip0"
#define IOS_WIFI @"en0"
#define IOS_VPN @"utun0"
#define IP_ADDR_IPv4 @"ipv4"
#define IP_ADDR_IPv6 @"ipv6" typedef void(^SuccessBlock)(id _Nullable data);
typedef void(^FailBlock)(NSError * _Nullable error); @interface PLZ_Tool : NSObject
/**
* 使用该函数计算时间戳
* parameters : 不传参
*/ //+ (NSString*)getTimeDate:(NSString*)time_ format:(NSString*)format_; /**
* 使用该函数添加提示框下
* parameters : 不传参
*/
//+(void)showMessage:(NSString *)message;
//
///**
// * 使用该函数添加提示框上
// * parameters : 不传参
// */
//+(void)showMessageUp:(NSString *)message; /**
* 使用该函数添加提示框上
* parameters : 不传参
*/
+ (void)sendGETWithUrl:(NSString *_Nullable)url parameters:(NSDictionary *_Nullable)dict success:(SuccessBlock _Nullable )successBlock fail:(FailBlock _Nullable )failBlock; + (void)sendPOSTWithUrl:(NSString *_Nullable)url parameters:(NSDictionary *_Nullable)dict success:(SuccessBlock _Nullable )successBlock fail:(FailBlock _Nullable )failBlock :(BOOL)isNeed; /**
* 判断是否有网
* parameters : 不传参
*/ //+ (BOOL)isCheckNetwork; /* *
*color:支持@“#123456”、 @“0X123456”、 @“123456”三种格式 */
+ (UIColor *_Nullable)colorWithHexString:(NSString *_Nullable)color; /* *
*color:支持@“#123456”、 @“0X123456”、 @“123456”三种格式 */
+ (UIColor *_Nullable)colorWithHexString:(NSString *_Nullable)color alpha:(CGFloat)alpha; + (NSString *_Nullable)filterEmoji:(NSString *_Nullable)string; + (NSMutableAttributedString *_Nullable)String:(NSString *_Nullable)String RangeString:(NSString *_Nullable)RangeString;//富文本 +(void)p_makeupDataForDidLoad:(NSMutableArray *_Nullable)arr; + (NSMutableAttributedString *_Nullable)String2:(NSString *_Nullable)String RangeString:(NSString *_Nullable)RangeString colorString:(NSString *_Nullable)colorString Size:(CGFloat)size;
//邮箱正则
+ (BOOL) validateEmail:(NSString *_Nullable)email;
+ (BOOL) validateMobile:(NSString *_Nullable)mobileNum;
+ (NSInteger)getNowTimestamp;
+ (NSMutableAttributedString *_Nullable)String:(NSString *_Nullable)String SetRangeString:(NSString *_Nullable)RangeString setColor:(UIColor *_Nullable)Color SetFont:(UIFont *_Nullable)Font;
//毫秒转成date
+ (NSString *_Nullable)ConvertStrToTime:(NSString *_Nullable)timeStr; //字符串判空
+(NSInteger)GetContentBackStyleToString:(NSString *_Nullable)string; //过滤表情
+ (BOOL)stringContainsEmoji:(NSString *_Nullable)string;
-(void)textFiledEditChangedN:(UITextField *_Nullable)field lenth:(CGFloat)lenth; -(void)textViewEditChangedN:(UITextView *_Nullable)textView lenth:(CGFloat)lenth; //获取ip地址
+ (NSString *_Nullable)getIPAddress:(BOOL)preferIPv4;
+ (NSString *_Nullable)deviceIPAdress;
+ (BOOL)isMobileNumber:(NSString *_Nullable)mobileNum; +(NSString *)stringAddStarsWithString:(NSString *_Nullable)string; //生成二维码
//+ (UIImage *)creatNonInterpolatedUIImageFormCIImage:(CIImage *)image withSize:(CGFloat)size;
+(NSString *)countdownStartTime:(NSString *)startTime;
@end
 //
// PLZ_Tool.m
// //
// Created by penglaizhi on 2017/7/3.
// Copyright © 2017年 yst-fll. All rights reserved.
// #import "PLZ_Tool.h"
#import "AppDelegate.h" @implementation PLZ_Tool
/**
* 使用该函数计算时间戳
* parameters : 不传参
*/ //+(void)showMessage:(NSString *)message
//{
// UIWindow * window = [UIApplication sharedApplication].keyWindow;
// __block UIView *showview = [[UIView alloc]init];
// showview.backgroundColor = [UIColor blackColor];
// showview.frame = CGRectMake(1, 1, 1, 1);
// showview.alpha = 1.0f;
// showview.layer.cornerRadius = 5.0f;
// showview.layer.masksToBounds = YES;
// [window addSubview:showview];
//
// UILabel *label = [[UILabel alloc]init];
//
// NSDictionary *attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
//
// CGSize LabelSize = [message boundingRectWithSize:CGSizeMake(290, 9000)
// options: NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading
// attributes:attribute context:nil].size;
//
// label.frame = CGRectMake(10, 5, LabelSize.width, LabelSize.height);
// label.text = message;
// label.textColor = [UIColor whiteColor];
// label.textAlignment = 1;
// label.backgroundColor = [UIColor clearColor];
// label.font = [UIFont boldSystemFontOfSize:15];
// [showview addSubview:label];
// showview.frame = CGRectMake((kScreenWidth - LabelSize.width - 20)/2, kScreenHeight - 100, LabelSize.width+20, LabelSize.height+10);
// [UIView animateWithDuration:2.5 animations:^{
// showview.alpha = 0;
// } completion:^(BOOL finished) {
// [showview removeFromSuperview];
// showview = nil;
// }];
//}
//
//+(void)showMessageUp:(NSString *)message
//{
// UIWindow * window = [UIApplication sharedApplication].keyWindow;
// UIView *showview = [[UIView alloc]init];
// showview.backgroundColor = [UIColor blackColor];
// showview.frame = CGRectMake(1, 1, 1, 1);
// showview.alpha = 1.0f;
// showview.layer.cornerRadius = 5.0f;
// showview.layer.masksToBounds = YES;
// [window addSubview:showview];
//
// UILabel *label = [[UILabel alloc]init];
// NSDictionary *attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
//
// CGSize LabelSize = [message boundingRectWithSize:CGSizeMake(290, 9000)
// options: NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading
// attributes:attribute context:nil].size;
// label.frame = CGRectMake(10, 5, LabelSize.width, LabelSize.height);
// label.text = message;
// label.textColor = [UIColor whiteColor];
// label.textAlignment = 1;
// label.backgroundColor = [UIColor clearColor];
// label.font = [UIFont boldSystemFontOfSize:15];
// [showview addSubview:label];
// showview.frame = CGRectMake((kScreenWidth - LabelSize.width - 20)/2, 100, LabelSize.width+20, LabelSize.height+10);
// [UIView animateWithDuration:2.5 animations:^{
// showview.alpha = 0;
// } completion:^(BOOL finished) {
// [showview removeFromSuperview];
// }];
//} //网络请求数据
+(void)sendPOSTWithUrl:(NSString *)url parameters:(NSDictionary *)dict success:(SuccessBlock)successBlock fail:(FailBlock)failBlock :(BOOL)isNeed
{
if (isNeed) {
[JHHJView showLoadingOnTheKeyWindowWithType:JQXLoading]; }
// if ([NetworkTool getNetworkStatus] == NotReachable) {
//// UIViewController *VC = [LFYCommonTool getCurrentVC];
//// [ALToastView toastInView:VC.view withText:@"网络无法连接,请稍后再试"];
// }else{
//加签方法
// NSString *url1 = [url substringFromIndex:26];//本地
// NSString *url1 = [url substringFromIndex:27];//测试
NSMutableDictionary * dic = [EncryptTool encryptParamter:dict withUrl:url]; NSString *url1 = [url substringFromIndex:];//正式
// dict = [YSTFileManageTool encryptChangeDic2:dict AndUrl:url1];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
AFHTTPSessionManager *manager = [app sharedHTTPSession]; // AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.requestSerializer.timeoutInterval = ; // if (kTOKEN) {
// [manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",kTOKEN] forHTTPHeaderField:@"Authorization"];
// }
// NSLog(@"%@------==-----%@0-0%@--9%@",kTOKEN,url1,url,dict); manager.requestSerializer.timeoutInterval = ;
// manager.responseSerializer=[AFJSONResponseSerializer serializer];
// manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/xml",@"text/html",@"text/xml",@"text/plain",@"application/json",nil];
manager.responseSerializer=[AFHTTPResponseSerializer serializer];
NSLog(@"%@",url);
// NSDictionary *Dic = [EncryptTool encryptParamter:dict withUrl:url];
[manager POST:url parameters:dic success:^(NSURLSessionDataTask *task, id responseObject) { [JHHJView hideLoading];
NSDictionary *dic_ = [NSJSONSerialization JSONObjectWithData:responseObject options: error:nil];
successBlock(dic_);
NSLog(@"QJGlobalAFN>>dic = %@",dic_);
// [NSObject creatPropertyCodeWithDictionary:dic_]; } failure:^(NSURLSessionDataTask *task, NSError *error) {
[JHHJView hideLoading];
failBlock(error);
NSLog(@"QJGlobalAFN>>error = %@",error);
// [JHHJView hideLoading]; }]; // } // AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
// //申明返回的是JSON数据
// manager.responseSerializer = [AFJSONResponseSerializer serializer];
// //申明请求的数据是json类型
// // manager.requestSerializer=[AFJSONRequestSerializer serializer];
// //如果报接受类型不一致请替换一致text/html/plain或别的
// manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
// manager.requestSerializer.timeoutInterval = 10.0;//超时
//
//
// [manager POST:url parameters:dict
//
// success:^(AFHTTPRequestOperation *operation,NSDictionary * responseObject) {
//
// successBlock(responseObject);
// }failure:^(AFHTTPRequestOperation *operation,NSError *error) {
//
// failBlock(error);
// }]; } //网络请求数据
+ (void)sendGETWithUrl:(NSString *)url parameters:(NSDictionary *)dict success:(SuccessBlock)successBlock fail:(FailBlock)failBlock
{
[JHHJView showLoadingOnTheKeyWindowWithType:JQXLoading];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
AFHTTPSessionManager *manager = [app sharedHTTPSession];
// NSString *url1 = [url substringFromIndex:27];//测试
NSString *url1 = [url substringFromIndex:];//正式
// NSString *url1 = [url substringFromIndex:26];//本地 // dict = [YSTFileManageTool encryptChangeDic2:dict AndUrl:url1]; // NSLog(@"%@^^^^^^^^^^",dict); // manager.responseSerializer = [AFHTTPResponseSerializer serializer];
// [manager.requestSerializer setValue:[NSString stringWithFormat:@"YTX-C;ios %@;%@;v%@",[UIDevice systemVersion],CUREENRBUILD,CUREENRVERSION] forHTTPHeaderField:@"User-Agent"]; // if (kTOKEN) {
// [manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",kTOKEN] forHTTPHeaderField:@"Authorization"];
// }
manager.requestSerializer.timeoutInterval = ; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/xml",@"text/html",@"text/xml",@"text/plain",@"application/json",nil]; manager.responseSerializer=[AFHTTPResponseSerializer serializer]; [manager GET:url parameters:dict success:^(NSURLSessionDataTask *task, id responseObject) {
[JHHJView hideLoading];
NSDictionary *dic_ = [NSJSONSerialization JSONObjectWithData:responseObject options: error:nil];
successBlock(dic_);
NSLog(@"
05-27 03:34