// // RQShareFunction.m // LN_School // // Created by 张嵘 on 2018/10/16. // Copyright © 2018 Danson. All rights reserved. // #import "RQShareFunction.h" #import "TZImagePickerController.h"//第三方相册 #import "TabBarController.h" #import "GKPhotoBrowser.h" //#import #import "SMSDemoPolicyManager.h" #import "LocalNotificationManager.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; } // 时间转换为时间戳,精确到微秒 - (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]]; } - (NSString *)getCurrentTimeString { NSDate *date = [NSDate date]; NSDateFormatter *formatter = [NSDateFormatter rq_defaultDateFormatter]; NSString *dateString = [formatter stringFromDate:date]; NSString *timeString = dateString; return timeString; } - (NSString *)getCurrentTimeStringWithTimeStamp:(NSInteger)timeStamp { NSDate *date = [NSDate date]; NSInteger timeStamp0 = [self getTimeStampWithDate:date]; NSInteger timeStamp1 = timeStamp0 + (timeStamp * 1000 * 1000); NSDate *date1 = [self getDateWithTimeStamp:timeStamp1]; NSDateFormatter *formatter = [NSDateFormatter rq_defaultDateFormatter]; NSString *dateString = [formatter stringFromDate:date1]; NSString *timeString = dateString; NSLog(@"%@",timeString); return timeString; } // 根据时间字符串和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; } #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 } dispatch_async(dispatch_get_main_queue(), ^{ [alertController addAction:action]; }); ///Support for iOS9 add preferredAction for highlights the text of that action if ([alertController respondsToSelector:@selector(setPreferredAction:)]) { if ([preferredActionTitle isEqualToString:buttonTitle]) { [alertController setPreferredAction:action]; } } } 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)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)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]; } }); }]; } } #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的所有的子控制器 if ([resultVC isKindOfClass:[TabBarController class]]) { TabBarController *mainVc = (TabBarController *)resultVC; resultVC = [self _topViewController:mainVc.tabBarController]; } 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; } /** * 展示大图 * * @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 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); } }); }]; } }]; } /** * 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) { // handler(YES); // [SMSDemoPolicyManager show:url compeletion:^(BOOL accept) { // //是否接受隐私协议 // [MobSDK uploadPrivacyPermissionStatus:accept onResult:^(BOOL success) { // NSLog(@"%@",success? @"MobSDK隐私授权成功" : @"MobSDK隐私授权失败"); // }]; // // }]; // } // // }]; } - (CGFloat)RQADViewHeight { return RQ_SCREEN_WIDTH / 3.f; } - (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]; 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]; NSMutableArray *imagesDataStrArr = [NSMutableArray arrayWithObject:imgString]; if (photosBlock) { photosBlock(imagesArr, imagesDataStrArr); } } 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 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]; 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]; NSMutableArray *imagesDataStrArr = [NSMutableArray arrayWithObject:imgString]; if (photosBlock) { photosBlock(imagesArr, imagesDataStrArr); } } 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]; 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]; NSMutableArray *imagesDataStrArr = [NSMutableArray arrayWithObject:imgString]; if (photosBlock) { photosBlock(imagesArr, imagesDataStrArr); } } 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 = defGreen; imagePickerVc.iconThemeColor = defGreen; 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, imagesDataStrArr); } }]; dispatch_async(dispatch_get_main_queue(), ^{ imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen; [[RQ_SHARE_FUNCTION topViewController] presentViewController:imagePickerVc animated:YES completion:nil]; }); }else{ NSLog(@"相册调用失败"); } } } - (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 { RQWebViewViewController *vc = [[RQWebViewViewController alloc] init]; vc.url = url; vc.modalPresentationStyle = UIModalPresentationFullScreen; vc.webType = WebTypeDefault; RQBaseNavigationController *nav = [[RQBaseNavigationController alloc] initWithRootViewController:vc]; [RQ_SHARE_FUNCTION.topViewController presentViewController:nav animated:NO 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