123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491 |
- //
- // RQShareFunction.m
- // LN_School
- //
- // Created by 张嵘 on 2018/10/16.
- // Copyright © 2018 Danson. All rights reserved.
- //
- #import "RQShareFunction.h"
- #import "TZImagePickerController.h"//第三方相册
- #import <MOBFoundation/MobSDK+Privacy.h>
- static RQShareFunction *_instance = nil;
- static dispatch_once_t onceToken;
- @interface RQShareFunction ()
- @property (nonatomic, strong) NSArray *dataSource;
- @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;
- }
- }
- // 个人中心功能模块类型一(预约相关,模拟相关,资讯相关)(开启地市:福州-3501,厦门-3502,莆田-3503)
- - (NSArray *)personalTypeOneCityCodeArr {
- return @[@"3501", @"3502", @"3503"];
- }
- // 个人中心功能模块类型一(预约相关,资讯相关)(开启地市:温州-3303)
- - (NSArray *)personalTypeTwoCityCodeArr {
- return @[@"3303"];
- }
- // 学车计时功能模块类型一(理论计时,实操计时,模拟计时,我的学时)(开启地市:福州-3501,厦门-3502,温州-3303)
- - (NSArray *)timingTypeOneCityCodeArr {
- return @[@"3501", @"3502", @"3303"];
- }
- // 学车计时功能模块类型二(理论计时,我的学时)(开启地市:莆田-3503)
- - (NSArray *)timingTypeTwoCityCodeArr {
- return @[@"3503"];
- }
- // 理论计时类型一 (在科目二,科目三可以进行科目四的理论计时) (开启地市:福州-3501,莆田-3503)
- - (NSArray *)theoryOfTimingTypeOneCityCodeArr {
- return @[@"3501", @"3503"];
- }
- // 理论计时类型二地市编号:null (在科目二可以进行科目四的理论计时)(开启地市:)
- - (NSArray *)theoryOfTimingTypeTwoCityCodeArr {
- return @[];
- }
- // 理论计时类型三 (在科目三可以进行科目四的理论计时)(开启地市:厦门-3502)
- - (NSArray *)theoryOfTimingTypeThreeCityCodeArr {
- return @[@"3502"];
- }
- // 是否开启广告 默认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;
- }
- //关闭广告概率 0-100% 关闭广告概率
- - (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;
- }
- - (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"];
- }
- // 时间转换为时间戳,精确到微秒
- - (NSInteger)getTimeStampWithDate:(NSDate *)date {
- return [[NSNumber numberWithDouble:[date timeIntervalSince1970] * 1000 * 1000] integerValue];
- }
- // 时间戳转换为时间
- - (NSDate *)getDateWithTimeStamp:(NSInteger)timeStamp {
- return [NSDate dateWithTimeIntervalSince1970:timeStamp * 0.001 * 0.001];
- }
- // 一个时间戳与当前时间的间隔(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];
- // 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 setDateFormat:formatterStr];
- return [self getTimeStampWithDate:[formatter dateFromString:timeStr]] * 0.001 * 0.001;
- }
- // 一个时间戳与另一个时间戳的间隔(s)
- - (NSInteger)getIntervalsWithTimeStamp:(NSInteger)timeStamp anotherTimeStamp:(NSInteger)anotherTimeStamp {
- return [[self getDateWithTimeStamp:timeStamp] timeIntervalSinceDate:[self getDateWithTimeStamp:anotherTimeStamp]] * 0.001 * 0.001;
- }
- #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
- completion:(nullable RQAlertViewCompletion)completion {
- __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:defGreen forKey:@"_titleTextColor"];
- } else {
- // Fallback on earlier versions
- }
- [alertController addAction:cancleAction];
- }
-
- if (otherButtonTitles.count == 0) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [[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:defGreen 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(), ^{
- [[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
- completion:(nullable RQAlertViewCompletion)completion{
- [self showAlertAtViewController:[RQ_SHARE_FUNCTION topViewController]
- WithTitle:title
- message:message
- alertControllerStyle:alertControllerStyle
- cancelButtonTitle:cancelButtonTitle
- otherButtonTitles:otherButtonTitles
- otherButtonStyles:otherButtonStyles
- preferredActionTitle:preferredActionTitle
- 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
- completion:(nullable RQAlertViewCompletion)completion {
- [self showAlertAtViewController:[RQ_SHARE_FUNCTION topViewController]
- WithTitle:title
- message:message
- alertControllerStyle:alertControllerStyle
- cancelButtonTitle:cancelButtonTitle
- otherButtonTitles:otherButtonTitles
- otherButtonStyles:otherButtonStyles
- preferredActionTitle:nil
- 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
- 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]];
-
- 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", @"ExerciseVC", @"ImitatePeriodVC", @"PeriodVC"];
- NSLog(@"string---Class-----%@",NSStringFromClass([RQ_SHARE_FUNCTION currentViewController].class));
- if ([controllers containsObject:NSStringFromClass([RQ_SHARE_FUNCTION currentViewController].class)]) {
- return;
- }
- 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(@"更新");
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"更新提示" message:[NSString stringWithFormat:@"本地版本为%@\nApp Store已发布%@\n请及时更新!",localVersion,netVersion] alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:nil otherButtonTitles:@[@"确定"] otherButtonStyles:nil 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];
- }
- }];
- }else{
- //已是最新版
- NSLog(@"不更");
- }
- }
- }];
-
- [task resume];
- }
- - (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;
- }
- }
- @end
|