// 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. 如果數組為空則創(chuàng)建對象,否則清空數組
#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; \\\\
}
//網絡設置
//為了方便調整網絡環(huán)境通過條件編譯調整
// ? 1代表內網環(huán)境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"]];