Problems encountered by the IOS development User Login Registration module _ios

Source: Internet
Author: User
Tags inheritance

Recently and another colleague responsible for the company login and User Center module development work, development cycle plan two weeks, minus the coordination time with the product and interface, minus the problem of the prototype diagram and interface, leading to obsessive symptoms of obsessive-compulsive disorder high, emotional instability spent time, can be completed in two weeks is also a big miracle. This article summarizes how to meet the needs of the product, the efficient development of a login registration module.

1. The use of inheritance to solve the interface repeatability function. Usually login registration will have a separate design, and the module will have a similar background, similar navigation bar style, similar return and exit behavior, similar input box, button style and so on.


For example, the above registration and login module, there will be the same return button, the same background, the same navigation bar style, or even the same button and input box style. So in order to speed up our development, we first define a parent controller, and then through the inheritance to achieve polymorphism, so that we quickly design the page and the implementation of basic functions. The following figure is the directory structure of my personal project Dingdingin login module, where Hooentrybaseviewcontroller defines the behavior and style common to this module:

2. Eject the keyboard and exit the keyboard mechanism development.

This makes it easy for developers to overlook the fact that I also see some apps because of the pop-up keyboard blocking input, causing anger to delete the app behavior. The design of this module is based on the design of the product to decide what code to use to achieve our goal.

