How to run HTML+javascript file run on UIWebView . .?

Everybody,

I have a one HTML page which contain one Javascript function which shows one animals animation.. i have added it locally in to xcode project.

Now when i load this file in UIWebView it will looks perfect.. Here is the code of loading HTMl file to UIWebView

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"elephant-animation" ofType:@"html"] isDirectory:NO];
        NSURLRequest *req = [NSURLRequest requestWithURL:url];
        [self performSelectorOnMainThread:@selector(startWebLoad3:) withObject:req waitUntilDone:YES];

-(void)startWebLoad3:(NSURLRequest *)request
{
    [wbView3 loadRequest:request];
    [wbView3 setBackgroundColor:[UIColor clearColor]];
    wbView3.scrollView.scrollEnabled = NO;
    [wbView3.scrollView setBackgroundColor:[UIColor clearColor]];
    [wbView3 setOpaque:NO];
}

But i have 6 pages. When start to load every page with separate UIWebView, It goes to memory warning.. And give me error like here.

void SendDelegateMessage(NSInvocation*): delegate (webView:didFinishLoadForFrame:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode

if i run only one page than it run perfectly, but when i start to load all together or one by one it crashed with memory warning.

Let me know if any one get any solution of it..

i have stuck with this problem..

Thanks,


finally i got solution.. After long R & D, got some effective solution...

"JavaScript execution time is limited to 10 seconds for each top-level entry point. If your script executes for more than 10 seconds, the web view stops executing the script"

this is the reason why i fail to load html page in UIWebView.. And iPad handle up to 3 MB data loading on App launch only.. And i have used more than it..

So, i change javascript as per requirement and now worked..

Thanks for be part of it..


static NSInteger currentIndex = 0;
if (currentIndex < 99) {
    currentIndex++;
}
NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"file%d",currentIndex] ofType:@"html"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
NSString *htmlString = [[NSString alloc] initWithData: 
                        [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
[self.myWebView loadHTMLString:htmlString baseURL:nil];

我希望它会起作用


In the figure below, one is for adding HTML, Javascript and CSS like files and the second is for general XCode files.

for HTML, Javascript and CSS files

While adding files into XCode:

在这里输入图像描述

This works for me..! Hope it will work for all. Thank you!!

链接地址: http://www.djcxy.com/p/59188.html

上一篇: 有可能简化我的架构吗?

下一篇: 如何在UIWebView上运行HTML + JavaScript文件。 。?