I have an UIWebview, when user taps a UIButton, my webview will be loaded. I have an 10 HTML files in bundle i want to show the first html in webview and when user **swipes** i want to show the next HTML file. When user wants to see previous HTML file, i want to allow swipe and see. I have used UISwipeGesture but how can i load the files one by one.. Please help me. I have loaded the files from bundle and i used
NSURLREQUEST *req = [NSURLREQUEST requestwithURL : myURL];
[webView loadRequest:req];
myURL is the path for first HTML. How can i do this for 10 HTML files using SWIPE
One simple thing you can do is rename your HTML files like 1.html, 2.html ..... 10.html
Declare an integar variable in your .h file initialize it in viewDidLoad and on detecting swipe right increment in that variable and use formatString to make correct url and reload the webview and on detecting swipe left decrement in that variable make correct url and reload the webview.
-(void)swipeRightDetected
{
if(fileNumber <= 10)
{
fileNumber++;
NSString *urlString = [NSString stringWithFormat:#"http://172.161.331.25/casa/admmathematic/Page00%d.html",fileNumber];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[webview loadRequest:request];
}
else
{
//No more files
}
}
-(void)swipeLeftDetected
{
if(fileNumber > 0)
{
fileNumber--;
NSString *urlString = [NSString stringWithFormat:#"http://172.161.331.25/casa/admmathematic/Page00%d.html",fileNumber];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[webview loadRequest:request];
}
else
{
//No more files
}
}
Related
Im struggled with redirect to webpage after read NFC scan by objective C.
Here is my code
- (void) readerSession:(nonnull NFCNDEFReaderSession *)session didDetectNDEFs:(nonnull NSArray<NFCNDEFMessage *> *)messages {
for (NFCNDEFMessage *message in messages) {
for (NFCNDEFPayload *payload in message.records) {
NSLog(#"Payload data:%#",payload.payload);
}
}
}
I got solution by using VYNFC kit,
https://github.com/vinceyuan/VYNFCKit
if ([parsedPayload isKindOfClass:[VYNFCNDEFURIPayload class]]) {
text = #"[URI payload]\n";
text = [NSString stringWithFormat:#"%#%#", text, ((VYNFCNDEFURIPayload *)parsedPayload).URIString];
urlString = ((VYNFCNDEFURIPayload *)parsedPayload).URIString;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webview loadRequest:requestObj];
}
I create app to use UIWebview and show log to url if touch in content in UIWebview.
this is my code
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url1 =[NSURL URLWithString:#"MyWebSite"];
NSURLRequest *request1 = [NSURLRequest requestWithURL:url1];
[_webView1 loadRequest:request1];
NSURL *url2 =[NSURL URLWithString:#"MyWebsite2"];
NSURLRequest *request2 = [NSURLRequest requestWithURL:url2];
[_webView2 loadRequest:request2];//url menu 2
NSString *currentURL = [_webView1 stringByEvaluatingJavaScriptFromString:#"document.title"];
NSLog(#"%#",currentURL);
}
but I touch the content log is not print and change webview log is print (null)
sorry for my poor English.
You can not get title of a website before you receive data from the URL.
So
Set your webview delegate to self
Then in
- webViewDidFinishLoad: to get title
I am learing WebView.
when I do something like
NSString *url = #"www.google.com";
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
it fails.
But when I type www.google.com (or even google.com) in standard browser, it works fine.
I also noticed that after loading the page, the url text field in standard browser changes the link from www.google.com to https:// www. google.co.in/?gws_rd=ssl
In above code when I set NSString *url = #"https://www.google.co.in/?gws_rd=ssl" it works fine
So how do I implement my WebView view so that if should work like a standard browser it terms of above context
UIWebView always needs http or https when starting request, if you click on links inside the webView it will handle it itself. So here is how to handle it:
- (void)viewDidLoad
{
[super viewDidLoad];
UITextField *addressBar = [[UITextField alloc] init];
[addressBar setDelegate:self];
[self loadRequestFromString:#"www.google.com"];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self loadRequestFromString:textField.text];
[textField resignFirstResponder];
return YES;
}
- (void)loadRequestFromString:(NSString *)urlString
{
NSURL *webpageUrl;
if ([urlString hasPrefix:#"http://"] || [urlString hasPrefix:#"https://"]) {
webpageUrl = [NSURL URLWithString:urlString];
} else if ([urlString containsString:#" "] || ![urlString containsString:#"."]) {
webpageUrl = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.google.com/search?q=%#", [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
} else {
webpageUrl = [NSURL URLWithString:[NSString stringWithFormat:#"http://%#", urlString]];
}
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:webpageUrl];
[_webView loadRequest:urlRequest];
}
to open any URL in UIWebView you should add url with protocol
eg #"http://www.google.com".
[NSURL URLWithString:#"http://www.google.com"];
then it will work.
I have three UIwebView added from story board when i load them i add activity indicator to show loading progress and when loading is finish. Delegate of DidFinishLoading called. But i see the white color on uiwebview. When i again load the UIwebview when white screen is visible then it shows the error "Operation couldn't be completed" but when loading of UIwebview is properly done and again i reload with new url. then it does not show any error.
Please somebody tell me.. Thanks in advance.
NSString* urlgmap=#"www.google.com"
NSURL *url_gmap = [NSURL URLWithString:urlgmap];
NSURLRequest *request_gmap = [NSURLRequest requestWithURL:url_gmap cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
[self.wrae_one loadRequest:request_gmap];
NSString* urlgrid=#"www.yahoo.com";
NSURL *url_grid = [NSURL URLWithString:urlgrid];
NSURLRequest *request_grid = [NSURLRequest requestWithURL:url_grid cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
[self.wrae_two loadRequest:request_grid];
NSString* urlSmap=#"www.facebook.com";
NSURL *url_smap = [NSURL URLWithString:urlSmap];
NSURLRequest *request_smap = [NSURLRequest requestWithURL:url_smap cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
How would you detect any attempt to display an SSL URL that contains non-SSL assets in WebView? Just like a browser gives you a mixed-SSL warning.
I don't see any obvious property on UIWebView or UIWebViewDelegate. I could subclass NSURLProtocol, and somehow communicate the non-SSL connections back to the UIWebView. Is there an easier way to do this?
One solution is to create your custom URL cache and make it the default so you can catch all HTTP requests, and then you can check for mixed SSL content.
Here is an example:
#interface MonitoringURLCache : NSURLCache
#end
#implementation MonitoringURLCache
- (NSCachedURLResponse*)cachedResponseForRequest:(NSURLRequest *)request {
NSURL *requestURL = [request URL];
NSURL *pageURL = [request mainDocumentURL];
if ([[pageURL scheme] isEqualToString:#"https"] && [[requestURL scheme] isEqualToString:#"http"]) {
NSLog(#"Non safe resource: %# referenced from page: %#", requestURL, pageURL);
}
return [super cachedResponseForRequest:request];
}
#end
/// Register your custom cache
MonitoringURLCache *cache = [[MonitoringURLCache alloc] init];
[NSURLCache setSharedURLCache:cache];
/// Make a request to a website with mixed SSL content
NSURL *url = [NSURL URLWithString:#"https://some-website-with-mixed-ssl-content/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];