session-ios/Signal/src/view controllers/PresentIdentityQRCodeViewCo...

62 lines
1.5 KiB
Objective-C

//
// PresentIdentityQRCodeViewController.m
// Signal-iOS
//
// Created by Christine Corbett Moran on 3/30/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
#import "PresentIdentityQRCodeViewController.h"
#import "NSData+Base64.h"
#import "UIImage+normalizeImage.h"
@implementation PresentIdentityQRCodeViewController
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void) viewDidLoad {
[super viewDidLoad];
CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
[filter setDefaults];
[filter setValue:[[self.identityKey base64EncodedString] dataUsingEncoding:NSUTF8StringEncoding] forKey:@"inputMessage"];
CIImage *outputImage = [filter outputImage];
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgImage = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *image = [UIImage imageWithCGImage:cgImage scale:1. orientation:UIImageOrientationUp];
// Resize without interpolating
UIImage *resized = [image resizedWithQuality:kCGInterpolationNone rate:5.0];
self.qrCodeView.image = resized;
CGImageRelease(cgImage);
}
#pragma mark - Action
- (IBAction)closeButtonAction:(id)sender
{
[UIView animateWithDuration:0.6 delay:0. options:UIViewAnimationOptionCurveEaseInOut animations:^{
[self.view setAlpha:0];
} completion:^(BOOL succeeded){
[self dismissViewControllerAnimated:YES completion:nil];
}];
}
@end