RQShareFunction.m 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  1. //
  2. // RQShareFunction.m
  3. // LN_School
  4. //
  5. // Created by 张嵘 on 2018/10/16.
  6. // Copyright © 2018 Danson. All rights reserved.
  7. //
  8. #import "RQShareFunction.h"
  9. #import "TZImagePickerController.h"//第三方相册
  10. #import "GKPhotoBrowser.h"
  11. //#import <MOBFoundation/MobSDK+Privacy.h>
  12. #import "SMSDemoPolicyManager.h"
  13. #import "SLShotViewController.h"
  14. #import "RQCustomWebViewViewController.h"
  15. static RQShareFunction *_instance = nil;
  16. static dispatch_once_t onceToken;
  17. @interface RQShareFunction ()<GKPhotoBrowserDelegate, IDMPhotoBrowserDelegate>
  18. @property (nonatomic, strong) NSArray *dataSource;
  19. @property (nonatomic, weak) GKPhotoBrowser *browser;
  20. @property (nonatomic, strong) UIPageControl *pageControl;
  21. @property (assign, readwrite, nonatomic) BOOL isCanSave;
  22. @end
  23. @implementation RQShareFunction
  24. + (instancetype)shareManager {
  25. return [[self alloc] init];
  26. }
  27. - (instancetype)init{
  28. dispatch_once(&onceToken, ^{
  29. _instance = [super init];
  30. });
  31. return _instance;
  32. }
  33. - (void)setShieldTopicIDArr:(NSArray *)shieldTopicIDArr {
  34. NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  35. [userDefault setObject:shieldTopicIDArr forKey:@"shieldTopicIDArr"];
  36. [userDefault synchronize];
  37. }
  38. - (NSArray *)shieldTopicIDArr {
  39. NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  40. NSArray *arr = (NSArray *)[userDefault objectForKey:@"shieldTopicIDArr"]? : [NSArray array];
  41. return arr;
  42. }
  43. - (void)setShieldPeopleIDArr:(NSArray *)shieldPeopleIDArr {
  44. NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  45. [userDefault setObject:shieldPeopleIDArr forKey:@"shieldPeopleIDArr"];
  46. [userDefault synchronize];
  47. }
  48. - (NSArray *)shieldPeopleIDArr {
  49. NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  50. NSArray *arr = (NSArray *)[userDefault objectForKey:@"shieldPeopleIDArr"]? : [NSArray array];
  51. return arr;
  52. }
  53. - (void)setAnnouncementIDArr:(NSArray *)announcementIDArr {
  54. NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  55. [userDefault setObject:announcementIDArr forKey:@"announcementIDArr"];
  56. [userDefault synchronize];
  57. }
  58. - (NSArray *)announcementIDArr {
  59. NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  60. NSArray *arr = (NSArray *)[userDefault objectForKey:@"announcementIDArr"]? : [NSArray array];
  61. return arr;
  62. }
  63. - (void)setCurrentUserInterfaceStyle:(UIUserInterfaceStyle)currentUserInterfaceStyle {
  64. NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  65. [userDefault setInteger:currentUserInterfaceStyle forKey:@"currentUserInterfaceStyle"];
  66. [userDefault synchronize];
  67. }
  68. - (UIUserInterfaceStyle)currentUserInterfaceStyle{
  69. NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
  70. if (@available(iOS 12.0, *)) {
  71. UIUserInterfaceStyle style = (UIUserInterfaceStyle)[userDefault integerForKey:@"currentUserInterfaceStyle"]? : UIUserInterfaceStyleUnspecified;
  72. return style;
  73. } else {
  74. return 0;
  75. }
  76. }
  77. // 理论计时不开启开启人脸比对模式 (不开启地市:台州-3310)
  78. - (NSArray *)theoryOfTimingNoOpenFaceToFaceArr {
  79. return @[@"3310"];
  80. }
  81. // 个人中心功能模块类型一(预约相关,模拟相关,资讯相关)(开启地市:福州-3501,厦门-3502,莆田-3503,泉州-3505)
  82. - (NSArray *)personalTypeOneCityCodeArr {
  83. return @[];
  84. }
  85. // 个人中心功能模块类型一(预约相关,资讯相关)(开启地市:温州-3303)
  86. - (NSArray *)personalTypeTwoCityCodeArr {
  87. return @[];
  88. }
  89. // 学车计时功能模块类型一(理论计时,实操计时,模拟计时,我的学时)(开启地市:福州-3501,厦门-3502,泉州-3505,温州-3303)
  90. - (NSArray *)timingTypeOneCityCodeArr {
  91. return @[];
  92. }
  93. // 学车计时功能模块类型二(理论计时,我的学时)(开启地市:莆田-3503)
  94. - (NSArray *)timingTypeTwoCityCodeArr {
  95. return @[];
  96. }
  97. // 理论计时类型一 (在科目二,科目三可以进行科目四的理论计时) (开启地市:福州-3501,莆田-3503,泉州-3505)
  98. - (NSArray *)theoryOfTimingTypeOneCityCodeArr {
  99. return @[];
  100. }
  101. // 理论计时类型二地市编号:null (在科目二可以进行科目四的理论计时)(开启地市:)
  102. - (NSArray *)theoryOfTimingTypeTwoCityCodeArr {
  103. return @[];
  104. }
  105. // 理论计时类型三 (在科目三可以进行科目四的理论计时)(开启地市:厦门-3502)
  106. - (NSArray *)theoryOfTimingTypeThreeCityCodeArr {
  107. return @[];
  108. }
  109. // 是否开启广告 默认0 不开通 1 开通
  110. - (BOOL)APP_AD {
  111. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"APP_AD"];
  112. BOOL appAd = [object boolValue];
  113. // return [RQ_SHARE_FUNCTION checkProxySetting]? NO : (object? appAd : YES);
  114. return object? appAd : YES;
  115. }
  116. //关闭插屏的时间(秒)
  117. - (NSInteger)APP_CLOSE {
  118. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"APP_CLOSE"];
  119. NSInteger appClose = [object integerValue];
  120. return appClose;
  121. }
  122. - (NSInteger)APP_AD_CYCLE {
  123. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"APP_AD_CYCLE"];
  124. NSInteger appAdCycle = [object integerValue];
  125. return appAdCycle;
  126. }
  127. //开屏广告展示概率
  128. - (NSInteger)APP_KP {
  129. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"APP_KP"];
  130. NSInteger appKp = [object integerValue];
  131. return appKp;
  132. }
  133. // 是否开启社区 1:开启 0:关闭
  134. - (NSInteger)APP_OPEN_COMMUNITY {
  135. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"APP_OPEN_COMMUNITY"];
  136. NSInteger appOpenCommunity = [object integerValue];
  137. return appOpenCommunity;
  138. }
  139. //审核开关
  140. - (NSInteger)APP_SWITCH {
  141. id object = [RQ_SHARE_FUNCTION getObjectWithKey:@"APP_SWITCH"];
  142. NSInteger appSwitch = [object integerValue];
  143. return appSwitch;
  144. }
  145. - (CGFloat)RQADViewHeight {
  146. return RQ_SCREEN_WIDTH / 3.f;
  147. }
  148. - (void)setAPP_AD:(BOOL)APP_AD {
  149. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithBool:APP_AD] ForKey:@"APP_AD"];
  150. }
  151. - (void)setAPP_CLOSE:(NSInteger)APP_CLOSE {
  152. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithInteger:APP_CLOSE] ForKey:@"APP_CLOSE"];
  153. }
  154. - (void)setAPP_AD_CYCLE:(NSInteger)APP_AD_CYCLE {
  155. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithInteger:APP_AD_CYCLE] ForKey:@"APP_AD_CYCLE"];
  156. }
  157. - (void)setAPP_OPEN_COMMUNITY:(NSInteger)APP_OPEN_COMMUNITY {
  158. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithInteger:APP_OPEN_COMMUNITY] ForKey:@"APP_OPEN_COMMUNITY"];
  159. }
  160. - (void)setAPP_KP:(NSInteger)APP_KP {
  161. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithInteger:APP_KP] ForKey:@"APP_KP"];
  162. }
  163. - (void)setAPP_SWITCH:(NSInteger)APP_SWITCH {
  164. [RQ_SHARE_FUNCTION saveObjectWithObject:[NSNumber numberWithInteger:APP_SWITCH] ForKey:@"APP_SWITCH"];
  165. }
  166. // 时间转换为时间戳,精确到微秒
  167. - (NSInteger)getTimeStampWithDate:(NSDate *)date {
  168. return [[NSNumber numberWithDouble:[date timeIntervalSince1970]] integerValue];
  169. }
  170. // 时间戳转换为时间
  171. - (NSDate *)getDateWithTimeStamp:(NSInteger)timeStamp {
  172. return [NSDate dateWithTimeIntervalSince1970:timeStamp];
  173. }
  174. // 一个时间戳与当前时间的间隔(s)
  175. - (NSInteger)getIntervalsWithTimeStamp:(NSInteger)timeStamp {
  176. return [[NSDate date] timeIntervalSinceDate:[self getDateWithTimeStamp:timeStamp]];
  177. }
  178. // 根据时间和formatter获取时间字符串
  179. - (NSString *)getTimeStrWithDate:(NSDate *)date formatter:(NSString *)formatterStr {
  180. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  181. formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
  182. // NSTimeZone *zone = [NSTimeZone systemTimeZone];
  183. // NSInteger interval = [zone secondsFromGMTForDate: date];
  184. // NSDate *localeDate = [date dateByAddingTimeInterval: interval];
  185. [formatter setDateFormat:formatterStr];
  186. NSString *dateStr = [formatter stringFromDate:date];
  187. return dateStr;
  188. }
  189. // 根据时间字符串和formatter获取时间戳(s)
  190. - (NSInteger)getTimeStampWithTimeStr:(NSString *)timeStr formatter:(NSString *)formatterStr {
  191. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  192. [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
  193. [formatter setDateFormat:formatterStr];
  194. NSDate *date = [formatter dateFromString:timeStr];
  195. NSInteger timeStamp = [self getTimeStampWithDate:date];
  196. return timeStamp * 1000;
  197. }
  198. // 一个时间戳与另一个时间戳的间隔(s)
  199. - (NSInteger)getIntervalsWithTimeStamp:(NSInteger)timeStamp anotherTimeStamp:(NSInteger)anotherTimeStamp {
  200. return [[self getDateWithTimeStamp:timeStamp] timeIntervalSinceDate:[self getDateWithTimeStamp:anotherTimeStamp]] * 0.001 * 0.001;
  201. }
  202. - (NSInteger)getTimeStampWithHour:(NSInteger)hour andMinute:(NSInteger)minute andDate:(NSDate *)date {
  203. NSCalendar *greCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
  204. NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"];
  205. [greCalendar setTimeZone: timeZone];
  206. NSDateComponents *dateComponents = [greCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date];
  207. // 定义一个NSDateComponents对象,设置一个时间点
  208. NSDateComponents *dateComponentsForDate = [[NSDateComponents alloc] init];
  209. [dateComponentsForDate setDay:dateComponents.day];
  210. [dateComponentsForDate setMonth:dateComponents.month];
  211. [dateComponentsForDate setYear:dateComponents.year];
  212. [dateComponentsForDate setHour:hour];
  213. [dateComponentsForDate setMinute:minute];
  214. NSDate *dateFromDateComponentsForDate = [greCalendar dateFromComponents:dateComponentsForDate];
  215. return [dateFromDateComponentsForDate timeIntervalSince1970];
  216. }
  217. #pragma mark - GetPhotos
  218. - (void)getPhotosWithGetPhotosWay:(GetPhotosWay)getPhotosWay size:(CGSize)size maxLength:(NSUInteger)maxLength maxImagesCount:(NSUInteger)maxImagesCount isCheckBody:(BOOL)isCheckBody photosBlock:(PhotosBlock)photosBlock {
  219. if (getPhotosWay == GetPhotosWay_Camera) {
  220. [RQPhotoManager fetchPhotosFromCamera:RQ_SHARE_FUNCTION.topViewController allowCrop:NO completion:^(UIImage * _Nonnull image, id _Nonnull asset) {
  221. if (image) {
  222. NSMutableArray *imagesArr = [NSMutableArray arrayWithObject:image];
  223. if (photosBlock) {
  224. photosBlock(imagesArr);
  225. }
  226. } else {
  227. if (photosBlock) {
  228. photosBlock(@[]);
  229. }
  230. }
  231. }];
  232. return;
  233. if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
  234. AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  235. if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {
  236. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"请在iPhone的“设置”-“隐私”-“相机”功能中,找到“极速驾培”打开相机访问权限" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  237. if (selectedOtherButtonIndex == 0) {
  238. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  239. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  240. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
  241. }
  242. }
  243. }];
  244. if (photosBlock) {
  245. photosBlock(@[]);
  246. }
  247. return;
  248. } else if (authStatus == AVAuthorizationStatusNotDetermined) {
  249. [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
  250. if (granted) {
  251. SLShotViewController *vc = [[SLShotViewController alloc] init];
  252. vc.isCheckBody = isCheckBody;
  253. [vc initTakePhotoBlock:^(UIImage * _Nullable image) {
  254. if (image) {
  255. NSMutableArray *imagesArr = [NSMutableArray arrayWithObject:image];
  256. if (photosBlock) {
  257. photosBlock(imagesArr);
  258. }
  259. } else {
  260. if (photosBlock) {
  261. photosBlock(@[]);
  262. }
  263. }
  264. }];
  265. dispatch_async(dispatch_get_main_queue(), ^{
  266. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  267. [[RQ_SHARE_FUNCTION topViewController] presentViewController:vc
  268. animated:NO
  269. completion:nil];
  270. });
  271. } else {
  272. if (photosBlock) {
  273. photosBlock(@[]);
  274. }
  275. }
  276. }];
  277. return;
  278. } else if (authStatus == AVAuthorizationStatusAuthorized) {
  279. SLShotViewController *vc = [[SLShotViewController alloc] init];
  280. vc.isCheckBody = isCheckBody;
  281. [vc initTakePhotoBlock:^(UIImage * _Nullable image) {
  282. if (image) {
  283. NSMutableArray *imagesArr = [NSMutableArray arrayWithObject:image];
  284. if (photosBlock) {
  285. photosBlock(imagesArr);
  286. }
  287. } else {
  288. if (photosBlock) {
  289. photosBlock(@[]);
  290. }
  291. }
  292. }];
  293. dispatch_async(dispatch_get_main_queue(), ^{
  294. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  295. [[RQ_SHARE_FUNCTION topViewController] presentViewController:vc
  296. animated:NO
  297. completion:nil];
  298. });
  299. } else {
  300. if (photosBlock) {
  301. photosBlock(@[]);
  302. }
  303. return;
  304. }
  305. } else {
  306. NSLog(@"相机调用失败");
  307. if (photosBlock) {
  308. photosBlock(@[]);
  309. }
  310. }
  311. }else if (getPhotosWay == GetPhotosWay_Album) {
  312. if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
  313. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:maxImagesCount ? maxImagesCount : 1 delegate:nil];
  314. imagePickerVc.naviBgColor = RQ_MAIN_COLOR;
  315. imagePickerVc.iconThemeColor = RQ_MAIN_COLOR;
  316. imagePickerVc.allowPickingVideo = NO;
  317. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isStop) {
  318. NSMutableArray *imagesDataStrArr = [NSMutableArray array];
  319. @synchronized (imagesDataStrArr) {
  320. for (UIImage *image in photos) {
  321. NSData *data;
  322. if (CGSizeEqualToSize(size, CGSizeZero)) {
  323. data = [UIImage resetSizeOfImageData:image maxSize:maxLength];
  324. }else {
  325. data = [UIImage resetSizeOfImageData:[image scaledAndCutToSize:size] maxSize:maxLength];
  326. }
  327. NSString *imgString = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
  328. [imagesDataStrArr addObject:imgString];
  329. }
  330. }
  331. if (photosBlock) {
  332. photosBlock(photos);
  333. }
  334. }];
  335. dispatch_async(dispatch_get_main_queue(), ^{
  336. imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
  337. [[RQ_SHARE_FUNCTION topViewController] presentViewController:imagePickerVc animated:YES completion:nil];
  338. });
  339. }else{
  340. NSLog(@"相册调用失败");
  341. }
  342. }
  343. }
  344. #pragma mark - RQAlertViewController
  345. - (void)showAlertAtViewController:(nonnull UIViewController *)viewController
  346. WithTitle:(nullable NSString *)title
  347. message:(nullable NSString *)message
  348. alertControllerStyle:(UIAlertControllerStyle)alertControllerStyle
  349. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  350. otherButtonTitles:(nullable NSArray *)otherButtonTitles
  351. otherButtonStyles:(nullable NSDictionary *)otherButtonStyles
  352. preferredActionTitle:(nullable NSString *)preferredActionTitle
  353. showInWindow:(BOOL)showInWindow
  354. completion:(nullable RQAlertViewCompletion)completion {
  355. @weakify(self)
  356. __block UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:alertControllerStyle];
  357. void (^alertActionHandler) (UIAlertAction *) = [^(UIAlertAction *action) {
  358. if (completion) {
  359. if (action.style == UIAlertActionStyleCancel) {
  360. completion(NSNotFound);
  361. }else {
  362. NSUInteger index = [alertController.actions indexOfObject:action];
  363. completion(cancelButtonTitle? index - 1 : index);
  364. }
  365. }
  366. alertController = nil;
  367. } copy];
  368. if (cancelButtonTitle) {
  369. UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:alertActionHandler];
  370. if (@available(iOS 9.0, *)) {
  371. [cancleAction setValue:RQ_MAIN_COLOR forKey:@"_titleTextColor"];
  372. } else {
  373. // Fallback on earlier versions
  374. }
  375. [alertController addAction:cancleAction];
  376. }
  377. if (otherButtonTitles.count == 0) {
  378. dispatch_async(dispatch_get_main_queue(), ^{
  379. @strongify(self)
  380. if (showInWindow) {
  381. [[self getKeyWindow].rootViewController presentViewController:alertController animated:YES completion:nil];
  382. } else {
  383. [[RQ_SHARE_FUNCTION topViewController] presentViewController:alertController animated:YES completion:nil];
  384. }
  385. });
  386. }else {
  387. [otherButtonTitles.rac_sequence.signal subscribeNext:^(NSString * buttonTitle) {
  388. NSNumber *actionStyleNumber = [otherButtonStyles valueForKey:buttonTitle];
  389. UIAlertActionStyle actionStyle = UIAlertActionStyleDefault;
  390. if (actionStyleNumber) {
  391. actionStyle = [actionStyleNumber integerValue];
  392. }
  393. UIAlertAction *action = [UIAlertAction actionWithTitle:buttonTitle
  394. style:actionStyle
  395. handler:alertActionHandler];
  396. if (@available(iOS 9.0, *)) {
  397. [action setValue:RQ_MAIN_COLOR forKey:@"_titleTextColor"];
  398. } else {
  399. // Fallback on earlier versions
  400. }
  401. [alertController addAction:action];
  402. ///Support for iOS9 add preferredAction for highlights the text of that action
  403. if ([alertController respondsToSelector:@selector(setPreferredAction:)]) {
  404. if ([preferredActionTitle isEqualToString:buttonTitle]) {
  405. if (@available(iOS 9.0, *)) {
  406. [alertController setPreferredAction:action];
  407. } else {
  408. // Fallback on earlier versions
  409. }
  410. }
  411. }
  412. } completed:^{
  413. dispatch_async(dispatch_get_main_queue(), ^{
  414. @strongify(self)
  415. if (showInWindow) {
  416. [[self getKeyWindow].rootViewController presentViewController:alertController animated:YES completion:nil];
  417. } else {
  418. [[RQ_SHARE_FUNCTION topViewController] presentViewController:alertController animated:YES completion:nil];
  419. }
  420. });
  421. }];
  422. }
  423. }
  424. - (void)showAlertWithTitle:(nullable NSString *)title
  425. message:(nullable NSString *)message
  426. alertControllerStyle:(UIAlertControllerStyle)alertControllerStyle
  427. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  428. otherButtonTitles:(nullable NSArray *)otherButtonTitles
  429. otherButtonStyles:(nullable NSDictionary *)otherButtonStyles
  430. preferredActionTitle:(nullable NSString *)preferredActionTitle
  431. showInWindow:(BOOL)showInWindow
  432. completion:(nullable RQAlertViewCompletion)completion{
  433. [self showAlertAtViewController:[RQ_SHARE_FUNCTION topViewController]
  434. WithTitle:title
  435. message:message
  436. alertControllerStyle:alertControllerStyle
  437. cancelButtonTitle:cancelButtonTitle
  438. otherButtonTitles:otherButtonTitles
  439. otherButtonStyles:otherButtonStyles
  440. preferredActionTitle:preferredActionTitle
  441. showInWindow:showInWindow
  442. completion:completion];
  443. }
  444. - (void)showAlertWithTitle:(nullable NSString *)title
  445. message:(nullable NSString *)message
  446. alertControllerStyle:(UIAlertControllerStyle)alertControllerStyle
  447. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  448. otherButtonTitles:(nullable NSArray *)otherButtonTitles
  449. otherButtonStyles:(nullable NSDictionary *)otherButtonStyles
  450. showInWindow:(BOOL)showInWindow
  451. completion:(nullable RQAlertViewCompletion)completion {
  452. [self showAlertAtViewController:[RQ_SHARE_FUNCTION topViewController]
  453. WithTitle:title
  454. message:message
  455. alertControllerStyle:alertControllerStyle
  456. cancelButtonTitle:cancelButtonTitle
  457. otherButtonTitles:otherButtonTitles
  458. otherButtonStyles:otherButtonStyles
  459. preferredActionTitle:nil
  460. showInWindow:showInWindow
  461. completion:completion];
  462. }
  463. - (void)showAlertWithMessage:(nullable NSString *)message
  464. completion:(nullable RQAlertViewCompletion)completion {
  465. [self showAlertAtViewController:[RQ_SHARE_FUNCTION topViewController]
  466. WithTitle:@""
  467. message:message
  468. alertControllerStyle:UIAlertControllerStyleAlert
  469. cancelButtonTitle:@"确定"
  470. otherButtonTitles:nil
  471. otherButtonStyles:nil
  472. preferredActionTitle:nil
  473. showInWindow:NO
  474. completion:completion];
  475. }
  476. #pragma mark - Custom Way
  477. - (UIViewController *)topViewController {
  478. return [RQ_SHARE_FUNCTION topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
  479. }
  480. - (UIViewController *)topViewController:(UIViewController*)rootViewController {
  481. if (rootViewController.presentedViewController == nil ||
  482. rootViewController.presentedViewController.beingDismissed) {
  483. return rootViewController;
  484. }
  485. if ([rootViewController.presentedViewController isMemberOfClass:[UINavigationController class]]) {
  486. UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
  487. UIViewController *lastViewController = [[navigationController viewControllers] lastObject];
  488. return [RQ_SHARE_FUNCTION topViewController:lastViewController];
  489. }
  490. UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController;
  491. return [RQ_SHARE_FUNCTION topViewController:presentedViewController];
  492. }
  493. - (UIViewController *)currentViewController {
  494. UIViewController *resultVC;
  495. resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
  496. /// RQ Fixed : 这里必须要判断一下,否则取出来永远都是 RQMainTabBarViewController。这是架构上小缺(特)陷(性)。因为RQMainTabBarViewController的子控制器是UITabBarController,所以需要递归UITabBarController的所有的子控制器
  497. while (resultVC.presentedViewController) {
  498. resultVC = [self _topViewController:resultVC.presentedViewController];
  499. }
  500. return resultVC;
  501. }
  502. - (UIViewController *)_topViewController:(UIViewController *)vc {
  503. if ([vc isKindOfClass:[UINavigationController class]]) {
  504. return [self _topViewController:[(UINavigationController *)vc topViewController]];
  505. } else if ([vc isKindOfClass:[UITabBarController class]]) {
  506. return [self _topViewController:[(UITabBarController *)vc selectedViewController]];
  507. } else {
  508. return vc;
  509. }
  510. }
  511. //- (NSData *)compressQualityWithImage:(UIImage *)image MaxLength:(NSInteger)maxLength {
  512. // CGFloat compression = 1;
  513. // NSData *data = UIImageJPEGRepresentation(image, compression);
  514. // if (data.length < maxLength) {
  515. // return data;
  516. // }
  517. // CGFloat max = 1;
  518. // CGFloat min = 0;
  519. // NSData *lastData;
  520. // for (int i = 0; i < 99; ++i) {
  521. // compression = (max + min) / 2;
  522. // data = UIImageJPEGRepresentation(image, compression);
  523. // if (data.length == lastData.length) {
  524. // return data;
  525. // }else {
  526. // lastData = data;
  527. // }
  528. // if (data.length < maxLength * 0.9) {
  529. // min = compression;
  530. // } else if (data.length > maxLength) {
  531. // max = compression;
  532. // } else {
  533. // break;
  534. // }
  535. // }
  536. // return data;
  537. //}
  538. - (void)showGuidePicture {
  539. UIButton* btn = [[UIButton alloc] initWithFrame:kFrame];
  540. [myDelegate.window addSubview:btn];
  541. [btn setImage:[UIImage imageNamed:@"welGuide2.png"] forState:UIControlStateNormal];
  542. UIImageView* iv;
  543. iv = [[UIImageView alloc] initWithFrame:CGRectMake(3, 11, 70, 70)];
  544. [iv setImage:[UIImage imageNamed:@"welGuide1.png"]];
  545. [btn addSubview:iv];
  546. [btn addTarget:self action:@selector(removeBtn:) forControlEvents:UIControlEventTouchUpInside];
  547. }
  548. - (void)removeBtn:(UIButton *)btn {
  549. [btn removeFromSuperview];
  550. }
  551. #pragma mark - 检查版本更新
  552. - (void)checkVersion {
  553. /// 在当前页面有弹窗 以及在模拟计时页面 理论计时页面 模拟考试界面 不弹出更新提示
  554. NSArray *controllers = @[@"UIAlertController", @"ImitatePeriodVC", @"PeriodVC"];
  555. NSLog(@"string---Class-----%@",NSStringFromClass([RQ_SHARE_FUNCTION currentViewController].class));
  556. if (![Util connectedToNetWork]) {
  557. return;
  558. }
  559. NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
  560. NSString *localVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
  561. NSString *URL = @"http://itunes.apple.com/cn/lookup?id=1214200225";
  562. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:URL] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
  563. [request setHTTPMethod:@"POST"];
  564. NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
  565. //这个导致部分手机网络不好时候出现闪退情况
  566. if (!data) {
  567. return;
  568. }
  569. //如果data等于nil的时候 再去解析 会发生崩溃
  570. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  571. if (!dic) {
  572. return;
  573. }
  574. NSArray *infoArray = [dic objectForKey:@"results"];
  575. if ([infoArray count]) {
  576. NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
  577. NSString *netVersion = [releaseInfo objectForKey:@"version"];
  578. //NSLog(@"AppStore-->%@,手机上-->%@",lastVersion,currentVersion);
  579. // 线上版本号
  580. NSInteger netInt = [[netVersion stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue];
  581. // 本地版本号
  582. NSInteger localInt = [[localVersion stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue];
  583. if (netInt > localInt) {
  584. NSLog(@"更新");
  585. if (RQ_USER_MANAGER.isLogin) {
  586. [[[RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {
  587. [subscriber sendNext:@1];
  588. [subscriber sendCompleted];
  589. return [RACDisposable disposableWithBlock:^{
  590. }];
  591. }] delay:2] subscribeCompleted:^{
  592. /// 检查版本更新
  593. if (RQ_AD_MANAGER.splashIsShow) {
  594. [[[RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {
  595. [subscriber sendNext:@1];
  596. [subscriber sendCompleted];
  597. return [RACDisposable disposableWithBlock:^{
  598. }];
  599. }] delay:5] subscribeCompleted:^{
  600. [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) {
  601. if (selectedOtherButtonIndex == 0) {
  602. NSURL *url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/ji-su-jia-pei-kua-jia-xiao-ban/id1214200225?l=en&mt=8"];
  603. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
  604. }
  605. }];
  606. }];
  607. } else {
  608. [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) {
  609. if (selectedOtherButtonIndex == 0) {
  610. NSURL *url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/ji-su-jia-pei-kua-jia-xiao-ban/id1214200225?l=en&mt=8"];
  611. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
  612. }
  613. }];
  614. }
  615. }];
  616. } else {
  617. return;
  618. }
  619. }else{
  620. //已是最新版
  621. NSLog(@"不更");
  622. }
  623. }
  624. }];
  625. [task resume];
  626. }
  627. /**
  628. * 展示大图
  629. *
  630. * @author ZhangRong
  631. * @date 2020-06-16 14:30:55
  632. *
  633. * @param dataSource 图片数组(Url数组)
  634. * @param currentIndex 当前标签
  635. * @param isCanSave 是否保存图片
  636. */
  637. - (void)showPhotoBrowserWithDataSource:(NSArray *)dataSource currentIndex:(NSInteger)currentIndex isCanSave:(BOOL)isCanSave {
  638. if (dataSource.count == 0) {
  639. ShowMsg(@"暂无图片");
  640. return;
  641. }
  642. NSMutableArray *photos = [NSMutableArray new];
  643. self.dataSource = dataSource;
  644. self.isCanSave = isCanSave;
  645. [self.dataSource enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  646. if ([obj isKindOfClass:[NSDictionary class]]) {
  647. // GKPhoto *photo = [GKPhoto new];
  648. // photo.url = [NSURL URLWithString:obj[@"IMGPATH"]];
  649. // [photos addObject:photo];
  650. IDMPhoto *photo = [IDMPhoto photoWithFilePath:obj[@"IMGPATH"]];
  651. [photos addObject:photo];
  652. }else if ([obj isKindOfClass:[NSString class]]) {
  653. // // 替换为中等尺寸图片
  654. // if ([obj rangeOfString:@"thumbnail"].location != NSNotFound) {
  655. // //这个要了没用噢 除非以后我们有清晰的图
  656. // obj= [obj stringByReplacingOccurrencesOfString:@"thumbnail" withString:@"bmiddle"];
  657. // }
  658. // NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
  659. // NSString *str = [obj stringByTrimmingCharactersInSet:whitespace];
  660. // if (str && ![str hasPrefix:@"http"]){
  661. // str = [imgPreFix stringByAppendingString:[obj stringByTrimmingCharactersInSet:whitespace]];
  662. // }
  663. // GKPhoto *photo = [GKPhoto new];
  664. // photo.url = [NSURL URLWithString:str];
  665. // [photos addObject:photo];
  666. IDMPhoto *photo = [IDMPhoto photoWithURL:[NSURL URLWithString:obj]];
  667. [photos addObject:photo];
  668. }else if ([obj isKindOfClass:[UIImage class]]) {
  669. // GKPhoto *photo = [GKPhoto new];
  670. // photo.image = obj;
  671. // [photos addObject:photo];
  672. IDMPhoto *photo = [IDMPhoto photoWithImage:obj];
  673. [photos addObject:photo];
  674. }
  675. }];
  676. [RQPhotoManager showPhotoBrowser:[RQ_SHARE_FUNCTION topViewController] photos:photos initialPageIndex:currentIndex delegate:self];
  677. // self.pageControl = [[UIPageControl alloc] init];
  678. // self.pageControl.numberOfPages = photos.count;
  679. // self.pageControl.currentPage = currentIndex;
  680. // self.pageControl.hidesForSinglePage = YES;
  681. //
  682. // self.browser = [GKPhotoBrowser photoBrowserWithPhotos:photos currentIndex:currentIndex];
  683. // _browser.delegate = self;
  684. // _browser.showStyle = GKPhotoBrowserShowStyleNone; // 缩放显示
  685. // _browser.hideStyle = GKPhotoBrowserHideStyleZoomScale; // 缩放隐藏
  686. // _browser.loadStyle = GKPhotoBrowserLoadStyleDeterminate; // 不明确的加载方式带阴影
  687. // _browser.maxZoomScale = 20.0f;
  688. // _browser.doubleZoomScale = 2.0f;
  689. // [_browser setupCoverViews:@[self.pageControl] layoutBlock:^(GKPhotoBrowser *photoBrowser, CGRect superFrame) {
  690. // CGFloat pointY = 0;
  691. // if (photoBrowser.isLandscape) {
  692. // pointY = superFrame.size.height - 20;
  693. // }else {
  694. // pointY = superFrame.size.height - 10 - kSafeAreaBottomHeight;
  695. // }
  696. //
  697. // self.pageControl.center = CGPointMake(superFrame.size.width * 0.5, pointY);
  698. // }];
  699. // [_browser showFromVC:[RQ_SHARE_FUNCTION topViewController]];
  700. }
  701. #pragma mark - GKPhotoBrowserDelegate
  702. - (void)photoBrowser:(GKPhotoBrowser *)browser didChangedIndex:(NSInteger)index {
  703. self.pageControl.currentPage = index;
  704. }
  705. - (void)photoBrowser:(GKPhotoBrowser *)browser longPressWithIndex:(NSInteger)index {
  706. if (!_isCanSave) return;
  707. [RQ_SHARE_FUNCTION showAlertWithTitle:nil message:nil alertControllerStyle:UIAlertControllerStyleActionSheet cancelButtonTitle:@"取消" otherButtonTitles:@[@"保存图片"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  708. if (selectedOtherButtonIndex == 0) {
  709. GKPhoto *photo = self.browser.photos[self.browser.currentIndex];
  710. NSData *imageData = nil;
  711. if ([photo.image isKindOfClass:[SDAnimatedImage class]]) {
  712. imageData = [(SDAnimatedImage *)photo.image animatedImageData];
  713. }else {
  714. imageData = [photo.image sd_imageData];
  715. }
  716. if (!imageData) return;
  717. [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
  718. if (@available(iOS 9, *)) {
  719. PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAsset];
  720. [request addResourceWithType:PHAssetResourceTypePhoto data:imageData options:nil];
  721. request.creationDate = [NSDate date];
  722. }
  723. } completionHandler:^(BOOL success, NSError *error) {
  724. dispatch_async(dispatch_get_main_queue(), ^{
  725. if (success) {
  726. NSLog(@"保存照片成功");
  727. ShowMsg(@"图片保存成功");
  728. } else if (error) {
  729. ShowMsg(@"保存保存失败");
  730. NSLog(@"保存照片出错:%@",error.localizedDescription);
  731. }
  732. });
  733. }];
  734. }
  735. }];
  736. }
  737. #pragma mark - IDMPhotoBrowserDelegate
  738. - (void)photoBrowser:(IDMPhotoBrowser *)photoBrowser didDismissActionSheetWithButtonIndex:(NSUInteger)buttonIndex photoIndex:(NSUInteger)photoIndex {
  739. }
  740. /**
  741. * Mob隐私判断
  742. *
  743. * @author ZhangRong
  744. * @date 2020-06-16 14:30:55
  745. */
  746. - (void)checkMobPolicyOnResult:(void (^_Nullable)(BOOL success))handler {
  747. //获取隐私协议
  748. // [MobSDK getPrivacyPolicy:@"1" language:@"zh" compeletion:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
  749. //
  750. // NSString *url = data[@"content"];
  751. // if(url) {
  752. // [SMSDemoPolicyManager show:url compeletion:^(BOOL accept) {
  753. // //是否接受隐私协议
  754. // [MobSDK uploadPrivacyPermissionStatus:accept onResult:^(BOOL success) {
  755. // handler(success);
  756. // }];
  757. //
  758. // }];
  759. // }
  760. //
  761. // }];
  762. }
  763. - (void)saveObjectWithObject:(id)object ForKey:(NSString* )key {
  764. NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
  765. if (!object) {
  766. [ud removeObjectForKey:key];
  767. }else{
  768. [ud setObject:object forKey:key];
  769. }
  770. [ud synchronize];
  771. }
  772. - (id)getObjectWithKey:(NSString *)key {
  773. NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
  774. return [ud objectForKey:key];
  775. }
  776. // 检测抓包
  777. - (BOOL)checkProxySetting {
  778. NSDictionary *proxySettings = (__bridge NSDictionary *)(CFNetworkCopySystemProxySettings());
  779. NSArray *proxies = (__bridge NSArray *)(CFNetworkCopyProxiesForURL((__bridge CFURLRef _Nonnull)([NSURL URLWithString:@"https://www.baidu.com"]), (__bridge CFDictionaryRef _Nonnull)(proxySettings)));
  780. NSLog(@"\n%@",proxies);
  781. NSDictionary *settings = proxies[0];
  782. NSLog(@"%@",[settings objectForKey:(NSString *)kCFProxyHostNameKey]);
  783. NSLog(@"%@",[settings objectForKey:(NSString *)kCFProxyPortNumberKey]);
  784. NSLog(@"%@",[settings objectForKey:(NSString *)kCFProxyTypeKey]);
  785. if ([[settings objectForKey:(NSString *)kCFProxyTypeKey] isEqualToString:@"kCFProxyTypeNone"]) {
  786. NSLog(@"没设置代理");
  787. return NO;
  788. } else {
  789. NSLog(@"设置了代理");
  790. return YES;
  791. }
  792. }
  793. - (void)gotoWebViewWithUrlStr:(NSString *)url {
  794. RQCustomWebViewViewController *vc = [[RQCustomWebViewViewController alloc] init];
  795. vc.url = url;
  796. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  797. vc.webType = WebTypeAd;
  798. RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:vc];
  799. [RQControllerHelper.topViewController presentViewController:nav animated:YES completion:nil];
  800. }
  801. // 前往小程序
  802. - (void)miniwithUserName:(NSString *)userName path:(NSString *)path {
  803. WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
  804. launchMiniProgramReq.userName = userName; ////拉起的小程序的username
  805. launchMiniProgramReq.path = path; ////拉起小程序页面的可带参路径,不填默认拉起小程序首页,对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"。
  806. launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; ///拉起小程序的类型
  807. return [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
  808. }];
  809. }
  810. - (UIWindow *)getKeyWindow {
  811. if (@available(iOS 13.0, *)) {
  812. for (UIWindowScene* windowScene in [UIApplication sharedApplication].connectedScenes) {
  813. if (windowScene.activationState == UISceneActivationStateForegroundActive) {
  814. for (UIWindow *window in windowScene.windows) {
  815. if (window.isKeyWindow) {
  816. return window;
  817. break;
  818. }
  819. }
  820. }
  821. }
  822. } else {
  823. return [UIApplication sharedApplication].keyWindow;
  824. }
  825. return nil;
  826. }
  827. @end