iOS open source encrypted album agony implementation (II)

Source: Internet
Author: User

Brief introduction

Although there are some good encryption album app on the market, but not the built-in ads, it is to limit the number of uploads. This paper introduces the production process of an encrypted album, which will include multiple passwords (enter different passwords to access different spaces, can be used to hide), WiFi transmission map, photo file encryption and other functions. Currently the project and the article will go forward at the same time, the project source code can be downloaded on GitHub.
Click to go to GitHub

Overview

The previous article mainly introduced the account storage class and the tool class design, this article through the tool class, realizes the login and the registration interactive interface.

Login controller and view design custom Controller view

To separate the view logic from the business logic, the controller view is managed with a custom class that designates the custom view as the controller view in the controller's Loadview method.
The file structure is as follows.

The methods for specifying a custom view as a controller view are as follows.
Because you want to use SGWelcomeView some of the API of a custom view, you need to refer to it, otherwise you need a strong type to use it directly from view.

@interface SGWelcomeViewController ()@property (nonatomicweak) SGWelcomeView *welcomeView;@end@implementation SGWelcomeViewController- (void)loadView {    SGWelcomeView *view = [SGWelcomeView new];    self.view = view;    self.welcomeView = view;}
Login interface Design

The login interface is as shown.

How to sign in with Touch ID

If the device supports Touch ID, the authentication of Touch ID is attempted first, and a password is required if validation fails.
When the login controller appears, clear the account that is already logged in, and try the Touch ID login implementation as follows.

- (void) Viewdidappear: (BOOL) Animated {[SuperViewdidappear:animated]; [Sgaccountmanager Sharedmanager]. Currentaccount=Nil; [ SelfHandletouchidlogin];} - (void) Handletouchidlogin {Lacontext *context = [Lacontext new];if([Context Canevaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics Error:Nil]) {[Context Evaluatepolicy:lapolicydeviceownerauthenticationwithbiometrics localizedreason:@"Agony need your Touch ID to login"reply:^ (BOOLSuccessNserror* _nullable error) {if(success)                {Sgaccount *account = [[Sgaccountmanager Sharedmanager] gettouchidaccount]; [ SelfLoginwithaccount:account]; }Else{                [ SelfHandlecommonlogin];    }        }]; }Else{        [ SelfHandlecommonlogin]; }}

Touch ID verification is implemented through Lacontext, and success is logged in with a password bound by Touch ID, and a password login (called the Handlecommonlogin method) fails.
Note that the Touch ID callback is in the child thread, and if the UI action is involved, do not forget to place the main thread operation.

Password Login method

Password login is implemented by calling the Handlecommonlogin method, which specifies a block callback for the login view and makes the password input box the first responder.

- (void)handleCommonLogin {    WS();  // 定义weakSelf的宏    [self.welcomeView setWelcomeHandler:^(SGAccount *account) {        [weakSelf loginWithAccount:account];    }];}

When the user enters the password and presses the return key, the block is called back to perform the login. Note that the last method of Touch ID and password login is Loginwithaccount: method, the implementation of this method is as follows.

- (void)loginWithAccount:(SGAccount *)account {    dispatch_async(dispatch_get_main_queue(), ^{        if (!account) {            [MBProgressHUD showError:@"Password Error"];            return;        }        [SGAccountManager sharedManager].currentAccount = account;        AppDelegate *app = [UIApplication sharedApplication].delegate;        [[UINavigationController alloc] initWithRootViewController:[SGHomeViewController new]];    });}

GCD is used because the call to the method is also made in the Touch ID callback, and the Touch ID callback is a child thread.
If the password verification successfully returns the account object during login verification, the failure returns NULL, so it is possible to determine whether the login is complete with the account being empty. If the login succeeds, save the successful object to the account management Singleton, and switch the root controller to the controller of the album home page.

Details of the login view

For a phone with a smaller screen size, the keyboard may obscure the input box, monitor the keyboard's display and hide events, and determine if the keyboard is blocking the input box to determine whether you want to move the view up.
The login interface contains icons, text, and input boxes, which are positioned on the parent view by constraints, and, SGWelcomeView for convenience, the entire parent view is shifted upward, panning is achieved by transform, as follows.

registration and cancellation notice

Because the view passes through the code framework, it is bound to call the initWithFrame: method to register the notification in the method.

[[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil];[[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(keyboardHide:) name:UIKeyboardWillHideNotification object:nil];

Unregisters the notification in the Dealloc method.

- (void)dealloc {    [[NSNotificationCenter defaultCenter] removeObserver:self];}
handling the display of the keyboard

The final position of the keyboard should be obtained through endframe because it is the event that the keyboard is about to move. The key to determine whether the keyboard obscures the input box is to see if the keyboard's topy is less than the bottomy of the input box, if the topy is less than bottomy, the entire view should be shifted upward bottomy-topy, in order to be beautiful, should be more translation of a space, DeltaY is the distance should be translated , and a negative value upward.
The addition of the delta in conditional judgment also determines whether the view also implements transformations because the transformation is for the entire parent view, and the input box coordinates that are obtained when computed are relative to the parent view, so the transformation of the parent view does not affect the input box coordinates, and the keyboard display may be called multiple times to ensure that the view is not duplicated. , you need to determine if the transformation has been made.

- (void) Keyboardshow: (nsnotification*) Nof {CGRectEndframe = [Nof. UserInfo[Uikeyboardframeenduserinfokey] Cgrectvalue];CGFloatEndY = Endframe. Origin. Y;CGFloatDeltaY = Endy-cgrectgetmaxy ( Self. pwdfiled. Frame) -Ten;if(DeltaY <0&& Cgaffinetransformequaltotransform ( Self. Transform, cgaffinetransformidentity)) { Self. Transform= Cgaffinetransformtranslate ( Self. Transform,0, DeltaY); }}
Handling Keyboard Hiding

When the keyboard is hidden, only the transform can be restored.

- (void)keyboardHide:(NSNotification *)nof {    self.transform = CGAffineTransformIdentity;}

If you want the keyboard to appear and disappear in sync with the view displacement, you can duration the keyboard movement by notifying the object, and then write the transformation in the UIView animation block.

Register controller and view design

The design of the registration controller is consistent with the login controller design, and the file structure is as follows.

The interface is as follows.

The registration page is the same as the login page, also through the block callback to the controller, to handle the registration, because each password corresponds to a storage space, registration requires that the password cannot be duplicated with the existing account. After entering the confirmation password and pressing the return key on the keyboard to pass the block callback, pass back the password and confirm the password, the controller processing implementation is as follows.

- (void) Handleregisterwithpassword: (NSString*) Password Confirm: (NSString*) Confirm {//password and Confirm password must be consistent and not empty    if(! [Password isequaltostring:confirm]) {[Mbprogresshud showerror:@"Passwords does not Match"];return; }Else if(!password. Length) {[Mbprogresshud showerror:@"Password cannot be Empty"];return; }//Use Account Management objects to process registered business logicSgaccountmanager *mgr = [Sgaccountmanager Sharedmanager];NSString*errormessage =Nil; [Mgr Registeraccountwithpassword:password errormessage:&errormessage];if(ErrorMessage = =Nil) {//Registered successfully back to the login page[Mbprogresshud showsuccess:@"Register succeeded"]; [ Self. NavigationcontrollerPopviewcontrolleranimated:YES]; }Else{[Mbprogresshud showerror:errormessage]; }}
Summarize

This article mainly introduces the login and registration interface Implementation Details, welcome to follow the project, the project can be found at the beginning of this article.

iOS open source encrypted album agony implementation (II)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.