Guest User

Untitled

a guest
Jan 18th, 2018
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. NSString *urlstring=[NSString stringWithFormat:@"http://demo.talentclouds.in/API/LoginHandler.asmx/Login?username=acet@acet.in&password=123={"username":"%@","password":"%@"}",self.userid.text,
  2. self.pwd.text];
  3. NSLog(@"url==>%@",urlstring);
  4.  
  5. NSURL *addurl = [[NSURL alloc]initWithString:[urlstring stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]];
  6.  
  7. NSData *apiData = [NSData dataWithContentsOfURL:addurl];
  8. NSLog(@"%@",apiData);
  9.  
  10. NSError *error = nil;
  11.  
  12. if(apiData==nil)
  13. {
  14. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@" Server Error Meanwhile check your internet.." message:[error localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
  15. UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil];
  16. [alert addAction:defaultAction];
  17. [self presentViewController:alert animated:YES completion:nil];
  18. }
  19. else
  20. {
  21. apiDictionary = [NSJSONSerialization JSONObjectWithData:apiData options:kNilOptions error:&error];
  22. NSLog(@"%@",apiDictionary);
  23.  
  24.  
  25. username =[NSString stringWithFormat:@"%@",[apiDictionary valueForKey:@"username"]];
  26. NSLog(@"%@",username);
  27.  
  28. password =[NSString stringWithFormat:@"%@",[apiDictionary valueForKey:@"password"]];
  29. NSLog(@"%@",password);
  30.  
  31. message=[NSString stringWithFormat:@"%@",[apiDictionary valueForKey:@"message"]];
  32. NSLog(@"%@",message);
  33.  
  34. response=[NSString stringWithFormat:@"%@",[apiDictionary valueForKey:@"response"]];
  35. NSLog(@"%@",response);
  36.  
  37. if([response isEqualToString:@"success"])
  38. {
  39.  
  40. [[NSUserDefaults standardUserDefaults]setObject:username forKey:@"USERNAME"];
  41. [[NSUserDefaults standardUserDefaults]setObject:password forKey:@"PASSWORD"]; [[NSUserDefaults standardUserDefaults]synchronize];
  42.  
  43. login1ViewController *homeVC=[self.storyboard instantiateViewControllerWithIdentifier:@"StudentViewController"];
  44. [self.navigationController pushViewController:homeVC animated:YES];
  45.  
  46.  
  47. // _singleton.AutomaticLogin=@"1";
  48.  
  49.  
  50. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Talent Cloud" message:message preferredStyle:UIAlertControllerStyleAlert];
  51. UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil];
  52. [alert addAction:defaultAction];
  53. [self presentViewController:alert animated:YES completion:nil];
  54. }
  55. else
  56. {
  57. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Talent Cloud" message:@"Please Enter username and password" preferredStyle:UIAlertControllerStyleAlert];
  58. UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:nil];
  59. [alert addAction:defaultAction];
  60. [self presentViewController:alert animated:YES completion:nil];
  61. }
  62.  
  63. }
Add Comment
Please, Sign In to add comment