- 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. кому то после меня это поддерживать :)
guest 03.10.2014 15:37 # 0
bormand 03.10.2014 18:56 # +1
guest 03.10.2014 21:20 # −4
Psionic 06.10.2014 09:47 # +1
guest 01.11.2014 08:45 # −2