- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[TMSpinner hide];
if (self.registrationModel && !self.loggedIn && [[self.webView.request.URL absoluteString] length]) {
[self autologinTheWebView];
}
}
#pragma mark - Black magic
- (void)autologinTheWebView {
[self.webView stringByEvaluatingJavaScriptFromString:[self javascriptToInject]];
[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"autologin('%@', '%@');", self.registrationModel.email, self.registrationModel.password]];
self.loggedIn = YES;
}
- (NSString *)javascriptToInject {
return @"autologin = function(email, password) {"
@" var emailField = document.getElementById('user_email');"
@" var passwordField = document.getElementById('user_password');"
@" var submitButton = document.querySelector('input.btn.btn-default.btn-success');"
@" emailField.value = email;"
@" passwordField.value = password;"
@" submitButton.click();"
@"};";
}
js в obj-c. кому то после меня это поддерживать :)