iOSアプリで認証システムを作成しようとしています。これにより、ユーザーはログインでき、アカウントをまだ持っていない場合は登録できます。昨日、ログインシステムを完全に稼働させましたが、登録システム用にコードを設定すると、コードはサーバーにpingを送信しませんでした。次に、ログインシステムを再度テストしようとしましたが、コードはサーバーにpingを送信しません。
RegistrationTableViewControllerの関連コード(一部のセルにテキストフィールドを含むカスタムTVCです。たとえば、ビューを考えて新しいカレンダーイベントを作成します)。
- (IBAction)signUpButtonPressed {
// Get the values out of the text fields that the user has filled out.
NSString *email = self.emailTextField.text;
NSString *firstName = self.firstNameTextField.text;
NSString *lastName = self.lastNameTextField.text;
NSString *password = self.passwordTextField.text;
// Assuming that sign-up could potentially take a noticeable amount of time, run the
// process on a separate thread to avoid locking the UI.
dispatch_queue_t signUpQueue = dispatch_queue_create("sign-up authenticator", NULL);
dispatch_async(signUpQueue, ^{
// self.brain refers to a SignUpBrain property. See the code for the class below.
[self.brain signUpUsingEmail:email firstName:firstName lastName:lastName
andPassword:password];
dispatch_async(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:@"ShowMainFromSignUp" sender:self];
});
});
dispatch_release(signUpQueue);
}
SignUpBrainの関連コード:
- (void)signUpUsingEmail:(NSString *)email firstName:(NSString *)firstName
lastName:(NSString *)lastName andPassword:(NSString *)password {
self.email = email;
self.firstName = firstName;
self.lastName = lastName;
self.password = password;
// Handle sign-up web calls.
NSMutableURLRequest *signUpRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL
URLWithString:@"URL GOES HERE"]]; // obviously there's an actual URL in real code
NSString *postString = [NSString stringWithFormat:@"uname=%@&pw=%@&fname=%@&lname=%@",
email, password, firstName, lastName];
//NSLog(postString);
[signUpRequest setHTTPMethod:@"POST"];
[signUpRequest setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *signUpConnection =
[NSURLConnection connectionWithRequest:signUpRequest delegate:self];
[signUpConnection start];
// Store any user data.
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
self.signUpResponse = data;
NSError *error;
NSDictionary *jsonLoginResults = [NSJSONSerialization JSONObjectWithData:data
options:0 error:&error];
if (error) {
NSLog(error.description);
}
NSLog(jsonLoginResults.description);
// Return whether the user has successfully been registered.
// If success is 1, then registration has been completed successfully. 0 if not.
if ([jsonLoginResults objectForKey:@"status"]) {
NSLog(@"Success!");
}
}
また、UIWebViewでこれらの同じWeb呼び出しを使用するテストを作成し、正常に機能することにも注意してください。
何かを明確にする必要がある場合、またはコードをさらに含める必要がある場合は、お知らせください。前もって感謝します。