Commit b086d257d17b85205859b4599b0184b4a18143af
1 parent
e77c60aa
no message
Showing
10 changed files
with
539 additions
and
8 deletions
CNLiveQrCodeModule/Classes/Controller/CNLiveGenerateCodeController.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveGenerateCodeController.h | |
| 3 | +// CNLiveQrCodeModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 生成二维码 | |
| 11 | + */ | |
| 12 | + | |
| 13 | +#import <UIKit/UIKit.h> | |
| 14 | + | |
| 15 | +NS_ASSUME_NONNULL_BEGIN | |
| 16 | + | |
| 17 | +@interface CNLiveGenerateCodeController : UIViewController | |
| 18 | + | |
| 19 | +@end | |
| 20 | + | |
| 21 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveQrCodeModule/Classes/Controller/CNLiveGenerateCodeController.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveGenerateCodeController.m | |
| 3 | +// CNLiveQrCodeModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright (c) 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNLiveGenerateCodeController.h" | |
| 10 | +#import <Photos/Photos.h> | |
| 11 | +#import <Accelerate/Accelerate.h> | |
| 12 | + | |
| 13 | +#import "QMUIKit.h" | |
| 14 | +#import <Masonry/Masonry.h> | |
| 15 | +#import <SDWebImage/SDWebImage.h> | |
| 16 | + | |
| 17 | +#import "CNLiveQrCodeNavigationBar.h" | |
| 18 | +#import "CNLiveGenerateCodeView.h" | |
| 19 | +#import "CNLiveScanQrCodeController.h" | |
| 20 | + | |
| 21 | +@interface CNLiveGenerateCodeController ()<CNLiveQrCodeNavigationBarDelegate,QMUIAlertControllerDelegate> | |
| 22 | +@property (nonatomic, strong) CNLiveQrCodeNavigationBar *navigationBar; | |
| 23 | +@property (nonatomic, strong) UIImageView *bgView; | |
| 24 | +@property (nonatomic, strong) CNLiveGenerateCodeView *qrCodeView; | |
| 25 | + | |
| 26 | +@end | |
| 27 | + | |
| 28 | +@implementation CNLiveGenerateCodeController | |
| 29 | +static const NSInteger margin = 20; | |
| 30 | +static const CGFloat timeValue = 1.5; | |
| 31 | + | |
| 32 | +#pragma mark - 生命周期 | |
| 33 | +- (void)viewWillAppear:(BOOL)animated{ | |
| 34 | + [super viewWillAppear:animated]; | |
| 35 | + self.navigationController.navigationBarHidden = YES; | |
| 36 | +} | |
| 37 | + | |
| 38 | +- (void)viewDidLoad { | |
| 39 | + [super viewDidLoad]; | |
| 40 | + self.view.backgroundColor = [UIColor blackColor]; | |
| 41 | + if (@available(iOS 11, *)) { | |
| 42 | + } | |
| 43 | + else { | |
| 44 | + self.automaticallyAdjustsScrollViewInsets = NO; | |
| 45 | + } | |
| 46 | + [self createSubViews]; | |
| 47 | +} | |
| 48 | + | |
| 49 | +- (void)dealloc { | |
| 50 | + NSLog(@"CNLiveGenerateCodeController -- dealloc"); | |
| 51 | + | |
| 52 | +} | |
| 53 | + | |
| 54 | +- (void)createSubViews { | |
| 55 | + [self.view addSubview:self.bgView]; | |
| 56 | + [self.view addSubview:self.qrCodeView]; | |
| 57 | + [self.view addSubview:self.navigationBar]; | |
| 58 | + | |
| 59 | +} | |
| 60 | + | |
| 61 | +#pragma mark - 响应方法 | |
| 62 | +- (void)goBack { | |
| 63 | + if (self.presentingViewController != nil) { | |
| 64 | + [self dismissViewControllerAnimated:YES completion:nil]; | |
| 65 | + | |
| 66 | + } | |
| 67 | + else { | |
| 68 | + [self.navigationController popViewControllerAnimated:YES]; | |
| 69 | + } | |
| 70 | +} | |
| 71 | + | |
| 72 | +- (void)getPHAuthorizationStatus:(void (^)(void))block{ | |
| 73 | + // 1.获取当前App的相册授权状态 | |
| 74 | + PHAuthorizationStatus authorizationStatus = [PHPhotoLibrary authorizationStatus]; | |
| 75 | + | |
| 76 | + // 2.判断授权状态 | |
| 77 | + if (authorizationStatus == PHAuthorizationStatusAuthorized) { | |
| 78 | + // 2.1 如果已经授权, 保存图片(调用步骤2的方法) | |
| 79 | + block(); | |
| 80 | + | |
| 81 | + } else if (authorizationStatus == PHAuthorizationStatusNotDetermined) { // 如果没决定, 弹出指示框, 让用户选择 | |
| 82 | + [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { | |
| 83 | + // 如果用户选择授权, 则保存图片 | |
| 84 | + if (status == PHAuthorizationStatusAuthorized) { | |
| 85 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 86 | + block(); | |
| 87 | + }); | |
| 88 | + } | |
| 89 | + }]; | |
| 90 | + | |
| 91 | + } else { | |
| 92 | + NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; | |
| 93 | + NSString *app_Name = [infoDict objectForKey:@"CFBundleDisplayName"]; | |
| 94 | + if (app_Name == nil) { | |
| 95 | + app_Name = [infoDict objectForKey:@"CFBundleName"]; | |
| 96 | + } | |
| 97 | + NSString *messageString = [NSString stringWithFormat:@"请在iPhone的\"设置 - 隐私 - 相机\"选项中,允许%@访问你的相册", app_Name]; | |
| 98 | + UIAlertController *alertC = [UIAlertController alertControllerWithTitle:nil message:messageString preferredStyle:(UIAlertControllerStyleAlert)]; | |
| 99 | + UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"好" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { | |
| 100 | + | |
| 101 | + }]; | |
| 102 | + | |
| 103 | + [alertC addAction:alertA]; | |
| 104 | + [self presentViewController:alertC animated:YES completion:nil]; | |
| 105 | + } | |
| 106 | +} | |
| 107 | + | |
| 108 | +// 保存图片 | |
| 109 | +- (void)saveImage:(UIImage *)image{ | |
| 110 | + if(!image){ | |
| 111 | + [QMUITips showError:@"保存失败" inView:self.view hideAfterDelay:timeValue]; | |
| 112 | + return; | |
| 113 | + } | |
| 114 | + [[PHPhotoLibrary sharedPhotoLibrary]performChanges:^{ | |
| 115 | + [PHAssetChangeRequest creationRequestForAssetFromImage:image]; | |
| 116 | + | |
| 117 | + } completionHandler:^(BOOL success, NSError * _Nullable error) { | |
| 118 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 119 | + if (success) { | |
| 120 | + [QMUITips showSucceed:@"保存成功" inView:self.view hideAfterDelay:timeValue]; | |
| 121 | + } else { | |
| 122 | + [QMUITips showError:@"保存失败" inView:self.view hideAfterDelay:timeValue]; | |
| 123 | + } | |
| 124 | + }); | |
| 125 | + | |
| 126 | + }]; | |
| 127 | +} | |
| 128 | +// UIView转UIImage | |
| 129 | +- (UIImage *)generateImage:(UIView *)view{ | |
| 130 | + // 1.开启上下文 | |
| 131 | + UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0); | |
| 132 | + // 2. 将控制器View的Layer渲染到上下文 | |
| 133 | + [view.layer renderInContext:UIGraphicsGetCurrentContext()]; | |
| 134 | + // 3.取出图片 | |
| 135 | + UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); | |
| 136 | + // 4.结束上下文 | |
| 137 | + UIGraphicsEndImageContext(); | |
| 138 | + | |
| 139 | + return newImage; | |
| 140 | +} | |
| 141 | + | |
| 142 | +#pragma mark - 代理 | |
| 143 | + | |
| 144 | +/** | |
| 145 | + * 状态栏的颜色 | |
| 146 | + * | |
| 147 | + * @return UIStatusBarStyle | |
| 148 | + * | |
| 149 | + */ | |
| 150 | +- (UIStatusBarStyle)preferredStatusBarStyle{ | |
| 151 | + return UIStatusBarStyleLightContent; | |
| 152 | + | |
| 153 | +} | |
| 154 | + | |
| 155 | +- (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{ | |
| 156 | + if ([actionEvents isEqualToString:@"1"]) { | |
| 157 | + [self goBack]; | |
| 158 | + } | |
| 159 | + else if ([actionEvents isEqualToString:@"2"]){ | |
| 160 | + self.navigationBar.right.userInteractionEnabled = NO; | |
| 161 | + __weak typeof(self) weakSelf = self; | |
| 162 | + QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"保存图片" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { | |
| 163 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 164 | + if(!strongSelf) return ; | |
| 165 | + [strongSelf getPHAuthorizationStatus:^{ | |
| 166 | + UIImage *image = [strongSelf generateImage:strongSelf.qrCodeView]; | |
| 167 | + [QMUITips showLoadingInView:strongSelf.view]; | |
| 168 | + [strongSelf saveImage:image]; | |
| 169 | + [QMUITips hideAllTipsInView:strongSelf.view]; | |
| 170 | + }]; | |
| 171 | + self.navigationBar.right.userInteractionEnabled = YES; | |
| 172 | + | |
| 173 | + }]; | |
| 174 | + QMUIAlertAction *action2 = [QMUIAlertAction actionWithTitle:@"扫描二维码" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { | |
| 175 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 176 | + if(!strongSelf) return ; | |
| 177 | + CNLiveScanQrCodeController *vc = [[CNLiveScanQrCodeController alloc]init]; | |
| 178 | + [strongSelf.navigationController pushViewController:vc animated:YES]; | |
| 179 | + | |
| 180 | + self.navigationBar.right.userInteractionEnabled = YES; | |
| 181 | + }]; | |
| 182 | + QMUIAlertAction *cancel = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { | |
| 183 | + __strong typeof(weakSelf) strongSelf = weakSelf; | |
| 184 | + if(!strongSelf) return ; | |
| 185 | + self.navigationBar.right.userInteractionEnabled = YES; | |
| 186 | + | |
| 187 | + }]; | |
| 188 | + | |
| 189 | + QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:QMUIAlertControllerStyleActionSheet]; | |
| 190 | + alertController.delegate = self; | |
| 191 | + [alertController addAction:action1]; | |
| 192 | + [alertController addAction:action2]; | |
| 193 | + [alertController addAction:cancel]; | |
| 194 | + | |
| 195 | + NSMutableDictionary *titleAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes]; | |
| 196 | + | |
| 197 | + titleAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0]; | |
| 198 | + | |
| 199 | + NSMutableDictionary *cancelAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes]; | |
| 200 | + cancelAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]; | |
| 201 | + | |
| 202 | + action1.buttonAttributes = titleAttributs; | |
| 203 | + action2.buttonAttributes = titleAttributs; | |
| 204 | + cancel.buttonAttributes = cancelAttributs; | |
| 205 | + | |
| 206 | + [alertController showWithAnimated:YES]; | |
| 207 | + } | |
| 208 | +} | |
| 209 | +- (void)didHideAlertController:(QMUIAlertController *)alertController{ | |
| 210 | + self.navigationBar.right.userInteractionEnabled = YES; | |
| 211 | + | |
| 212 | +} | |
| 213 | + | |
| 214 | +#pragma mark - 懒加载 | |
| 215 | +- (UIImageView *)bgView{ | |
| 216 | + if(!_bgView){ | |
| 217 | + _bgView = [[UIImageView alloc]initWithFrame:self.view.bounds]; | |
| 218 | + _bgView.backgroundColor = [UIColor blackColor]; | |
| 219 | + } | |
| 220 | + return _bgView; | |
| 221 | +} | |
| 222 | +- (CNLiveGenerateCodeView *)qrCodeView { | |
| 223 | + if (!_qrCodeView) { | |
| 224 | + _qrCodeView = [[CNLiveGenerateCodeView alloc]initWithID:@"asdasr"]; | |
| 225 | + _qrCodeView.frame = CGRectMake(0, 0, SCREEN_WIDTH-2*margin, SCREEN_WIDTH-2*margin+40); | |
| 226 | + _qrCodeView.center = self.view.center; | |
| 227 | + } | |
| 228 | + return _qrCodeView; | |
| 229 | +} | |
| 230 | +- (CNLiveQrCodeNavigationBar *)navigationBar { | |
| 231 | + if (!_navigationBar) { | |
| 232 | + _navigationBar = [[CNLiveQrCodeNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)]; | |
| 233 | + _navigationBar.delegate = self; | |
| 234 | + _navigationBar.title.text = @"生成二维码"; | |
| 235 | + UIImage *image2 = [self xw_getImageName:@"mine_code_more" bundleName:@"CNLiveQrCodeModule" targetClass:[self class]]; | |
| 236 | + [_navigationBar.right setImage:[image2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal]; | |
| 237 | + } | |
| 238 | + return _navigationBar; | |
| 239 | +} | |
| 240 | + | |
| 241 | +/** | |
| 242 | + * 创建图片 | |
| 243 | + * | |
| 244 | + * @param imageName 图片名字 | |
| 245 | + * @param bundleName 图片所在的bundle名字 | |
| 246 | + * @param targetClass 类和bundle的同级目录 | |
| 247 | + * @return 返回UIImage | |
| 248 | + */ | |
| 249 | +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{ | |
| 250 | + NSBundle *bundle = [NSBundle bundleForClass:targetClass]; | |
| 251 | + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"]; | |
| 252 | + NSBundle *targetBundle = [NSBundle bundleWithURL:url]; | |
| 253 | + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil]; | |
| 254 | + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]; | |
| 255 | +} | |
| 256 | + | |
| 257 | +@end | ... | ... |
CNLiveQrCodeModule/Classes/Controller/CNLiveGroupQrCodeController.m
| ... | ... | @@ -28,6 +28,8 @@ |
| 28 | 28 | |
| 29 | 29 | @implementation CNLiveGroupQrCodeController |
| 30 | 30 | static const NSInteger margin = 10; |
| 31 | +static const CGFloat timeValue = 1.5; | |
| 32 | + | |
| 31 | 33 | #pragma mark - 生命周期 |
| 32 | 34 | - (void)viewWillAppear:(BOOL)animated{ |
| 33 | 35 | [super viewWillAppear:animated]; |
| ... | ... | @@ -159,10 +161,17 @@ static const NSInteger margin = 10; |
| 159 | 161 | [PHAssetChangeRequest creationRequestForAssetFromImage:image]; |
| 160 | 162 | |
| 161 | 163 | } completionHandler:^(BOOL success, NSError * _Nullable error) { |
| 162 | - if (!success) return ; | |
| 163 | - dispatch_async(dispatch_get_main_queue(), ^{ | |
| 164 | - [QMUITips showSucceed:@"已保存到系统相册" inView:self.view hideAfterDelay:1.5]; | |
| 165 | - }); | |
| 164 | + if (success){ | |
| 165 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 166 | + [QMUITips showSucceed:@"保存成功" inView:self.view hideAfterDelay:timeValue]; | |
| 167 | + }); | |
| 168 | + }else{ | |
| 169 | + dispatch_async(dispatch_get_main_queue(), ^{ | |
| 170 | + [QMUITips showError:@"保存失败" inView:self.view hideAfterDelay:timeValue]; | |
| 171 | + }); | |
| 172 | + } | |
| 173 | + | |
| 174 | + | |
| 166 | 175 | }]; |
| 167 | 176 | |
| 168 | 177 | } | ... | ... |
CNLiveQrCodeModule/Classes/Controller/CNLiveMyQrCodeController.m
| ... | ... | @@ -238,6 +238,7 @@ static const CGFloat timeValue = 1.5; |
| 238 | 238 | if (!_qrCodeView) { |
| 239 | 239 | _qrCodeView = [[CNLiveMyQrCodeView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-2*margin, SCREEN_WIDTH-2*margin+40)]; |
| 240 | 240 | _qrCodeView.center = self.view.center; |
| 241 | + _qrCodeView.text = @"扫描二维码,加我好友"; | |
| 241 | 242 | } |
| 242 | 243 | return _qrCodeView; |
| 243 | 244 | } | ... | ... |
CNLiveQrCodeModule/Classes/View/CNLiveGenerateCodeView.h
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveGenerateCodeView.h | |
| 3 | +// CNLiveQrCodeModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright © 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <UIKit/UIKit.h> | |
| 10 | + | |
| 11 | +NS_ASSUME_NONNULL_BEGIN | |
| 12 | + | |
| 13 | +@interface CNLiveGenerateCodeView : UIView | |
| 14 | + | |
| 15 | +- (instancetype)initWithID:(NSString *)ID; | |
| 16 | + | |
| 17 | +@end | |
| 18 | + | |
| 19 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveQrCodeModule/Classes/View/CNLiveGenerateCodeView.m
0 → 100644
| 1 | +// | |
| 2 | +// CNLiveGenerateCodeView.m | |
| 3 | +// CNLiveQrCodeModule | |
| 4 | +// | |
| 5 | +// Created by 153993236@qq.com on 11/12/2019. | |
| 6 | +// Copyright © 2019 153993236@qq.com. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "CNLiveGenerateCodeView.h" | |
| 10 | +#import <Masonry/Masonry.h> | |
| 11 | +#import <SDWebImage/SDWebImage.h> | |
| 12 | +#import "QMUIKit.h" | |
| 13 | +#import "SGQRCode.h"//二维码库 | |
| 14 | + | |
| 15 | +#import "CNUserInfoManager.h" | |
| 16 | + | |
| 17 | +#import "CNLiveNetworking.h" | |
| 18 | +#import "CNLiveEnvironment.h" | |
| 19 | + | |
| 20 | +@interface CNLiveGenerateCodeView () | |
| 21 | +@property (nonatomic, strong) UIImageView *header; | |
| 22 | +@property (nonatomic, strong) UILabel *name; | |
| 23 | +@property (nonatomic, strong) UILabel *address; | |
| 24 | +@property (nonatomic, strong) UIImageView *qrCode; | |
| 25 | +@property (nonatomic, strong) NSString *ID; | |
| 26 | + | |
| 27 | +@property (nonatomic, strong) UILabel *desc; | |
| 28 | + | |
| 29 | +@end | |
| 30 | + | |
| 31 | +@implementation CNLiveGenerateCodeView | |
| 32 | +static const NSInteger margin = 20; | |
| 33 | +- (instancetype)initWithID:(NSString *)ID{ | |
| 34 | + self = [super init]; | |
| 35 | + if(self){ | |
| 36 | + self.backgroundColor = [UIColor whiteColor]; | |
| 37 | + self.layer.masksToBounds = YES; | |
| 38 | + self.layer.cornerRadius = 10; | |
| 39 | + // 生成二维码 | |
| 40 | + [self createSubViews]; | |
| 41 | + [self generateQRCode:ID]; | |
| 42 | + } | |
| 43 | + return self; | |
| 44 | + | |
| 45 | +} | |
| 46 | + | |
| 47 | +- (void)createSubViews { | |
| 48 | + [self addSubview:self.header]; | |
| 49 | + [self addSubview:self.name]; | |
| 50 | + [self addSubview:self.address]; | |
| 51 | + [self addSubview:self.qrCode]; | |
| 52 | + [self addSubview:self.desc]; | |
| 53 | + [_header mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 54 | + make.left.equalTo(self.mas_left).with.offset(margin); | |
| 55 | + make.top.equalTo(self.mas_top).with.offset(margin); | |
| 56 | + make.width.height.offset(60); | |
| 57 | + | |
| 58 | + }]; | |
| 59 | + | |
| 60 | + [_name mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 61 | + make.top.equalTo(self.header.mas_top); | |
| 62 | + make.left.equalTo(self.header.mas_right).with.offset(margin/2.0); | |
| 63 | + make.right.equalTo(self.mas_right).with.offset(-margin); | |
| 64 | + make.height.offset(30); | |
| 65 | + | |
| 66 | + }]; | |
| 67 | + | |
| 68 | + [_address mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 69 | + make.top.equalTo(self.name.mas_bottom); | |
| 70 | + make.left.equalTo(self.name.mas_left); | |
| 71 | + make.right.equalTo(self.name.mas_right); | |
| 72 | + make.height.equalTo(self.name.mas_height); | |
| 73 | + | |
| 74 | + }]; | |
| 75 | + | |
| 76 | + [_qrCode mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 77 | + make.centerX.equalTo(self.mas_centerX).with.offset(0); | |
| 78 | + make.top.equalTo(self.header.mas_bottom).with.offset(margin); | |
| 79 | + make.width.height.equalTo(self.mas_width).with.offset(-6*margin); | |
| 80 | + | |
| 81 | + }]; | |
| 82 | + | |
| 83 | + [_desc mas_makeConstraints:^(MASConstraintMaker *make) { | |
| 84 | + make.left.equalTo(self.mas_left); | |
| 85 | + make.right.equalTo(self.mas_right); | |
| 86 | + make.top.equalTo(self.qrCode.mas_bottom).with.offset(0); | |
| 87 | + make.bottom.equalTo(self.mas_bottom).with.offset(-0); | |
| 88 | + | |
| 89 | + }]; | |
| 90 | + | |
| 91 | +} | |
| 92 | + | |
| 93 | +// 重置二维码 | |
| 94 | +- (void)generateQRCode:(NSString *)ID{ | |
| 95 | + // | |
| 96 | +// NSDictionary *dic = @{@"content":[EncryptAndDecrypt base64StringFromText:ID encryptKey:AppDESKey],@"type":@"user"}; | |
| 97 | + NSDictionary *jsonDic = @{@"content":ID,@"type":@"orderCode"}; | |
| 98 | + | |
| 99 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDic options:NSJSONWritingPrettyPrinted error:nil]; | |
| 100 | + | |
| 101 | + NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; | |
| 102 | + | |
| 103 | + UIImage *xw_image = [self xw_getImageName:@"qr_code_icon" bundleName:@"CNLiveQrCodeModule" targetClass:[self class]]; | |
| 104 | + [self.qrCode sd_setImageWithURL:nil placeholderImage:[SGQRCodeObtain generateQRCodeWithData:jsonStr size:SCREEN_WIDTH-12*margin logoImage:xw_image ratio:0.2]]; | |
| 105 | + | |
| 106 | +} | |
| 107 | + | |
| 108 | +// 字典转json字符串 | |
| 109 | +- (NSString *)dictionaryToJsonString:(NSDictionary *)dic { | |
| 110 | + NSError *parseError = nil; | |
| 111 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError]; | |
| 112 | + | |
| 113 | + return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; | |
| 114 | +} | |
| 115 | + | |
| 116 | +/* | |
| 117 | + // Only override drawRect: if you perform custom drawing. | |
| 118 | + // An empty implementation adversely affects performance during animation. | |
| 119 | + - (void)drawRect:(CGRect)rect { | |
| 120 | + // Drawing code | |
| 121 | + } | |
| 122 | + */ | |
| 123 | +#pragma mark - 懒加载 | |
| 124 | +- (UIImageView *)header { | |
| 125 | + if (!_header) { | |
| 126 | + _header = [[UIImageView alloc] init]; | |
| 127 | + _header.layer.masksToBounds = YES; | |
| 128 | + _header.layer.cornerRadius = 5; | |
| 129 | + UIImage *xw_image = [self xw_getImageName:@"default_avatar_f" bundleName:@"CNLiveQrCodeModule" targetClass:[self class]]; | |
| 130 | + [_header sd_setImageWithURL:[NSURL URLWithString:CNUserShareModel.faceUrl] placeholderImage:xw_image]; | |
| 131 | + } | |
| 132 | + return _header; | |
| 133 | +} | |
| 134 | + | |
| 135 | +- (UILabel *)name { | |
| 136 | + if (!_name) { | |
| 137 | + _name = [[UILabel alloc] init]; | |
| 138 | + _name.numberOfLines = 1; | |
| 139 | + _name.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]; | |
| 140 | + _name.font = [UIFont systemFontOfSize:16]; | |
| 141 | + _name.text = CNUserShareModel.nickname; | |
| 142 | + } | |
| 143 | + return _name; | |
| 144 | +} | |
| 145 | +- (UILabel *)address { | |
| 146 | + if (!_address) { | |
| 147 | + _address = [[UILabel alloc] init]; | |
| 148 | + _address.numberOfLines = 1; | |
| 149 | + _address.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]; | |
| 150 | + _address.font = [UIFont systemFontOfSize:14]; | |
| 151 | + _address.text = CNUserShareModel.location; | |
| 152 | + } | |
| 153 | + return _address; | |
| 154 | +} | |
| 155 | +- (UIImageView *)qrCode { | |
| 156 | + if (!_qrCode) { | |
| 157 | + _qrCode = [[UIImageView alloc] init]; | |
| 158 | + } | |
| 159 | + return _qrCode; | |
| 160 | +} | |
| 161 | +- (UILabel *)desc { | |
| 162 | + if (!_desc) { | |
| 163 | + _desc = [[UILabel alloc] init]; | |
| 164 | + _desc.numberOfLines = 1; | |
| 165 | + _desc.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]; | |
| 166 | + _desc.font = [UIFont systemFontOfSize:16]; | |
| 167 | + _desc.textAlignment = NSTextAlignmentCenter; | |
| 168 | + _desc.text = @"扫描二维码,完成确认订单"; | |
| 169 | + } | |
| 170 | + return _desc; | |
| 171 | +} | |
| 172 | + | |
| 173 | +/** | |
| 174 | + * 创建图片 | |
| 175 | + * | |
| 176 | + * @param imageName 图片名字 | |
| 177 | + * @param bundleName 图片所在的bundle名字 | |
| 178 | + * @param targetClass 类和bundle的同级目录 | |
| 179 | + * @return 返回UIImage | |
| 180 | + */ | |
| 181 | +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{ | |
| 182 | + NSBundle *bundle = [NSBundle bundleForClass:targetClass]; | |
| 183 | + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"]; | |
| 184 | + NSBundle *targetBundle = [NSBundle bundleWithURL:url]; | |
| 185 | + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil]; | |
| 186 | + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]; | |
| 187 | + | |
| 188 | +} | |
| 189 | + | |
| 190 | +@end | ... | ... |
CNLiveQrCodeModule/Classes/View/CNLiveGroupQrCodeView.m
| ... | ... | @@ -98,6 +98,8 @@ static const NSInteger margin = 15; |
| 98 | 98 | if (!_groupHead) { |
| 99 | 99 | _groupHead = [[UIImageView alloc] init]; |
| 100 | 100 | _groupHead.backgroundColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]; |
| 101 | + UIImage *xw_image = [self xw_getImageName:@"default_avatar_f" bundleName:@"CNLiveQrCodeModule" targetClass:[self class]]; | |
| 102 | + [_groupHead sd_setImageWithURL:[NSURL URLWithString:CNUserShareModel.faceUrl] placeholderImage:xw_image]; | |
| 101 | 103 | |
| 102 | 104 | } |
| 103 | 105 | return _groupHead; | ... | ... |
CNLiveQrCodeModule/Classes/View/CNLiveMyQrCodeView.h
| ... | ... | @@ -9,8 +9,13 @@ |
| 9 | 9 | #import <UIKit/UIKit.h> |
| 10 | 10 | |
| 11 | 11 | NS_ASSUME_NONNULL_BEGIN |
| 12 | +typedef NS_ENUM(NSInteger, CNLiveQrCodeType){ | |
| 13 | + CNLiveQrCodeTypeDefualt = 0, //默认生成个人二维码 | |
| 14 | + CNLiveQrCodeTypeOrder, //生成订单二维码 | |
| 15 | +}; | |
| 12 | 16 | |
| 13 | 17 | @interface CNLiveMyQrCodeView : UIView |
| 18 | +@property (nonatomic, strong) NSString *text; | |
| 14 | 19 | |
| 15 | 20 | - (void)generateQRCode:(NSString *)type; |
| 16 | 21 | ... | ... |
CNLiveQrCodeModule/Classes/View/CNLiveMyQrCodeView.m
| ... | ... | @@ -95,6 +95,11 @@ static const CGFloat timeValue = 1.5; |
| 95 | 95 | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | +- (void)setText:(NSString *)text{ | |
| 99 | + _text = text; | |
| 100 | + _friends.text = text; | |
| 101 | +} | |
| 102 | + | |
| 98 | 103 | // 重置二维码 |
| 99 | 104 | - (void)generateQRCode:(NSString *)type{ |
| 100 | 105 | NSDictionary *params = @{ |
| ... | ... | @@ -119,7 +124,8 @@ static const CGFloat timeValue = 1.5; |
| 119 | 124 | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDic options:NSJSONWritingPrettyPrinted error:nil]; |
| 120 | 125 | NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; |
| 121 | 126 | |
| 122 | - [strongSelf.qrCode sd_setImageWithURL:nil placeholderImage:[SGQRCodeObtain generateQRCodeWithData:jsonStr size:SCREEN_WIDTH-12*margin logoImage:nil ratio:0.2]]; | |
| 127 | + UIImage *xw_image = [self xw_getImageName:@"qr_code_icon" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveMyQrCodeView class]]; | |
| 128 | + [strongSelf.qrCode sd_setImageWithURL:nil placeholderImage:[SGQRCodeObtain generateQRCodeWithData:jsonStr size:SCREEN_WIDTH-12*margin logoImage:xw_image ratio:0.2]]; | |
| 123 | 129 | |
| 124 | 130 | if([type isEqualToString:@"reset"]){ |
| 125 | 131 | [QMUITips showSucceed:@"重置成功" inView:strongSelf hideAfterDelay:timeValue]; |
| ... | ... | @@ -156,7 +162,7 @@ static const CGFloat timeValue = 1.5; |
| 156 | 162 | _header = [[UIImageView alloc] init]; |
| 157 | 163 | _header.layer.masksToBounds = YES; |
| 158 | 164 | _header.layer.cornerRadius = 5; |
| 159 | - UIImage *xw_image = [self xw_getImageName:@"default_avatar_f" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveMyQrCodeView class]]; | |
| 165 | + UIImage *xw_image = [self xw_getImageName:@"default_avatar_f" bundleName:@"CNLiveQrCodeModule" targetClass:[self class]]; | |
| 160 | 166 | [_header sd_setImageWithURL:[NSURL URLWithString:CNUserShareModel.faceUrl] placeholderImage:xw_image]; |
| 161 | 167 | } |
| 162 | 168 | return _header; | ... | ... |
Example/CNLiveQrCodeModule/CNLIVEAppDelegate.m
| ... | ... | @@ -11,10 +11,11 @@ |
| 11 | 11 | #import "CNLiveScanQrCodeController.h" |
| 12 | 12 | #import "CNLiveGroupQrCodeController.h" |
| 13 | 13 | #import "CNLiveScanResultController.h" |
| 14 | -#import "CNLiveEnvironmentManager.h" | |
| 14 | +#import "CNLiveGenerateCodeController.h" | |
| 15 | 15 | |
| 16 | 16 | #import "CNLiveNetworking.h" |
| 17 | 17 | #import "CNLiveEnvironment.h" |
| 18 | +#import "CNUserInfoManager.h" | |
| 18 | 19 | |
| 19 | 20 | @implementation CNLIVEAppDelegate |
| 20 | 21 | - (void)networkParamAction{ |
| ... | ... | @@ -40,9 +41,29 @@ |
| 40 | 41 | |
| 41 | 42 | [CNLiveEnvironmentManager setEnvironment:CNLiveDebugAppStore]; |
| 42 | 43 | [self networkParamAction]; |
| 44 | + [CNUserInfoManager saveUserinfoDic:@{ | |
| 45 | + @"bigFaceUrl":@"http://yweb0.cnliveimg.com/images/headImg/2019/1030/1572439148697.jpg", | |
| 46 | + @"countryCode":@"86", | |
| 47 | + @"email":@"", | |
| 48 | + @"extInfo":@"", | |
| 49 | + @"faceUrl":@"http://yweb0.cnliveimg.com/images/headImg/2019/1030/1572439148697_small.jpg", | |
| 50 | + @"gender":@"m", | |
| 51 | + @"hUid":@"", | |
| 52 | + @"isNewUser":@"0", | |
| 53 | + @"location":@"北京市海淀区", | |
| 54 | + @"mobile":@"17600922519", | |
| 55 | + @"nickName":@"金帝", | |
| 56 | + @"platformId":@"769_jetj7bq525", | |
| 57 | + @"qqUid":@"", | |
| 58 | + @"renrenUid":@"", | |
| 59 | + @"sinaUid":@"", | |
| 60 | + @"token":@"RkFYeLkl/u5S7tW8UcOkT3rfLTP/Ua8NIkdEsKlcolvl/yxTMNbAYXmmJyhKGpkj", | |
| 61 | + @"uid":@"10514405", | |
| 62 | + @"wxUid":@"" | |
| 63 | + }]; | |
| 43 | 64 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; |
| 44 | 65 | |
| 45 | - CNLiveMyQrCodeController *vc = [[CNLiveMyQrCodeController alloc] init]; | |
| 66 | + CNLiveGenerateCodeController *vc = [[CNLiveGenerateCodeController alloc] init]; | |
| 46 | 67 | // vc.jump_URL = @"http://www.baidu.com"; |
| 47 | 68 | UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc]; |
| 48 | 69 | ... | ... |