Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 12, 2012, 07:17 AM   #1
mikezang
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
How to request HTML page with "Loading..."

I am using NSURLCoeection to request HTML page, when I show it in UIWebView, the main contents can't be loaded and page is showing "読み込み中...", you can check attachment though there is Japanese for "Loading...". I checked source, there is somethings as below:
Code:
<div id="Tables"><div class="load_data"><span>読み込み中</span></div></div>
I tried to use code as below to redirect, but it looks like no redirect happened, what can I do next?
Code:
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2012-12-12 at 22.12.29.jpg
Views:	35
Size:	62.6 KB
ID:	383057  
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2

Last edited by mikezang; Dec 12, 2012 at 07:22 AM.
mikezang is offline   0 Reply With Quote
Old Dec 12, 2012, 07:24 AM   #2
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
What do you expect?
What have you tried?

A single method name isn't good enough. Show us your implementation.
ArtOfWarfare is offline   0 Reply With Quote
Old Dec 12, 2012, 07:30 AM   #3
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Quote:
Originally Posted by ArtOfWarfare View Post
What do you expect?
What have you tried?

A single method name isn't good enough. Show us your implementation.
Well , I request as below
Code:
	NSURL *url = [NSURL URLWithString:[self prefixForURLString:_htmlUrl.text]];
	NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
	_connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Then I implemented delegation as below, that's all!
Code:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
    _htmlData = [[NSMutableData alloc] initWithData:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    [_htmlData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"");
    
    NSString *error_str = [error localizedDescription];
    UIAlertView *alertView = [[UIAlertView alloc]
                              initWithTitle:@"RequestError"
                              message:error_str
                              delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
    [alertView show];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *htmlString = [[NSString alloc]
                    initWithData:_htmlData
                    encoding:NSUTF8StringEncoding;
    
    [_htmlSource loadHTMLString:htmlString baseURL:nil];
}

- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
{
    if (redirectResponse) {
        NSMutableURLRequest *r = [request mutableCopy]; // original request
        [r setURL: [request URL]];
        return r;
    }
    else {
        return request;
    }
}
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Dec 12, 2012, 10:29 PM   #4
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
The web page probably has relative links inside it and you don't set the baseURL so the web view doesn't know where to look for those assets.

Either just send the original link to the web view and let it load the page or you need to set the baseURL.
PhoneyDeveloper is offline   0 Reply With Quote
Old Dec 12, 2012, 11:34 PM   #5
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Quote:
Originally Posted by PhoneyDeveloper View Post
The web page probably has relative links inside it and you don't set the baseURL so the web view doesn't know where to look for those assets.

Either just send the original link to the web view and let it load the page or you need to set the baseURL.
Where should I put a real baseURL?
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Dec 13, 2012, 07:24 AM   #6
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
Code:
[_htmlSource loadHTMLString:htmlString baseURL:nil];
PhoneyDeveloper is offline   0 Reply With Quote
Old Dec 13, 2012, 10:09 AM   #7
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Quote:
Originally Posted by PhoneyDeveloper View Post
Code:
[_htmlSource loadHTMLString:htmlString baseURL:nil];
That is no problems, my question is not HTML Web Viewer but HTML source view.
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Dec 13, 2012, 07:27 PM   #8
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
You download a web page's html into a string and then ask the webview to load the html string. If there are relative paths in the html how will the web view know what web site to use to find the resources at those relative paths?

For example if I look at the page source for the main page of this forum I see html code like this

Code:
<a href="subscription.php?do=addsubscription&amp;f=135" rel="nofollow">Subscribe to This Forum</a>
How will the web view know what web site is being referenced without the baseURL?
PhoneyDeveloper is offline   0 Reply With Quote
Old Dec 13, 2012, 11:08 PM   #9
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Quote:
Originally Posted by PhoneyDeveloper View Post
You download a web page's html into a string and then ask the webview to load the html string. If there are relative paths in the html how will the web view know what web site to use to find the resources at those relative paths?

For example if I look at the page source for the main page of this forum I see html code like this

Code:
<a href="subscription.php?do=addsubscription&amp;f=135" rel="nofollow">Subscribe to This Forum</a>
How will the web view know what web site is being referenced without the baseURL?
This is what I want to know, I am interesting in HTML source itself because I want parse it, so that I use NSURLConnection to get it, I hope that I can get all source like it show in browser, but I can only get part of source, I thought maybe there is redirect but it seems no redirect happened.

My question is how can I get whole source including JavaScript, redirect and anything else, just like what I viewed in browser, how can I do? May I make sense?
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Safari's "Swipe to go back" re-loading page hotttnickkk OS X Mavericks (10.9) 1 Nov 1, 2013 06:52 AM
"default.html" file on web server Jaggions Mac OS X Server, Xserve, and Networking 12 Aug 21, 2013 04:51 AM
How to create a pdf file that "compiles" html code and creates hyperlinks? seekinginfo Mac Applications and Mac App Store 0 Aug 7, 2013 02:07 PM
iPad: My ipad 3 sometimes gets " hung up" while loading a web page. Jacoblee23 iPad 6 Nov 6, 2012 06:00 AM
What apps export to "flat HTML"? loft3 Web Design and Development 2 Oct 23, 2012 01:55 PM

Forum Jump

All times are GMT -5. The time now is 12:09 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC