Advertisement
Guest User

Untitled

a guest
Feb 26th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. NSString *user = _username.text;
  2. NSString *password = _password.text;
  3.  
  4.  
  5. AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://thesite.com/login.php"]];
  6. [httpClient setParameterEncoding:AFFormURLParameterEncoding];
  7. NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST"
  8. path:@"http://thesite.com/login.php"
  9. parameters:@{@"username":user, @"password":password}];
  10. AFHTTPRequestOperation * httpOperation = [httpClient HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
  11. //success code
  12. } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  13. //error handler
  14. }];
  15. [httpClient enqueueHTTPRequestOperation:httpOperation];
  16.  
  17. [self performSegueWithIdentifier:@"secondVC"];
  18.  
  19. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  20. if ([[segue identifier] isEqualToString:@"secondVC"]) {
  21. SecondViewController *second = (SecondViewController *)[segue destinationViewController];
  22. second.userString = self.user;
  23. }
  24. }
  25.  
  26. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  27. [defaults setObject:username forKey:@"UserName"];
  28. [defaults synchronize];
  29.  
  30. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  31. NSString *username = [defaults objectForKey:@"UserName"];
  32.  
  33. SecondViewController * sVC = [SecondViewController alloc] initWithUserName: username];
  34.  
  35. @property (nonatomic, strong) NSString * userName
  36.  
  37. - (id) initWithUserName: (NSString *) name
  38. {
  39. self = [super initWithNibName: @"SecondViewController"
  40. bundle: nil];
  41. if (self)
  42. {
  43. self.userName = name;
  44. }
  45. return self;
  46. }
  47.  
  48. secondClass *appdelegate = [NSApp delegate];
  49. [appdelegate initwithDetails:userName withPassword:password];
  50.  
  51. -(id)initwithDetails:(NSString *)user withPassword:(NSString *)password
  52. {
  53. userName = [NSString stringWithFormat:@"%@", user];
  54. newPass=[NSString stringWithFormat:@"%@", password];
  55. return self;
  56. }
  57.  
  58. #import <Foundation/Foundation.h>
  59.  
  60. @protocol ProcessDataDelegate <NSObject>
  61. @required
  62. - (void) processSuccessful: (BOOL)success;
  63. @end
  64.  
  65. @interface ClassWithProtocol : NSObject
  66. {
  67. id <ProcessDataDelegate> delegate;
  68. }
  69.  
  70. @property (retain) id delegate;
  71.  
  72. -(void)startSomeProcess;
  73.  
  74. @end
  75.  
  76. #import "ClassWithProtocol.h"
  77.  
  78. @implementation ClassWithProtocol
  79.  
  80. @synthesize delegate;
  81.  
  82. - (void)processComplete
  83. {
  84. [[self delegate] processSuccessful:YES];
  85. }
  86.  
  87. -(void)startSomeProcess
  88. {
  89. [NSTimer scheduledTimerWithTimeInterval:5.0 target:self
  90. selector:@selector(processComplete) userInfo:nil repeats:YES];
  91. }
  92.  
  93. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement