I have a UIWebView
and the UIWebViewDelegate
.
At the method webViewDidStartLoad
I define a variable bs
with another class burningSoft
-(void)webViewDidStartLoad:(UIWebView *)webView
{
NSLog(@"webViewDidStartLoad");
NSLog(@"burningSoft 1: %@", self.context[@"burningSoft"]);
[self initJS];
NSLog(@"burningSoft 2: %@", self.context[@"burningSoft"]);
[self setContext:[[self webView] valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"]];
if(self.context[@"burningSoft"].isUndefined) {
self.context[@"burningSoft"] = [self bs];
}
NSLog(@"burningSoft 3: %@", self.context[@"burningSoft"]);
}
The method initJS
looks like
-(void)initJS
{
NSLog(@"initJS");
[self setBs:[[BurningSoft alloc] init]];
[[self bs] setMain:self];
if(self.context[@"burningSoft"].isUndefined) {
self.context[@"burningSoft"] = [self bs];
}
}
and webViewDidFinishLoad
looks similar like webViewDidStartLoad
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
NSLog(@"webViewDidFinishLoad");
NSLog(@"burningSoft 4: %@", self.context[@"burningSoft"]);
if(self.context[@"burningSoft"].isUndefined)
{
NSLog(@"UNDEFINED!!!");
NSLog(@"[self bs] 1: %@", [self bs]);
NSLog(@"burningSoft 5: %@", self.context[@"burningSoft"]);
self.context[@"burningSoft"] = [self bs];
NSLog(@"burningSoft 6: %@", self.context[@"burningSoft"]);
NSLog(@"[self bs] 2: %@", [self bs]);
}
NSLog(@"burningSoft 7: %@", self.context[@"burningSoft"]);
}
So my first page did some logs like this
2016-08-26 13:42:57.054 burningSoft[2325:342056] webViewDidStartLoad
2016-08-26 13:42:57.055 burningSoft[2325:342056] burningSoft 1: (null)
2016-08-26 13:42:57.055 burningSoft[2325:342056] initJS
2016-08-26 13:42:57.056 burningSoft[2325:342056] burningSoft 2: (null)
2016-08-26 13:42:57.060 burningSoft[2325:342056] burningSoft 3: < burningSoft: 0x7fc7a3616870>
2016-08-26 13:42:57.300 burningSoft[2325:342056] webViewDidFinishLoad
2016-08-26 13:42:57.300 burningSoft[2325:342056] burningSoft 4: < burningSoft: 0x7fc7a3616870>
2016-08-26 13:42:57.300 burningSoft[2325:342056] burningSoft 7: < burningSoft: 0x7fc7a3616870>
and that's correct. If I entered some login data and another site is loaded I get logs like
2016-08-26 13:43:12.269 burningSoft[2325:342056] webViewDidStartLoad
2016-08-26 13:43:12.269 burningSoft[2325:342056] burningSoft 1: < burningSoft: 0x7fc7a3616870>
2016-08-26 13:43:12.270 burningSoft[2325:342056] initJS
2016-08-26 13:43:12.270 burningSoft[2325:342056] burningSoft 2: < burningSoft: 0x7fc7a3616870>
2016-08-26 13:43:12.270 burningSoft[2325:342056] burningSoft 3: < burningSoft: 0x7fc7a3616870>
2016-08-26 13:43:12.444 burningSoft[2325:342056] webViewDidFinishLoad
2016-08-26 13:43:12.445 burningSoft[2325:342056] burningSoft 4: undefined
2016-08-26 13:43:12.445 burningSoft[2325:342056] UNDEFINED!!!
2016-08-26 13:43:12.445 burningSoft[2325:342056] [self bs] 1: < burningSoft: 0x7fc7a5827230>
2016-08-26 13:43:12.445 burningSoft[2325:342056] burningSoft 5: undefined
2016-08-26 13:43:12.445 burningSoft[2325:342056] burningSoft 6: undefined
2016-08-26 13:43:12.445 burningSoft[2325:342056] [self bs] 2: < burningSoft: 0x7fc7a5827230>
2016-08-26 13:43:12.446 burningSoft[2325:342056] burningSoft 7: undefined
Everything is correct till the log 2016-08-26 13:43:12.445 burningSoft[2325:342056] burningSoft 5: undefined
. My variable bs
has the correct content and I set this content in this method to self.context[@"burningSoft"]
but the log in the next line told me that there is nothing.
Did someone know why my variable self.context[@"burningSoft"]
set to undefined between the methods webViewDidStartLoad
and webViewDidFinishLoad
and will not set?