Files
featherVoice/QXLive/Tools/QXProjectTools.m

479 lines
20 KiB
Mathematica
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// QXProjectTools.m
// QXLive
//
// Created by on 2025/4/27.
//
#import "QXProjectTools.h"
#import <sys/utsname.h>
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import "NSDate+QX.h"
//#import <WXApi.h>
//#import <AlipaySDK/AlipaySDK.h>
@implementation QXProjectTools
+(NSString *)getDispalyTimeWithType:(DataFormatType)type dateStr:(NSString *)dateStr{
// NSDateFormatter
NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
//
[formatter1 setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
// NSDate
NSDate *date =[formatter1 dateFromString:dateStr];
NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
switch (type) {
case DataFormatTypeMMDDHHMM:
[formatter2 setDateFormat:@"MM-dd HH:mm"];
break;
case DataFormatTypeZHMMDDHHMM:
[formatter2 setDateFormat:@"MM月dd日 HH:mm"];
break;
case DataFormatTypeHHMM:
[formatter2 setDateFormat:@"HH:mm"];
break;
case DataFormatTypeYYYYMMDD:
[formatter2 setDateFormat:@"yyyy-MM-dd"];
break;
default:
break;
}
NSString *dateString2 = [formatter2 stringFromDate:date];
return dateString2;
}
#pragma mark -
+(NSString *)getDayDisplayWithDate:(NSString *)dateStr{
NSString* time = [self getTimestampFromTime:dateStr];
NSString *str = [NSDate timeStringWithTimeInterval:time];
return str;
}
//
+ (NSString *)getTimestampFromTime:(NSString*)dateStr{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];// ----------,hhHH:12,24
//,
//,,,.
//2010-01-26 17:40:50,?
//7,...
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[formatter setTimeZone:timeZone];
NSDate *date =[formatter dateFromString:dateStr];
NSString *nowtimeStr = [formatter stringFromDate:date];//----------nsdateformatternsstring
NSLog(@"%@", nowtimeStr);
// :
NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[date timeIntervalSince1970]];
NSLog(@"timeSp:%@",timeSp);//
return timeSp;
}
//
+(NSString *)replaceStringWithAsterisk:(NSString *)originalStr startLocation:(NSInteger)startLocation lenght:(NSInteger)lenght{
NSString *newStr = originalStr;
for (int i = 0; i < lenght; i++) {
NSRange range = NSMakeRange(startLocation, 1);
newStr = [newStr stringByReplacingCharactersInRange:range withString:@"*"];
startLocation ++;
}
return newStr;
}
#pragma mark ----
+ (NSString *)getTimeFromTimestampWithTime:(long)time{
NSDate * myDate=[NSDate dateWithTimeIntervalSince1970:time];
//
NSDateFormatter * formatter=[[NSDateFormatter alloc]init];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
//
NSString *timeStr=[formatter stringFromDate:myDate];
return timeStr;
}
+(void)contactWithMobile:(NSString *)mobile{
NSMutableString * string = [[NSMutableString alloc] initWithFormat:@"tel:%@",mobile];
if (@available(iOS 10, *)) {
/// 10.0使openURL
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string] options:@{} completionHandler:nil];
});
}else{
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
});
}
}
+ (void)shakeView:(UIView*)viewToShake {
viewToShake.backgroundColor = [UIColor redColor];
// //
// CGFloat t = 5.0;
// //
// CGAffineTransform translateLeft =CGAffineTransformTranslate(CGAffineTransformIdentity,-t,0.0);
// //
// CGAffineTransform translateRight =CGAffineTransformTranslate(CGAffineTransformIdentity, t,0.0);
// //
// viewToShake.transform = translateLeft;
// [UIView animateWithDuration:0.07 delay:0.0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
// // repeatCountfloat
// [UIView setAnimationRepeatCount:2.0];
// viewToShake.transform = translateRight;
//
// } completion:^(BOOL finished){
// if(finished){
// //
// [UIView animateWithDuration:0.05 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
// viewToShake.transform =CGAffineTransformIdentity;
// } completion:^(BOOL finished) {
// viewToShake.backgroundColor = [UIColor whiteColor];
// }];
// }
// }];
[UIView animateWithDuration:0.1 animations:^{
viewToShake.backgroundColor = [UIColor whiteColor];
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.1 animations:^{
viewToShake.backgroundColor = [UIColor redColor];
} completion:^(BOOL finished) {
viewToShake.backgroundColor = [UIColor whiteColor];
}];
}];
}
+(UIAlertController *)getInstalledMapAppWithEndLocation:(CLLocationCoordinate2D)coord
address:(NSString*)address
currentLocation:(CLLocationCoordinate2D)currentCoord
{
//   
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:@"前往导航" preferredStyle:UIAlertControllerStyleActionSheet];
//
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
UIAlertAction *baiduMapAction = [UIAlertAction actionWithTitle:@"百度地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *baiduParameterFormat = @"baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&destination=latlng:%f,%f|name:终点&mode=driving";
NSString *urlString = [[NSString stringWithFormat:
baiduParameterFormat,
currentCoord.latitude,//
currentCoord.longitude,//
coord.latitude,
coord.longitude]
stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
if (@available(iOS 10, *)) {
/// 10.0使openURL
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
}else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
}];
[actionSheet addAction:baiduMapAction];
}
//
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
UIAlertAction *gaodeMapAction = [UIAlertAction actionWithTitle:@"高德地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *gaodeParameterFormat = @"iosamap://path?sourceApplication=%@&sid=&slat=&slon=&sname=&did=&dlat=%f&dlon=%f&dname=&dev=0&t=0";
NSString *urlString = [[NSString stringWithFormat:
gaodeParameterFormat,
@"运是滴车主",
coord.latitude,
coord.longitude]
stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
if (@available(iOS 10, *)) {
/// 10.0使openURL
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
}else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
}];
[actionSheet addAction:gaodeMapAction];
}
//
[actionSheet addAction:[UIAlertAction actionWithTitle:@"苹果地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//
MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
CLLocationCoordinate2D desCorrdinate = CLLocationCoordinate2DMake(coord.latitude, coord.longitude);
//
MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:desCorrdinate addressDictionary:nil]];
toLocation.name = address;
//
[MKMapItem openMapsWithItems:@[currentLocation, toLocation]
launchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsMapTypeKey:[NSNumber numberWithInteger:MKMapTypeStandard],
MKLaunchOptionsShowsTrafficKey:[NSNumber numberWithBool:YES]}];
}]];
//
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]]) {
[actionSheet addAction:[UIAlertAction actionWithTitle:@"腾讯地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *QQParameterFormat = @"qqmap://map/routeplan?type=drive&fromcoord=%f, %f&tocoord=%f,%f&coord_type=1&policy=0&refer=%@";
NSString *urlString = [[NSString stringWithFormat:
QQParameterFormat,
currentCoord.latitude,//
currentCoord.longitude,//
coord.latitude,
coord.longitude,
@"运是滴车主"]
stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
if (@available(iOS 10, *)) {
/// 10.0使openURL
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
}else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
}]];
}
//
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {
[actionSheet addAction:[UIAlertAction actionWithTitle:@"谷歌地图"style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",
@"运是滴车主",
@"wufengTrucks",
coord.latitude,
coord.longitude]
stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
if (@available(iOS 10, *)) {
/// 10.0使openURL
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
}else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
}]];
}
//
UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[actionSheet dismissViewControllerAnimated:YES completion:nil];
}];
[actionSheet addAction:action3];
return actionSheet;
}
+(void)contactServices{
// TCallServicesView *v = [[TCallServicesView alloc] initWithFrame:CGRectMake(0, 0, 267, 255)];
// [[TGlobal sharedInstance] handleLayoutAlertViewBlockAndAnimation:v type:(YSDPopViewTypePopFromCenter)];
// [TGlobal sharedInstance].alertViewController.modal = YES;
}
//
+(void)vibrationFeedback{
UIImpactFeedbackGenerator*impactLight = [[UIImpactFeedbackGenerator alloc]initWithStyle:UIImpactFeedbackStyleLight];
[impactLight impactOccurred];
}
+(void)showMessage:(NSString *)text{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:KEYWINDOW animated:YES];
hud.mode = MBProgressHUDModeText;
hud.bezelView.backgroundColor = [UIColor blackColor];
hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
hud.bezelView.color = [UIColor blackColor];
hud.label.textColor = [UIColor whiteColor];
hud.label.text = text;
2025-10-20 09:43:10 +08:00
hud.label.numberOfLines = 0;
2025-08-08 10:49:36 +08:00
[hud hideAnimated:YES afterDelay:1];
}
+(void)showMessage:(NSString *)text view:(UIView *)view{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.mode = MBProgressHUDModeText;
hud.bezelView.backgroundColor = [UIColor blackColor];
hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
hud.bezelView.color = [UIColor blackColor];
hud.label.textColor = [UIColor whiteColor];
hud.label.text = text;
2025-10-20 09:43:10 +08:00
hud.label.numberOfLines = 0;
2025-08-08 10:49:36 +08:00
[hud hideAnimated:YES afterDelay:1];
}
+(void)showLoadingInView:(UIView*)view{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
}
+(void)hideLoadingInView:(UIView*)view{
[MBProgressHUD hideHUDForView:view animated:YES];
}
+(void)jumpToControllerWithType:(NSInteger)type parameterId:(NSString *)parameterId{
}
+(NSString *)showDoubleNumberWithType:(NSInteger)type number:(double)number{
NSString *str = @"0.00";
if (type == 0) {
long result = (long)roundf(number*100);
str = [NSString stringWithFormat:@"%.2f",result/100.0];
}else if (type == 1){
long result = (long)ceilf(number*100);
str = [NSString stringWithFormat:@"%.2f",result/100.0];
}else if (type == 2){
long price = number*100;
long result = (long)floor(price);
str = [NSString stringWithFormat:@"%.2f",result/100.0];
}
return str;
}
+(void)toSetting{
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}
}
+ (UIViewController*)topViewController{
return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
+(UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController{
if ([rootViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController *tabBarController = (UITabBarController *)rootViewController;
return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];
} else if ([rootViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController* navigationController = (UINavigationController*)rootViewController;
return [self topViewControllerWithRootViewController:navigationController.visibleViewController];
} else if (rootViewController.presentedViewController) {
UIViewController* presentedViewController = rootViewController.presentedViewController;
return [self topViewControllerWithRootViewController:presentedViewController];
} else {
return rootViewController;
}
}
//
+(UIViewController *)getViewControllerWithChildVC:(UIViewController*)childVC{
for (UIView* next = [childVC.view superview]; next; next = next.superview) {
UIResponder *nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)nextResponder;
}
}
return nil;
}
//+(void)aliPayWithOrderNum:(NSString*)orderString
// resultBlcok:(void(^)(NSDictionary*dict))resultBlock{
// [[AlipaySDK defaultService] payOrder:orderString fromScheme:@"QXLive" callback:^(NSDictionary *resultDic) {
// NSLog(@"reslut = %@",resultDic);
// resultBlock(resultDic);
// }];
//}
//+(void)wexinPayWithDict:(NSDictionary*)dict{
//// [WXApi registerApp:dict[@"appid"] enableMTA:YES];
//// [WXApi registerApp:dict[@"appid"] universalLink:@"https://"]
// //
// PayReq *req = [[PayReq alloc] init];
// //AppID
// req.openID = dict[@"appid"];
// // id
// req.partnerId = dict[@"partnerid"];
// //
// req.prepayId = dict[@"prepayid"];
// req.package = dict[@"package"];
// //
// req.nonceStr = dict[@"noncestr"];
// //
// req.timeStamp = [dict[@"timestamp"] intValue];
// //
// req.sign = dict[@"sign"];
// [WXApi sendReq:req completion:^(BOOL success) {
//
// }];
//}
@end