103 lines
3.1 KiB
Objective-C
103 lines
3.1 KiB
Objective-C
//
|
|
// QrCodeViewController.m
|
|
// Unity-iPhone
|
|
//
|
|
// Created by zhl on 2022/11/24.
|
|
//
|
|
|
|
#import "QrCodeViewController.h"
|
|
#include "LBXScanNative.h"
|
|
#include "UIUtils.h"
|
|
|
|
@interface QrCodeViewController ()
|
|
@property (weak, nonatomic) IBOutlet UIImageView *scanImg;
|
|
@property (weak, nonatomic) IBOutlet UIView *container;
|
|
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
|
|
@property (weak, nonatomic) IBOutlet UIButton *closeBtn;
|
|
@property (weak, nonatomic) IBOutlet UIButton *saveBtn;
|
|
@property (weak, nonatomic) IBOutlet UITextView *textView;
|
|
@end
|
|
|
|
@implementation QrCodeViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
[_closeBtn addTarget:self action:@selector(dismissSelf:) forControlEvents:UIControlEventTouchUpInside];
|
|
[_saveBtn addTarget:self action:@selector(saveToLibrary:) forControlEvents:UIControlEventTouchUpInside];
|
|
self.container.backgroundColor = [UIColor whiteColor];
|
|
self.container.layer.shadowOffset = CGSizeMake(0, 2);
|
|
self.container.layer.shadowRadius = 2;
|
|
self.container.layer.shadowColor = [UIColor blackColor].CGColor;
|
|
self.container.layer.shadowOpacity = 0.5;
|
|
}
|
|
|
|
/*
|
|
#pragma mark - Navigation
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
// Get the new view controller using [segue destinationViewController].
|
|
// Pass the selected object to the new view controller.
|
|
}
|
|
*/
|
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
{
|
|
[super viewWillAppear:animated];
|
|
|
|
if (!_imgScan) {
|
|
_scanImg.backgroundColor = [UIColor grayColor];
|
|
if (_content) {
|
|
CGSize _size = _scanImg.frame.size;
|
|
_imgScan = [LBXScanNative createQRWithString:_content QRSize:_size];
|
|
}
|
|
}
|
|
_titleLabel.text = _tipTitle;
|
|
_scanImg.image = _imgScan;
|
|
|
|
if (_tipTxt) {
|
|
_textView.text = _tipTxt;
|
|
_textView.hidden = NO;
|
|
} else {
|
|
_textView.hidden = YES;
|
|
}
|
|
|
|
_saveBtn.hidden = YES;
|
|
if (_autosave) {
|
|
[self saveToPhotoLibrary];
|
|
}
|
|
}
|
|
// save qr image to Camera Roll album
|
|
-(void) saveToPhotoLibrary {
|
|
UIGraphicsBeginImageContextWithOptions(self.container.bounds.size, NO, 0);
|
|
CGContextRef ctx = UIGraphicsGetCurrentContext();
|
|
[self.container.layer renderInContext:ctx];
|
|
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
UIGraphicsEndImageContext();
|
|
UIImageWriteToSavedPhotosAlbum(newImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
|
|
}
|
|
|
|
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
|
|
{
|
|
if (error) {
|
|
NSLog(@"save error");
|
|
[UIUtils showToastWithMessage: @"Error save recovery key image to System Library, Save it manually."];
|
|
_saveBtn.hidden = NO;
|
|
} else {
|
|
NSLog(@"save success");
|
|
[UIUtils showToastWithMessage: @"Success save recovery key image to System Library."];
|
|
_saveBtn.hidden = YES;
|
|
}
|
|
}
|
|
|
|
-(void)dismissSelf:(UIButton *)button{
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
}
|
|
|
|
-(void)saveToLibrary:(UIButton *)button{
|
|
[self saveToPhotoLibrary];
|
|
}
|
|
|
|
@end
|