UIDataDetectorTypeAll Trouble parse again UIWebView

91 views Asked by At

I use javascript/jquery to hidde/show div

The div content is phone-number / adress ...

It's appear that Adress detection work on visible Div. It doesn't on hidden div. And I don't manage to force ios to parse again de WebView.

Does someone have experiment same trouble shoot? any idea? thx in advance

Here some sample code to experiment :

NSString * defaultString=[NSString stringWithFormat:
                              @"<div onclick='hiddeDiv(this)' id=title%i>"
                              "<h2>"
                              "H2Title"
                              "</h2>"
                              "</div>"
                              "<hr>"
                              "<div id=hidden%i style='display:none;'>"
                              "ADRESSE OR PHONE"
                              "</div>"
                              "",1,1];


[webView loadHTMLString:defaultString baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];
[webView setDataDetectorTypes:UIDataDetectorTypeAll];

script.js

function hiddeDiv(element) { 

 var newId=element.id.replace('title','');

 var elementHidden = document.getElementById('hidden'+newId);

 if (elementHidden.style.display == 'none'){

 $( '#hidden'+newId ).show(400,function(){$('html, body').animate({ scrollTop: $('#title'+newId).offset().top - 20}, 600);});
 }
 else { $( "#hidden"+newId ).hide(400);}

window.location.href = "detectAdress://hiddeDiv";//-->Handle event in xcode
};

handle event in xcode :

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:{
if (navigationType == UIWebViewNavigationTypeOther){
    scheme = [[request URL] scheme];
    if ([scheme isEqualToString: @"detectadress"]) {
        dispatch_async(dispatch_get_main_queue(), ^{
        [webView setDataDetectorTypes:UIDataDetectorTypeAll];//--> I want to force new detection after div is show but it doesn't work
        });
        return NO;
    }
}
return YES;
}
0

There are 0 answers