0

I have tried to open below url in WebView

http://1-dot-smartrefill-968.appspot.com/#/#mfucci@gmail_com

But unable to make object of NSURL.

Nirav D
  • 71,513
  • 12
  • 161
  • 183
Ashok Domadiya
  • 1,124
  • 13
  • 31
  • in which language u tried this in objective C or swift add language tag and show your tried code – Anbu.Karthik Oct 12 '16 at 06:43
  • NSString *strUrl = [[NSString stringWithFormat:@"%@%@",ITEM_URL,[AppDelegate_.usermanager userName]] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:strUrl]]; [self.webView loadRequest:request]; – Ashok Domadiya Oct 12 '16 at 09:05
  • #define ITEM_URL @"http://1-dot-smartrefill-968.appspot.com/#/#" – Ashok Domadiya Oct 12 '16 at 09:05
  • what the output you get here `strUrl` – Anbu.Karthik Oct 12 '16 at 09:06

4 Answers4

2

where's your code? did u use a webView?

I used this method :

[_webView loadRequest:[NSURLRequest requestWithURL:url]];
Kishan Bharda
  • 5,446
  • 3
  • 30
  • 57
dalegege
  • 21
  • 1
1

Step-1

initially add NSAppTransportSecurity in your .plist, see this

step-2

call the url like

NSString *urlAddress =  @"http://1-dot-smartrefill-968.appspot.com/#/#mfucci@gmail_com"; 
[self.yourwebviewName loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSURL URLWithString:[urlAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]]];
Community
  • 1
  • 1
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
  • NSString *strUrl = [[NSString stringWithFormat:@"%@%@",ITEM_URL,[AppDelegate_.usermanager userName]] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]]; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:strUrl]]; [self.webView loadRequest:request]; – Ashok Domadiya Oct 12 '16 at 09:07
  • @AshokD - in this place `[[NSString stringWithFormat:@"%@%@",ITEM_URL,[AppDelegate_.usermanager userName]] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharac‌​terSet URLPathAllowedCharacterSet]];` try my ansswer once – Anbu.Karthik Oct 12 '16 at 09:08
1

Try to encode your URL using addingPercentEncoding instead of stringByAddingPercentEscapesUsingEncoding because it is deprecated.

In Swift:

  • For Swift 3:

    let strUrl = "http://1-dot-smartrefill-968.appspot.com/#/#mfucci@gmail_com"
    let encodedUrl = strUrl.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
    
  • For Swift 2.3 or lower:

     let encodedUrl = strUrl.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())
    

In Objective-C

NSString *strUrl = @"http://1-dot-smartrefill-968.appspot.com/#/#mfucci@gmail_com";
NSString *encodedUrl = [strUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
Nirav D
  • 71,513
  • 12
  • 161
  • 183
  • This url is not load webview, that is an error. Can pls suggest ? – Ashok Domadiya Oct 12 '16 at 08:44
  • @AshokD Have you check this http://stackoverflow.com/questions/19713610/how-to-resolve-frame-load-interrupted-error-in-uiwebview and this http://stackoverflow.com/questions/23473780/ios-uiwebview-frame-load-interrupted – Nirav D Oct 12 '16 at 09:49
0

For swift :

var url : NSString = "http://1-dot-smartrefill-968.appspot.com/#/#mfucci@gmail_com" 
var urlStr : NSString = url.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)! 
var searchURL : NSURL = NSURL(string: urlStr)! 
    webviewInstance.loadRequest(NSURLRequest(URL: searchURL))

For objective-c

[webviewInstance loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSURL URLWithString:[your_URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]]];
Maulik Pandya
  • 2,200
  • 17
  • 26
  • I have tried all this,then post this question. NSURL is not create, it's null with that url. – Ashok Domadiya Oct 12 '16 at 07:33
  • have you done `NSUTF8StringEncoding` with your url string? – Maulik Pandya Oct 12 '16 at 07:42
  • Yes, I have tried. But webview is not load that url. – Ashok Domadiya Oct 12 '16 at 08:45
  • RootViewController.m-->-[RootViewController webView:didFailLoadWithError:]@114: URL Error Error Domain=WebKitErrorDomain Code=102 "Frame load interrupted" UserInfo={NSErrorFailingURLStringKey=file://http%253A%252F%252F1-dot-smartrefill-968.appspot.com%252F%2523%252F%2523himen%2540blupixeltech.in, NSLocalizedDescription=Frame load interrupted, NSErrorFailingURLKey=file://http%253A%252F%252F1-dot-smartrefill-968.appspot.com%252F%2523%252F%2523himen%2540ashok.in} – Ashok Domadiya Oct 12 '16 at 08:48