ios - How to add login api using nsjsonserilization.? -


i have api http://qa.networc.in:1336/api/users/app/login , want fire api on login button click. need match email , password.

 - (void)viewdidload {   [super viewdidload];    name = [nsmutablearray new];     [uiapplication sharedapplication].networkactivityindicatorvisible = yes;    nsurl *url =  [nsurl urlwithstring:@"http://qa.networc.in:1336/api/users/app/login"];    nsurlrequest *request= [nsurlrequest requestwithurl:url];    [nsurlconnection connectionwithrequest:request delegate:self];  }  - (void)didreceivememorywarning {   [super didreceivememorywarning]; }  -(void)connection:(nsurlconnection *)connection   didreceiveresponse:  (nonnull nsurlresponse *)response     {   data = [[nsmutabledata alloc] init];   nslog(@"did receive response");  }  -(void)connection:(nsurlconnection *)connection didreceivedata:(nsdata   *)theta {   [data appenddata:thedata];    nslog(@"daata"); }  -(void)connectiondidfinishloading:(nsurlconnection  *)connection {   [uiapplication sharedapplication].networkactivityindicatorvisible = no;   name= [nsjsonserialization jsonobjectwithdata:data options:0 error:nil];  }  -(void)connection:(nsurlconnection *)connection didfailwitherror:(nserror   *)error      {      uialertview *errorview= [[uialertview alloc]initwithtitle:@"error"       message:@"the download not complete please make sure you're connected internet" delegate:nil cancelbuttontitle:@"dismiss" otherbuttontitles: nil];     [errorview show];      [uiapplication sharedapplication].networkactivityindicatorvisible = no; }  - (ibaction)login:(id)sender    {    } 

step-1

add following details in .plist

<key>nsapptransportsecurity</key> <dict> <key>nsallowsarbitraryloads</key> <true/>  </dict> 

step-2

- (ibaction)login:(id)sender    {     nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:[nsurl urlwithstring:@"http://qa.networc.in:1336/api/users/app/login"]];  nsurlsession *session = [nsurlsession sharedsession]; //  email": user_name, "password": password, "devicetoken":'testdata nsstring * params =[nsstring stringwithformat:@"email=%@&password=%@&devicetoken=testdata",youremailtextfield.text,yourpasswordtextfield.text];  request.httpmethod = @"post"; request.httpbody =[params datausingencoding:nsutf8stringencoding];   nsurlsessiondatatask *task = [session datataskwithrequest:request                                         completionhandler:                               ^(nsdata *data, nsurlresponse *response, nserror *error) {                                   // ...                                    nslog(@"response:%@ %@\n", response, error);                                   if(error == nil)                                   {                                       // use nsjson serlizeitaion , serlize value                                       nsstring * text = [[nsstring alloc] initwithdata: data encoding: nsutf8stringencoding];                                       nslog(@"data = %@",text);                                   }                               }];  [task resume];  } 

for additional information see tutorial


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -