// // RQShareFunction.m // LN_School // // Created by 张嵘 on 2018/10/16. // Copyright © 2018 Danson. All rights reserved. // #import "RQShareFunction.h" #import "TZImagePickerController.h"//第三方相册 #import "GKPhotoBrowser.h" //#import #import "SMSDemoPolicyManager.h" #import "SLShotViewController.h" #import "RQCustomWebViewViewController.h" static RQShareFunction *_instance = nil; static dispatch_once_t onceToken; @interface RQShareFunction () @property (nonatomic, strong) NSArray *dataSource; @property (nonatomic, weak) GKPhotoBrowser *browser; @property (nonatomic, strong) UIPageControl *pageControl; @property (assign, readwrite, nonatomic) BOOL isCanSave; @end @implementation RQShareFunction + (instancetype)shareManager { return [[self alloc] init]; } - (instancetype)init{ dispatch_once(&onceToken, ^{ _instance = [super init]; }); return _instance; } - (void)setShieldTopicIDArr:(NSArray *)shieldTopicIDArr { NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; [userDefault setObject:shieldTopicIDArr forKey:@"shieldTopicIDArr"]; [userDefault synchronize]; } - (NSArray *)shieldTopicIDArr { NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; NSArray *arr = (NSArray *)[userDefault objectForKey:@"shieldTopicIDArr"]? : [NSArray array]; return arr; } - (void)setShieldPeopleIDArr:(NSArray *)shieldPeopleIDArr { NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; [userDefault setObject:shieldPeopleIDArr forKey:@"shieldPeopleIDArr"]; [userDefault synchronize]; } - (NSArray *)shieldPeopleIDArr { NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; NSArray *arr = (NSArray *)[userDefault objectForKey:@"shieldPeopleIDArr"]? : [NSArray array]; return arr; } - (void)setAnnouncementIDArr:(NSArray *)announcementIDArr { NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; [userDefault setObject:announcementIDArr forKey:@"announcementIDArr"]; [userDefault synchronize]; } - (NSArray *)announcementIDArr { NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; NSArray *arr = (NSArray *)[userDefault objectForKey:@"announcementIDArr"]? : [NSArray array]; return arr; } - (void)setCurrentUserInterfaceStyle:(UIUserInterfaceStyle)currentUserInterfaceStyle { NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; [userDefault setInteger:currentUserInterfaceStyle forKey:@"currentUserInterfaceStyle"]; [userDefault synchronize]; } - (UIUserInterfaceStyle)currentUserInterfaceStyle{ NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; if (@available(iOS 12.0, *)) { UIUserInterfaceStyle style = (UIUserInterfaceStyle)[userDefault integerForKey:@"currentUserInterfaceStyle"]? : UIUserInterfaceStyleUnspecified; return style; } else { return 0; } } // 理论计时不开启开启人脸比对模式 (不开启地市:台州-3310) - (NSArray *)theoryOfTimingNoOpenFaceToFaceArr { return @[@"3310"]; } // 个人中心功能模块类型一(预约相关,模拟相关,资讯相关)(开启地市:福州-3501,厦门-3502,莆田-3503,泉州-3505) - (NSArray *)personalTypeOneCityCodeArr { return @[]; } // 个人中心功能模块类型一(预约相关,资讯相关)(开启地市:温州-3303) - (NSArray *)personalTypeTwoCityCodeArr { return @[]; } // 学车计时功能模块类型一(理论计时,实操计时,模拟计时,我的学时)(开启地市:福州-3501,厦门-3502,泉州-3505,温州-3303) - (NSArray *)timingTypeOneCityCodeArr { return @[]; } // 学车计时功能模块类型二(理论计时,我的学时)(开启地市:莆田-3503) - (NSArray *)timingTypeTwoCityCodeArr { return @[]; } // 理论计时类型一 (在科目二,科目三可以进行科目四的理论计时) (开启地市:福州-3501,莆田-3503,泉州-3505) - (NSArray *)theoryOfTimingTypeOneCityCodeArr { return @[]; } // 理论计时类型二地市编号:null (在科目二可以进行科目四的理论计时)(开启地市:) - (NSArray *)theoryOfTimingTypeTwoCityCodeArr { return @[]; } // 理论计时类型三 (在科目三可以进行科目四的理论计时)(开启地市:厦门-3502) - (NSArray *)theoryOfTimingTypeThreeCityCodeArr { return @[]; } // 是否开启广告 默认0 不开通 1 开通 - (BOOL)APP_AD { id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"APP_AD"]; BOOL appAd = [object boolValue]; // return [RQ_SHARE_FUNCTION checkProxySetting]? NO : (object? appAd : YES); return object? appAd : YES; } //关闭插屏的时间(秒) - (NSInteger)APP_CLOSE { id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"APP_CLOSE"]; NSInteger appClose = [object integerValue]; return appClose; } - (NSInteger)APP_AD_CYCLE { id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"APP_AD_CYCLE"]; NSInteger appAdCycle = [object integerValue]; return appAdCycle; } //开屏广告展示概率 - (NSInteger)APP_KP { id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"APP_KP"]; NSInteger appKp = [object integerValue]; return appKp; } - (NSInteger)SP_COMPLAINT_DQBH { id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"SP_COMPLAINT_DQBH"]; NSInteger SP_COMPLAINT_DQBH = [object integerValue]; return SP_COMPLAINT_DQBH; } // 是否开启社区 1:开启 0:关闭 - (NSInteger)APP_OPEN_COMMUNITY { id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"APP_OPEN_COMMUNITY"]; NSInteger appOpenCommunity = [object integerValue]; return appOpenCommunity; } //审核开关 - (NSInteger)APP_SWITCH { id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"APP_SWITCH"]; NSInteger appSwitch = [object integerValue]; return appSwitch; } - (CGFloat)RQADViewHeight { return RQ_SCREEN_WIDTH / 3.f; } - (void)setAPP_AD:(BOOL)APP_AD { [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithBool:APP_AD] ForKey:@"APP_AD"]; } - (void)setAPP_CLOSE:(NSInteger)APP_CLOSE { [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithInteger:APP_CLOSE] ForKey:@"APP_CLOSE"]; } - (void)setAPP_AD_CYCLE:(NSInteger)APP_AD_CYCLE { [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithInteger:APP_AD_CYCLE] ForKey:@"APP_AD_CYCLE"]; } - (void)setSP_COMPLAINT_DQBH:(NSInteger)SP_COMPLAINT_DQBH { [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithInteger:SP_COMPLAINT_DQBH] ForKey:@"SP_COMPLAINT_DQBH"]; } - (void)setAPP_OPEN_COMMUNITY:(NSInteger)APP_OPEN_COMMUNITY { [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithInteger:APP_OPEN_COMMUNITY] ForKey:@"APP_OPEN_COMMUNITY"]; } - (void)setAPP_KP:(NSInteger)APP_KP { [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithInteger:APP_KP] ForKey:@"APP_KP"]; } - (void)setAPP_SWITCH:(NSInteger)APP_SWITCH { [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithInteger:APP_SWITCH] ForKey:@"APP_SWITCH"]; } // 时间转换为时间戳,精确到微秒 - (NSInteger)getTimeStampWithDate:(NSDate *)date { return [[NSNumber numberWithDouble:[date timeIntervalSince1970]] integerValue]; } // 时间戳转换为时间 - (NSDate *)getDateWithTimeStamp:(NSInteger)timeStamp { return [NSDate dateWithTimeIntervalSince1970:timeStamp]; } // 一个时间戳与当前时间的间隔(s) - (NSInteger)getIntervalsWithTimeStamp:(NSInteger)timeStamp { return [[NSDate date] timeIntervalSinceDate:[self getDateWithTimeStamp:timeStamp]]; } // 根据时间和formatter获取时间字符串 - (NSString *)getTimeStrWithDate:(NSDate *)date formatter:(NSString *)formatterStr { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; // NSTimeZone *zone = [NSTimeZone systemTimeZone]; // NSInteger interval = [zone secondsFromGMTForDate: date]; // NSDate *localeDate = [date dateByAddingTimeInterval: interval]; [formatter setDateFormat:formatterStr]; NSString *dateStr = [formatter stringFromDate:date]; return dateStr; } // 根据时间字符串和formatter获取时间戳(s) - (NSInteger)getTimeStampWithTimeStr:(NSString *)timeStr formatter:(NSString *)formatterStr { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]]; [formatter setDateFormat:formatterStr]; NSDate *date = [formatter dateFromString:timeStr]; NSInteger timeStamp = [self getTimeStampWithDate:date]; return timeStamp * 1000; } // 一个时间戳与另一个时间戳的间隔(s) - (NSInteger)getIntervalsWithTimeStamp:(NSInteger)timeStamp anotherTimeStamp:(NSInteger)anotherTimeStamp { return [[self getDateWithTimeStamp:timeStamp] timeIntervalSinceDate:[self getDateWithTimeStamp:anotherTimeStamp]] * 0.001 * 0.001; } - (NSInteger)getTimeStampWithHour:(NSInteger)hour andMinute:(NSInteger)minute andDate:(NSDate *)date { NSCalendar *greCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"]; [greCalendar setTimeZone: timeZone]; NSDateComponents *dateComponents = [greCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date]; // 定义一个NSDateComponents对象,设置一个时间点 NSDateComponents *dateComponentsForDate = [[NSDateComponents alloc] init]; [dateComponentsForDate setDay:dateComponents.day]; [dateComponentsForDate setMonth:dateComponents.month]; [dateComponentsForDate setYear:dateComponents.year]; [dateComponentsForDate setHour:hour]; [dateComponentsForDate setMinute:minute]; NSDate *dateFromDateComponentsForDate = [greCalendar dateFromComponents:dateComponentsForDate]; return [dateFromDateComponentsForDate timeIntervalSince1970]; } #pragma mark - GetPhotos - (void)getPhotosWithGetPhotosWay:(GetPhotosWay)getPhotosWay size:(CGSize)size maxLength:(NSUInteger)maxLength maxImagesCount:(NSUInteger)maxImagesCount isCheckBody:(BOOL)isCheckBody photosBlock:(PhotosBlock)photosBlock { if (getPhotosWay == GetPhotosWay_Camera) { [RQPhotoManager fetchPhotosFromCamera:RQ_SHARE_FUNCTION.topViewController allowCrop:NO completion:^(UIImage * _Nonnull image, id _Nonnull asset) { if (image) { NSMutableArray *imagesArr = [NSMutableArray arrayWithObject:image]; if (photosBlock) { photosBlock(imagesArr); } } else { if (photosBlock) { photosBlock(@[]); } } }]; return; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) { [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"请在iPhone的“设置”-“隐私”-“相机”功能中,找到“极速驾培”打开相机访问权限" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) { if (selectedOtherButtonIndex == 0) { NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([[UIApplication sharedApplication] canOpenURL:url]) { [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; } } }]; if (photosBlock) { photosBlock(@[]); } return; } else if (authStatus == AVAuthorizationStatusNotDetermined) { [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { if (granted) { SLShotViewController *vc = [[SLShotViewController alloc] init]; vc.isCheckBody = isCheckBody; [vc initTakePhotoBlock:^(UIImage * _Nullable image) { if (image) { NSMutableArray *imagesArr = [NSMutableArray arrayWithObject:image]; if (photosBlock) { photosBlock(imagesArr); } } else { if (photosBlock) { photosBlock(@[]); } } }]; dispatch_async(dispatch_get_main_queue(), ^{ vc.modalPresentationStyle = UIModalPresentationFullScreen; [[RQ_SHARE_FUNCTION topViewController] presentViewController:vc animated:NO completion:nil]; }); } else { if (photosBlock) { photosBlock(@[]); } } }]; return; } else if (authStatus == AVAuthorizationStatusAuthorized) { SLShotViewController *vc = [[SLShotViewController alloc] init]; vc.isCheckBody = isCheckBody; [vc initTakePhotoBlock:^(UIImage * _Nullable image) { if (image) { NSMutableArray *imagesArr = [NSMutableArray arrayWithObject:image]; if (photosBlock) { photosBlock(imagesArr); } } else { if (photosBlock) { photosBlock(@[]); } } }]; dispatch_async(dispatch_get_main_queue(), ^{ vc.modalPresentationStyle = UIModalPresentationFullScreen; [[RQ_SHARE_FUNCTION topViewController] presentViewController:vc animated:NO completion:nil]; }); } else { if (photosBlock) { photosBlock(@[]); } return; } } else { NSLog(@"相机调用失败"); if (photosBlock) { photosBlock(@[]); } } }else if (getPhotosWay == GetPhotosWay_Album) { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) { TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:maxImagesCount ? maxImagesCount : 1 delegate:nil]; imagePickerVc.naviBgColor = RQ_MAIN_COLOR; imagePickerVc.iconThemeColor = RQ_MAIN_COLOR; imagePickerVc.allowPickingVideo = NO; [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray *photos, NSArray *assets, BOOL isStop) { NSMutableArray *imagesDataStrArr = [NSMutableArray array]; @synchronized (imagesDataStrArr) { for (UIImage *image in photos) { NSData *data; if (CGSizeEqualToSize(size, CGSizeZero)) { data = [UIImage resetSizeOfImageData:image maxSize:maxLength]; }else { data = [UIImage resetSizeOfImageData:[image scaledAndCutToSize:size] maxSize:maxLength]; } NSString *imgString = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]; [imagesDataStrArr addObject:imgString]; } } if (photosBlock) { photosBlock(photos); } }]; dispatch_async(dispatch_get_main_queue(), ^{ imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen; [[RQ_SHARE_FUNCTION topViewController] presentViewController:imagePickerVc animated:YES completion:nil]; }); }else{ NSLog(@"相册调用失败"); } } } #pragma mark - RQAlertViewController - (void)showAlertAtViewController:(nonnull UIViewController *)viewController WithTitle:(nullable NSString *)title message:(nullable NSString *)message alertControllerStyle:(UIAlertControllerStyle)alertControllerStyle cancelButtonTitle:(nullable NSString *)cancelButtonTitle otherButtonTitles:(nullable NSArray *)otherButtonTitles otherButtonStyles:(nullable NSDictionary *)otherButtonStyles preferredActionTitle:(nullable NSString *)preferredActionTitle showInWindow:(BOOL)showInWindow completion:(nullable RQAlertViewCompletion)completion { @weakify(self) __block UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:alertControllerStyle]; void (^alertActionHandler) (UIAlertAction *) = [^(UIAlertAction *action) { if (completion) { if (action.style == UIAlertActionStyleCancel) { completion(NSNotFound); }else { NSUInteger index = [alertController.actions indexOfObject:action]; completion(cancelButtonTitle? index - 1 : index); } } alertController = nil; } copy]; if (cancelButtonTitle) { UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:alertActionHandler]; if (@available(iOS 9.0, *)) { [cancleAction setValue:RQ_MAIN_COLOR forKey:@"_titleTextColor"]; } else { // Fallback on earlier versions } [alertController addAction:cancleAction]; } if (otherButtonTitles.count == 0) { dispatch_async(dispatch_get_main_queue(), ^{ @strongify(self) if (showInWindow) { [[self getKeyWindow].rootViewController presentViewController:alertController animated:YES completion:nil]; } else { [[RQ_SHARE_FUNCTION topViewController] presentViewController:alertController animated:YES completion:nil]; } }); }else { [otherButtonTitles.rac_sequence.signal subscribeNext:^(NSString * buttonTitle) { NSNumber *actionStyleNumber = [otherButtonStyles valueForKey:buttonTitle]; UIAlertActionStyle actionStyle = UIAlertActionStyleDefault; if (actionStyleNumber) { actionStyle = [actionStyleNumber integerValue]; } UIAlertAction *action = [UIAlertAction actionWithTitle:buttonTitle style:actionStyle handler:alertActionHandler]; if (@available(iOS 9.0, *)) { [action setValue:RQ_MAIN_COLOR forKey:@"_titleTextColor"]; } else { // Fallback on earlier versions } [alertController addAction:action]; ///Support for iOS9 add preferredAction for highlights the text of that action if ([alertController respondsToSelector:@selector(setPreferredAction:)]) { if ([preferredActionTitle isEqualToString:buttonTitle]) { if (@available(iOS 9.0, *)) { [alertController setPreferredAction:action]; } else { // Fallback on earlier versions } } } } completed:^{ dispatch_async(dispatch_get_main_queue(), ^{ @strongify(self) if (showInWindow) { [[self getKeyWindow].rootViewController presentViewController:alertController animated:YES completion:nil]; } else { [[RQ_SHARE_FUNCTION topViewController] presentViewController:alertController animated:YES completion:nil]; } }); }]; } } - (void)showAlertWithTitle:(nullable NSString *)title message:(nullable NSString *)message alertControllerStyle:(UIAlertControllerStyle)alertControllerStyle cancelButtonTitle:(nullable NSString *)cancelButtonTitle otherButtonTitles:(nullable NSArray *)otherButtonTitles otherButtonStyles:(nullable NSDictionary *)otherButtonStyles preferredActionTitle:(nullable NSString *)preferredActionTitle showInWindow:(BOOL)showInWindow completion:(nullable RQAlertViewCompletion)completion{ [self showAlertAtViewController:[RQ_SHARE_FUNCTION topViewController] WithTitle:title message:message alertControllerStyle:alertControllerStyle cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles otherButtonStyles:otherButtonStyles preferredActionTitle:preferredActionTitle showInWindow:showInWindow completion:completion]; } - (void)showAlertWithTitle:(nullable NSString *)title message:(nullable NSString *)message alertControllerStyle:(UIAlertControllerStyle)alertControllerStyle cancelButtonTitle:(nullable NSString *)cancelButtonTitle otherButtonTitles:(nullable NSArray *)otherButtonTitles otherButtonStyles:(nullable NSDictionary *)otherButtonStyles showInWindow:(BOOL)showInWindow completion:(nullable RQAlertViewCompletion)completion { [self showAlertAtViewController:[RQ_SHARE_FUNCTION topViewController] WithTitle:title message:message alertControllerStyle:alertControllerStyle cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles otherButtonStyles:otherButtonStyles preferredActionTitle:nil showInWindow:showInWindow completion:completion]; } - (void)showAlertWithMessage:(nullable NSString *)message completion:(nullable RQAlertViewCompletion)completion { [self showAlertAtViewController:[RQ_SHARE_FUNCTION topViewController] WithTitle:@"" message:message alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil preferredActionTitle:nil showInWindow:NO completion:completion]; } #pragma mark - Custom Way - (UIViewController *)topViewController { return [RQ_SHARE_FUNCTION topViewController:[UIApplication sharedApplication].keyWindow.rootViewController]; } - (UIViewController *)topViewController:(UIViewController*)rootViewController { if (rootViewController.presentedViewController == nil || rootViewController.presentedViewController.beingDismissed) { return rootViewController; } if ([rootViewController.presentedViewController isMemberOfClass:[UINavigationController class]]) { UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController; UIViewController *lastViewController = [[navigationController viewControllers] lastObject]; return [RQ_SHARE_FUNCTION topViewController:lastViewController]; } UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController; return [RQ_SHARE_FUNCTION topViewController:presentedViewController]; } - (UIViewController *)currentViewController { UIViewController *resultVC; resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]]; /// RQ Fixed : 这里必须要判断一下,否则取出来永远都是 RQMainTabBarViewController。这是架构上小缺(特)陷(性)。因为RQMainTabBarViewController的子控制器是UITabBarController,所以需要递归UITabBarController的所有的子控制器 while (resultVC.presentedViewController) { resultVC = [self _topViewController:resultVC.presentedViewController]; } return resultVC; } - (UIViewController *)_topViewController:(UIViewController *)vc { if ([vc isKindOfClass:[UINavigationController class]]) { return [self _topViewController:[(UINavigationController *)vc topViewController]]; } else if ([vc isKindOfClass:[UITabBarController class]]) { return [self _topViewController:[(UITabBarController *)vc selectedViewController]]; } else { return vc; } } //- (NSData *)compressQualityWithImage:(UIImage *)image MaxLength:(NSInteger)maxLength { // CGFloat compression = 1; // NSData *data = UIImageJPEGRepresentation(image, compression); // if (data.length < maxLength) { // return data; // } // CGFloat max = 1; // CGFloat min = 0; // NSData *lastData; // for (int i = 0; i < 99; ++i) { // compression = (max + min) / 2; // data = UIImageJPEGRepresentation(image, compression); // if (data.length == lastData.length) { // return data; // }else { // lastData = data; // } // if (data.length < maxLength * 0.9) { // min = compression; // } else if (data.length > maxLength) { // max = compression; // } else { // break; // } // } // return data; //} - (void)showGuidePicture { UIButton* btn = [[UIButton alloc] initWithFrame:kFrame]; [myDelegate.window addSubview:btn]; [btn setImage:[UIImage imageNamed:@"welGuide2.png"] forState:UIControlStateNormal]; UIImageView* iv; iv = [[UIImageView alloc] initWithFrame:CGRectMake(3, 11, 70, 70)]; [iv setImage:[UIImage imageNamed:@"welGuide1.png"]]; [btn addSubview:iv]; [btn addTarget:self action:@selector(removeBtn:) forControlEvents:UIControlEventTouchUpInside]; } - (void)removeBtn:(UIButton *)btn { [btn removeFromSuperview]; } #pragma mark - 检查版本更新 - (void)checkVersion { /// 在当前页面有弹窗 以及在模拟计时页面 理论计时页面 模拟考试界面 不弹出更新提示 NSArray *controllers = @[@"UIAlertController", @"ImitatePeriodVC", @"PeriodVC", @"NYTheoryTimeVC", @"NYGetjobTimeVC"]; NSLog(@"string---Class-----%@",NSStringFromClass([RQ_SHARE_FUNCTION currentViewController].class)); if (![Util connectedToNetWork]) { return; } NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; NSString *localVersion = [infoDic objectForKey:@"CFBundleShortVersionString"]; NSString *URL = @"http://itunes.apple.com/cn/lookup?id=1214200225"; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:URL] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10]; [request setHTTPMethod:@"POST"]; NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { //这个导致部分手机网络不好时候出现闪退情况 if (!data) { return; } //如果data等于nil的时候 再去解析 会发生崩溃 NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; if (!dic) { return; } NSArray *infoArray = [dic objectForKey:@"results"]; if ([infoArray count]) { NSDictionary *releaseInfo = [infoArray objectAtIndex:0]; NSString *netVersion = [releaseInfo objectForKey:@"version"]; //NSLog(@"AppStore-->%@,手机上-->%@",lastVersion,currentVersion); // 线上版本号 NSInteger netInt = [[netVersion stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue]; // 本地版本号 NSInteger localInt = [[localVersion stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue]; if (netInt > localInt) { NSLog(@"更新"); if (RQ_USER_MANAGER.isLogin) { [[[RACSignal createSignal:^RACDisposable * _Nullable(id _Nonnull subscriber) { [subscriber sendNext:@1]; [subscriber sendCompleted]; return [RACDisposable disposableWithBlock:^{ }]; }] delay:2] subscribeCompleted:^{ /// 检查版本更新 if (RQ_AD_MANAGER.splashIsShow) { [[[RACSignal createSignal:^RACDisposable * _Nullable(id _Nonnull subscriber) { [subscriber sendNext:@1]; [subscriber sendCompleted]; return [RACDisposable disposableWithBlock:^{ }]; }] delay:5] subscribeCompleted:^{ [RQ_SHARE_FUNCTION showAlertWithTitle:@"更新提示" message:[NSString stringWithFormat:@"本地版本为%@\nApp Store已发布%@\n请及时更新!",localVersion,netVersion] alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:(RQ_USER_MANAGER.qzgx == 1)? nil : @"取消" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:YES completion:^(NSUInteger selectedOtherButtonIndex) { if (selectedOtherButtonIndex == 0) { NSURL *url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/ji-su-jia-pei-kua-jia-xiao-ban/id1214200225?l=en&mt=8"]; [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; } }]; }]; } else { [RQ_SHARE_FUNCTION showAlertWithTitle:@"更新提示" message:[NSString stringWithFormat:@"本地版本为%@\nApp Store已发布%@\n请及时更新!",localVersion,netVersion] alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:[controllers containsObject:NSStringFromClass([RQ_SHARE_FUNCTION currentViewController].class)]? @"取消" : nil otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:YES completion:^(NSUInteger selectedOtherButtonIndex) { if (selectedOtherButtonIndex == 0) { NSURL *url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/ji-su-jia-pei-kua-jia-xiao-ban/id1214200225?l=en&mt=8"]; [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; } }]; } }]; } else { return; } }else{ //已是最新版 NSLog(@"不更"); } } }]; [task resume]; } /** * 展示大图 * * @author ZhangRong * @date 2020-06-16 14:30:55 * * @param dataSource 图片数组(Url数组) * @param currentIndex 当前标签 * @param isCanSave 是否保存图片 */ - (void)showPhotoBrowserWithDataSource:(NSArray *)dataSource currentIndex:(NSInteger)currentIndex isCanSave:(BOOL)isCanSave { if (dataSource.count == 0) { ShowMsg(@"暂无图片"); return; } NSMutableArray *photos = [NSMutableArray new]; self.dataSource = dataSource; self.isCanSave = isCanSave; [self.dataSource enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj isKindOfClass:[NSDictionary class]]) { // GKPhoto *photo = [GKPhoto new]; // photo.url = [NSURL URLWithString:obj[@"IMGPATH"]]; // [photos addObject:photo]; IDMPhoto *photo = [IDMPhoto photoWithFilePath:obj[@"IMGPATH"]]; [photos addObject:photo]; }else if ([obj isKindOfClass:[NSString class]]) { // // 替换为中等尺寸图片 // if ([obj rangeOfString:@"thumbnail"].location != NSNotFound) { // //这个要了没用噢 除非以后我们有清晰的图 // obj= [obj stringByReplacingOccurrencesOfString:@"thumbnail" withString:@"bmiddle"]; // } // NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet]; // NSString *str = [obj stringByTrimmingCharactersInSet:whitespace]; // if (str && ![str hasPrefix:@"http"]){ // str = [imgPreFix stringByAppendingString:[obj stringByTrimmingCharactersInSet:whitespace]]; // } // GKPhoto *photo = [GKPhoto new]; // photo.url = [NSURL URLWithString:str]; // [photos addObject:photo]; IDMPhoto *photo = [IDMPhoto photoWithURL:[NSURL URLWithString:obj]]; [photos addObject:photo]; }else if ([obj isKindOfClass:[UIImage class]]) { // GKPhoto *photo = [GKPhoto new]; // photo.image = obj; // [photos addObject:photo]; IDMPhoto *photo = [IDMPhoto photoWithImage:obj]; [photos addObject:photo]; } }]; [RQPhotoManager showPhotoBrowser:[RQ_SHARE_FUNCTION topViewController] photos:photos initialPageIndex:currentIndex delegate:self]; // self.pageControl = [[UIPageControl alloc] init]; // self.pageControl.numberOfPages = photos.count; // self.pageControl.currentPage = currentIndex; // self.pageControl.hidesForSinglePage = YES; // // self.browser = [GKPhotoBrowser photoBrowserWithPhotos:photos currentIndex:currentIndex]; // _browser.delegate = self; // _browser.showStyle = GKPhotoBrowserShowStyleNone; // 缩放显示 // _browser.hideStyle = GKPhotoBrowserHideStyleZoomScale; // 缩放隐藏 // _browser.loadStyle = GKPhotoBrowserLoadStyleDeterminate; // 不明确的加载方式带阴影 // _browser.maxZoomScale = 20.0f; // _browser.doubleZoomScale = 2.0f; // [_browser setupCoverViews:@[self.pageControl] layoutBlock:^(GKPhotoBrowser *photoBrowser, CGRect superFrame) { // CGFloat pointY = 0; // if (photoBrowser.isLandscape) { // pointY = superFrame.size.height - 20; // }else { // pointY = superFrame.size.height - 10 - kSafeAreaBottomHeight; // } // // self.pageControl.center = CGPointMake(superFrame.size.width * 0.5, pointY); // }]; // [_browser showFromVC:[RQ_SHARE_FUNCTION topViewController]]; } #pragma mark - GKPhotoBrowserDelegate - (void)photoBrowser:(GKPhotoBrowser *)browser didChangedIndex:(NSInteger)index { self.pageControl.currentPage = index; } - (void)photoBrowser:(GKPhotoBrowser *)browser longPressWithIndex:(NSInteger)index { if (!_isCanSave) return; [RQ_SHARE_FUNCTION showAlertWithTitle:nil message:nil alertControllerStyle:UIAlertControllerStyleActionSheet cancelButtonTitle:@"取消" otherButtonTitles:@[@"保存图片"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) { if (selectedOtherButtonIndex == 0) { GKPhoto *photo = self.browser.photos[self.browser.currentIndex]; NSData *imageData = nil; if ([photo.image isKindOfClass:[SDAnimatedImage class]]) { imageData = [(SDAnimatedImage *)photo.image animatedImageData]; }else { imageData = [photo.image sd_imageData]; } if (!imageData) return; [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ if (@available(iOS 9, *)) { PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAsset]; [request addResourceWithType:PHAssetResourceTypePhoto data:imageData options:nil]; request.creationDate = [NSDate date]; } } completionHandler:^(BOOL success, NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ if (success) { NSLog(@"保存照片成功"); ShowMsg(@"图片保存成功"); } else if (error) { ShowMsg(@"保存保存失败"); NSLog(@"保存照片出错:%@",error.localizedDescription); } }); }]; } }]; } #pragma mark - IDMPhotoBrowserDelegate - (void)photoBrowser:(IDMPhotoBrowser *)photoBrowser didDismissActionSheetWithButtonIndex:(NSUInteger)buttonIndex photoIndex:(NSUInteger)photoIndex { } /** * Mob隐私判断 * * @author ZhangRong * @date 2020-06-16 14:30:55 */ - (void)checkMobPolicyOnResult:(void (^_Nullable)(BOOL success))handler { //获取隐私协议 // [MobSDK getPrivacyPolicy:@"1" language:@"zh" compeletion:^(NSDictionary * _Nullable data, NSError * _Nullable error) { // // NSString *url = data[@"content"]; // if(url) { // [SMSDemoPolicyManager show:url compeletion:^(BOOL accept) { // //是否接受隐私协议 // [MobSDK uploadPrivacyPermissionStatus:accept onResult:^(BOOL success) { // handler(success); // }]; // // }]; // } // // }]; } - (void)saveObjectWithObject:(id)object ForKey:(NSString* )key { NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; if (!object) { [ud removeObjectForKey:key]; }else{ [ud setObject:object forKey:key]; } [ud synchronize]; } - (id)getObjectWithKey:(NSString *)key { NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; return [ud objectForKey:key]; } // 检测抓包 - (BOOL)checkProxySetting { NSDictionary *proxySettings = (__bridge NSDictionary *)(CFNetworkCopySystemProxySettings()); NSArray *proxies = (__bridge NSArray *)(CFNetworkCopyProxiesForURL((__bridge CFURLRef _Nonnull)([NSURL URLWithString:@"https://www.baidu.com"]), (__bridge CFDictionaryRef _Nonnull)(proxySettings))); NSLog(@"\n%@",proxies); NSDictionary *settings = proxies[0]; NSLog(@"%@",[settings objectForKey:(NSString *)kCFProxyHostNameKey]); NSLog(@"%@",[settings objectForKey:(NSString *)kCFProxyPortNumberKey]); NSLog(@"%@",[settings objectForKey:(NSString *)kCFProxyTypeKey]); if ([[settings objectForKey:(NSString *)kCFProxyTypeKey] isEqualToString:@"kCFProxyTypeNone"]) { NSLog(@"没设置代理"); return NO; } else { NSLog(@"设置了代理"); return YES; } } - (void)gotoWebViewWithUrlStr:(NSString *)url { RQCustomWebViewViewController *vc = [[RQCustomWebViewViewController alloc] init]; vc.url = url; vc.modalPresentationStyle = UIModalPresentationFullScreen; vc.webType = WebTypeAd; RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:vc]; [RQControllerHelper.topViewController presentViewController:nav animated:YES completion:nil]; } // 前往小程序 - (void)miniwithUserName:(NSString *)userName path:(NSString *)path { WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object]; launchMiniProgramReq.userName = userName; ////拉起的小程序的username launchMiniProgramReq.path = path; ////拉起小程序页面的可带参路径,不填默认拉起小程序首页,对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"。 launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; ///拉起小程序的类型 return [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) { }]; } - (UIWindow *)getKeyWindow { if (@available(iOS 13.0, *)) { for (UIWindowScene* windowScene in [UIApplication sharedApplication].connectedScenes) { if (windowScene.activationState == UISceneActivationStateForegroundActive) { for (UIWindow *window in windowScene.windows) { if (window.isKeyWindow) { return window; break; } } } } } else { return [UIApplication sharedApplication].keyWindow; } return nil; } @end