• Click the blank area to exit the keyboard code:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Closekeyboard:)];
tap.numberoftapsrequired = 1;
tap.numberoftouchesrequired = 1;
[Self.view Addgesturerecognizer:tap]; 
-(void) Closekeyboard: (ID) sender
{
[Self.view endediting:yes];

• Avoid keyboard occlusion, login form or button to move code:

-(void) textviewdidbeginediting: (Uitextfield *) TextView
{
CGRect frame = textview.frame;
int offset = FRAME.ORIGIN.Y +-(self.view.frame.size.height-216.0);//keyboard height 216
nstimeinterval Animationduration = 0.30f;
[UIView beginanimations:@ "Resizeforkeyboard" context:nil];
[UIView setanimationduration:animationduration];
float width = self.view.frame.size.width;
float height = self.view.frame.size.height;
if (Offset > 0)
{
CGRect rect = CGRectMake (0.0f,-offset,width,height);
Self.view.frame = rect;
}
[UIView commitanimations];
}

3. Access to a third party login, you must determine whether the user installed the Third-party client, or Apple may audit could not pass. The lesson of blood.

For example, my app "Dingdingin" access to the QQ login function, the program will be the client installed QQ, if not installed then hide the QQ login icon.

if (![ Qqapi isqqinstalled]) {
self. Qqloginbutton.hidden = YES;
Self. Qqloginlabel.hidden = YES;

4. Special situation processing. This is easy to spot, usually young developers will not consider this piece, and usually the product and the UE will not remember to define the behavior of the critical point.

• Loading status. User-friendly prompts are required when a user initiates a logon or registration request.

#pragma mark-Login button click
-(ibaction) Login: (UIButton *) Sender {
if ([Self.userNameTextField.text IsEmpty] | | [Self.passwordTextField.text IsEmpty]) {
[svprogresshud showerrorwithstatus:@ username or password cannot be blank];
} else{
__weak typeof (self) weakself = self;
[[Hoousermanager Manager] LoginWithUserName:self.userNameTextField.text AndPassword:self.passwordTextField.text block:^ (Bmobuser *user, Nserror *error) {__strong __typeof
(weakself) strongself = weakself;
if (error) {
[Svprogresshud showerrorwithstatus:@ Login failed];
} else if (user) {
[Svprogresshud showsuccesswithstatus:@ Login succeeded];
[Strongself Loginsuccessdismiss];}}

• Account or password for all kinds of wrong judgments

 NSString *emailstr;
NSString *phonestr;
NSString *passwordstr = WeakSelf.passwordView.inputTextField.text;
Emailstr = WeakSelf.accountView.inputTextField.text; if (![ NSString Validateemail:emailstr] | | !emailstr.length) {[weakself showerrortipviewwithmessage:@ "mailbox format error]; return;}} else {phonestr = WeakSelf.accountView.inputTextField.text; if (Phonestr.length < 5) {[Weakself showerrortipviewwithm
essage:@ "Cell phone length error")];
Return } if ([WeakSelf.accountView.countryCode isequaltostring:@ "+86"]) {if (![
Phonestr Isvalidatemobilenumber]) {[Weakself showerrortipviewwithmessage:@ "mobile number format error")];
Return }} if (Passwordstr.length < kpasswordminlength) {[Weakself showerrortipviewwithmessage:atlocalizedstring @
Password length more than 6 characters ")];
Return
} if (Passwordstr.length > Kpasswordmaxlength) {[weakself showerrortipviewwithmessage:@ password longer than 20 characters)];
Return }

5. Phone to retrieve the password, send the Verification Code button processing. This behavior is also easy to ignore the product needs of our developers to actively think about, and then with the product to determine the demand, and then determine the button after the trigger behavior, otherwise the user may click to send the authentication code, which will cause the server burden, and may return to the user more than a message, causing trouble The following code allows you to click the Verification Code button and then count down the 2 minutes to restore the clickable state of the button.

-(void) Verifedcodebuttonwithtitle: (NSString *) title Andnewtitle: (NSString *) newtitle {WS (weakself); __block int
Timeout = ktimeout;
dispatch_queue_t queue = Dispatch_get_global_queue (Dispatch_queue_priority_default, 0);
dispatch_source_t _timer = dispatch_source_create (dispatch_source_type_timer, 0, 0,queue);
Dispatch_source_set_timer (_timer,dispatch_walltime (NULL, 0), 1.0*nsec_per_sec, 0); Dispatch_source_set_event_handler (_timer, ^{if (timeout<=0) {dispatch_source_cancel (_timer); Dispatch_async (
Dispatch_get_main_queue (), ^{[weakself settitle:title forstate:uicontrolstatenormal];
weakself.userinteractionenabled = YES;
});
}else{int seconds = timeout;
NSString *strtime = [NSString stringwithformat:@ "%.2d", seconds];
Dispatch_async (Dispatch_get_main_queue (), ^{[UIView beginanimations:nil Context:nil];
[UIView Setanimationduration:1];
[Weakself settitle:[nsstring stringwithformat:@ "%@ (%@)", Newtitle,strtime] forstate:uicontrolstatenormal];
[UIView commitanimations]; Weakself.userinteractionenabled = NO;
});
timeout--;
}
});
Dispatch_resume (_timer); }

5. User login information and state persistence. We typically have a business layer that handles the persistent data for the login and uses a single example, but cannot rely on the status of a single instance of logging, because the user may exit, so the field that needs to read the user's state from the sandbox is present, such as the user's ID, or Accesstoken.

The following code is used to persist user information

-

 (void) Saveuserinfowithdata: (Nsdictionary *) dict {
NSString *userid = Dict[kuserid];
NSString *email = Dict[kemail];
NSString *mobile = Dict[kmobile];
[Hoonsuserdefaultserialzer Setobject:memberid Forkey:kuserid];
[Hoonsuserdefaultserialzer Setobject:email forkey:kemail];
[Hoonsuserdefaultserialzer setobject:mobile forkey:kmobile];
}

5. External development of user information interface. Encapsulation of our modules. External provide our interface, usually other pages need to determine whether the user is logged in, may also require the user's unique identifier request data. This piece if we do the confusion, it is easy to cause other pages to get user information arbitrary, such as the development of a read in the sandbox to read the user information fields. We should be in the login module to unify other pages to obtain these user information behavior.

#import <Foundation/Foundation.h> #import "HooSingleton.h" @interface hoousermanager:nsobject @property (
Nonatomic, strong) NSString *userid; Singletonh (Manager)/** * Verify user if login or not * * @return if login to return YES, otherwise return NO/-(BOOL) I
Suserlogin;
/** * Login out */(void) loginout;
@end #import "HooUserManager.h" #import "HooNSUserDefaultSerialzer.h" static NSString * Const KMOBILE = @ "Mobile";
Static NSString * Const KEMAIL = @ "Email";
Static NSString * Const Kuserid = @ "UserID"; @implementation Hoousermanager singletonm (Manager) #pragma mark-getter and setter-(NSString *) UserID {nsstring *useri
D = [Hoonsuserdefaultserialzer Objectforkey:kuserid];
return UserID; }-(BOOL) isuserlogin {nsstring *userid = [Hoonsuserdefaultserialzer Objectforkey:kuserid]; if (userid.length) {return Y
ES;
} return NO;
}-(void) loginout {[Hoonsuserdefaultserialzer removeobjectforkey:kmobile];
[Hoonsuserdefaultserialzer Removeobjectforkey:kemail]; [HoonsuserdeFaultserialzer Removeobjectforkey:kuseid];  } @end

6. Other.

In fact, in order to better user experience, we will also provide other functions, such as the clear text Display password selection button, read mailbox format prompts from the server, error character correction, of course, the most important animation effect.

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.