最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

iphone - How to run HTML+javascript file run on UIWebView . .? - Stack Overflow

programmeradmin5浏览0评论

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,

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,

Share Improve this question asked May 3, 2012 at 12:21 Solid SoftSolid Soft 1,9322 gold badges27 silver badges56 bronze badges 5
  • i have searched on many forums and googling it, but dont get any luck... please help me.. – Solid Soft Commented May 3, 2012 at 12:22
  • I think load 6 pages each for 6 UIWebView is not necessary, is there any alternative way to make it? – Tom Commented May 11, 2012 at 4:59
  • also tried.... But not success... – Solid Soft Commented May 11, 2012 at 9:13
  • Hey @Jagdish can you share what did for U got sucess. I am stuck here finally i have seen your sucess. – simbesi. Commented Dec 13, 2013 at 13:02
  • @Raju Change Java script.. to make feasible in iOS - Objective C.. "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" – Solid Soft Commented Dec 16, 2013 at 6:31
Add a ment  | 

4 Answers 4

Reset to default 2

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];

I hope it will work

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!!

i think,you want to do html file in webview ,in my application i done one scrollview in that view ,in that view i add webview in loop at last i add the html file in webview. try this code:

ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,768,[[UIScreen mainScreen] bounds].size.height)];
    ScrollView.contentSize = CGSizeMake(768*21,[[UIScreen mainScreen] bounds].size.width);
    ScrollView.pagingEnabled=YES;
    ScrollView.delegate = self;
    ScrollView.userInteractionEnabled = YES;
    ScrollView.showsVerticalScrollIndicator=NO;
    ScrollView.showsHorizontalScrollIndicator=NO;

    int x=0,y=125;
    for ( i=1; i<22; i++)
    {

        view3=[[UIView alloc]initWithFrame:CGRectMake(x,0,768, 1000)];
        view3.backgroundColor=[UIColor whiteColor];

        webview2=[[UIWebView alloc]initWithFrame:CGRectMake(0,y,768,755)];
        webview2.scalesPageToFit=YES;
        webview2.autoresizingMask=(UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
        webview2.multipleTouchEnabled=YES;
        webview2.backgroundColor=[UIColor whiteColor];

        NSString *st = [NSString stringWithFormat:@"1%d",i];
        NSString *str12=[NSString stringWithFormat:@"information_"];
        str12=[str12 stringByAppendingString:st];
        NSString *urlAddress        = [[NSBundle mainBundle] pathForResource:str12 ofType:@"html"];//you can also use PDF files
        NSURL *url                  = [NSURL fileURLWithPath:urlAddress];
        NSURLRequest *requestObj    = [NSURLRequest requestWithURL:url];
        [webview2 loadRequest:requestObj];

        webview2.tag= i + 10;
        [view3 addSubview:webview2];


        [ScrollView addSubview:view3];

        x=x+768;


}
    [self.view addSubview:ScrollView];



}

in my application 22 html pages(information_%i,must in resource ) add in webview ,it is working very well.

i hope it's helpful to u also.

发布评论

评论列表(0)

  1. 暂无评论