常用宏(弹框,从数组生成弹框,打电话,清空数组,创建数组,单利,打印log)--让你的工作事半功倍

// 1 如果两个按钮都为空,则默认一个确定按钮

#define HTALERTWITHBUTTONS(title,commitButtontitle,commitBlock,cancelButtonTitle) {UIAlertController *alert = [ UIAlertController alertControllerWithTitle:@"温馨提示" message:title preferredStyle:UIAlertControllerStyleAlert];\

if(commitButtontitle != nil && commitBlock != nil){\

UIAlertAction *action1 = [ UIAlertAction actionWithTitle:commitButtontitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {\

commitBlock();\

}];\

[alert addAction:action1];\

}\

if(cancelButtonTitle == nil && commitButtontitle == nil){\

UIAlertAction *action = [ UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {}];\

[alert addAction:action];\

}else if(cancelButtonTitle != nil){\

UIAlertAction *action = [ UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {}];\

[alert addAction:action];\

}\

[self presentViewController:alert animated:YES completion:nil];\

}


//2. 传入数组,生成弹窗/点击事件    需要导入UIAlertController的扩展(自己写的)️

//调用形如:(

//     NSArray *arry = @[@{@"删除":^{NSLog(@"删除...........");}},@{@"编辑":^{    NSLog(@"编辑...........");}},@{@"搜索":^{}},@{@"确定":^{}}];

//   HTALERTSHEET(@"温馨提示", @"", UIAlertControllerStyleActionSheet, arry, self);

//  )

#define HTALERTSHEET(title,msg,type,arry,controll) {UIAlertController *alert = [ UIAlertController alertControllerWithTitle:title message:msg preferredStyle:type];\\\\

int cancelCount = 0;\\\\

for (NSDictionary *dict in arry) {\\\\

for (NSString *key in dict) {\\\\

UIAlertAction *cancle = [ UIAlertAction actionWithTitle:key style: [key isEqualToString:@"取消"]?UIAlertActionStyleCancel:UIAlertActionStyleDefault handler:[dict valueForKey:key]];\\\\

[alert addAction:cancle];\\\\

if ([key isEqualToString:@"取消"]) {\\\\

cancelCount = 1;\\\\

}\\\\

}\\\\

}\\\\

if (cancelCount == 0) {\\\\

UIAlertAction *cancle = [ UIAlertAction actionWithTitle:@"取消" style: UIAlertActionStyleCancel handler:nil];\\\\

[alert addAction:cancle];\\\\

}\\\\

[controll presentViewController:alert animated:YES completion:nil];\\\\

}

// 3. 拨打电话

#define HTMakeACallWithPhoneNum(phoneNum,view) {UIWebView *webView =[[ UIWebView alloc]init];\\\\

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: [NSString stringWithFormat:@"tel:%@",[phoneNum isEqualToString:@""]?@ "888888":phoneNum]]]];\\\\

[view addSubview:webView];\\\\

}

//4. 如果数组为空则创建对象,否则清空数组

#define HTCLEARARRY(arry)  if(arry== nil){\\\\

arry = [[ NSMutableArray alloc]init];\\\\

}else{\\\\

[arry removeAllObjects];\\\\

}


//5. 打印

#ifdef DEBUG

#define HtLog(...) NSLog(__VA__ARGS__);

#else

#define HtLog(...)

#endif

//6. 单例

#define singleton_interface(className) \\\\

+ (className *)shared##className;

#define singleton_implementation(className) \\\\

static className *_instance; \\\\

+ (id)allocWithZone:(NSZone *)zone \\\\

{ \\\\

static dispatch_once_t onceToken; \\\\

dispatch_once(&onceToken, ^{ \\\\

_instance = [super allocWithZone:zone]; \\\\

}); \\\\

return _instance; \\\\

} \\\\

+ (className *)shared##className \\\\

{ \\\\

static dispatch_once_t onceToken; \\\\

dispatch_once(&onceToken, ^{ \\\\

_instance = [[self alloc] init]; \\\\

}); \\\\

return _instance; \\\\

}


//网络设置

//为了方便调整网络环境通过条件编译调整

//   1代表内网环境0代表外网

//   baseUrl为访问的服务器路径

//   requestPort为普通请求的端口号

//   uploadPort代表上传文件的端口号

#define LocalTest 0

#if LocalTest

//内网

#define BaseUrl @"http://192.168.31.68:8900/api"   //内网

#define RequestPort @"8900"

#define UploadPort @"9000"

#else

//外网

#define BaseUrl @"http://133.224.17.12:9800/api"

#define RequestPort @"9800"

#define UploadPort @"9801"

#endif

能够访问百度证明连接者外网  ,检测网络是内网还是外网

BOOL  isOutHost =  [[UIApplicationsharedApplication]canOpenURL:[NSURLURLWithString:@"http://www.baidu.com"]];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容