2016-10-12 4 views
0

Ich habe versucht, in WebView unter URL zu öffnenWie öffne ich URL in WebView in iOS?

http://1-dot-smartrefill-968.appspot.com/#/#[email protected]_com

aber nicht in der Lage Objekt von NSURL zu machen.

+0

, in welcher Sprache versucht u dies in Objective C oder swift Add Sprach-Tag und zeigen Sie Ihren versucht Code –

+0

NSString * StrUrl = [[NSString string: @ "% @% @ ", ITEM_URL, [AppDelegate_.usermanager userName]] stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet URLPathAllowedCharacterSet]]; NSURLRequest * Anfrage = [NSURLRequest requestWithURL: [NSURL URLWithString: strUrl]]; [self.webView loadRequest: Anfrage]; –

+0

#define ITEM_URL @ "http://1-dot-smartrefill-968.appspot.com/#/#" –

Antwort

1

Step-1

initially add NSAppTransportSecurity in your .plist, see this

Schritt-2

call the url like

NSString *urlAddress = @"http://1-dot-smartrefill-968.appspot.com/#/#[email protected]_com"; 
[self.yourwebviewName loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSURL URLWithString:[urlAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]]]; 
+0

NSString * strUrl = [[NSString StringWithFormat: @ "% @ % @ ", ITEM_URL, [AppDelegate_.usermanager userName]] stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet URLPathAllowedCharacterSet]]; NSURLRequest * Anfrage = [NSURLRequest requestWithURL: [NSURL URLWithString: strUrl]]; [selbst.webView loadRequest: Anfrage]; –

+0

@AshokD - an diesem Ort '[[NSString stringWithFormat: @"% @% @ ", ITEM_URL, [AppDelegate_.usermanager userName]] stringByAddingPercentEncodingWithAllowedCharacters: [NSCharac terSet URLPathAllowedCharacterSet]];' versuchen Sie meine Answer einmal –

1

wo ist dein Code? hast du ein WebView benutzt?

   [_webView loadRequest:[NSURLRequest requestWithURL:url]]; 

Ich verwende diese Methode.

+0

guten Mann .. ...... –

+0

ich habe alles versucht, dann diese Frage stellen. NSURL ist nicht erstellt, es ist null mit dieser URL. –

0

Für swift:

var url : NSString = "http://1-dot-smartrefill-968.appspot.com/#/#[email protected]_com" 
var urlStr : NSString = url.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)! 
var searchURL : NSURL = NSURL(string: urlStr)! 
    webviewInstance.loadRequest(NSURLRequest(URL: searchURL)) 

Für Objective-c

[webviewInstance loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSURL URLWithString:[your_URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]]]; 
+0

Ich habe das alles versucht, dann posten Sie diese Frage. NSURL ist nicht erstellt, es ist null mit dieser URL. –

+0

haben Sie 'NSUTF8StringEncoding' mit Ihrem URL-String getan? –

+0

Ja, ich habe es versucht. Aber Webview lädt diese URL nicht. –

1

Versuchen Sie, Ihre URL mit addingPercentEncoding statt stringByAddingPercentEscapesUsingEncoding zu kodieren, weil es veraltet ist.

In Swift:

  • für SWIFT 3:

    let strUrl = "http://1-dot-smartrefill-968.appspot.com/#/#[email protected]_com" 
    let encodedUrl = strUrl.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) 
    
  • für SWIFT 2.3 oder niedriger:

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

In Objective-C

NSString *strUrl = @"http://1-dot-smartrefill-968.appspot.com/#/#[email protected]_com"; 
NSString *encodedUrl = [strUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]; 
+0

Diese uRL webview nicht geladen wird, das ist ein Fehler. Kann bitte vorschlagen? –

+0

@AshokD Hast Du diesen http://stackoverflow.com/questions/19713610/how-to-resolve-frame-load-interrupted-error-in-uiwebview überprüfen und diese http://stackoverflow.com/questions/23473780/ ios-uiwebview-frame-load-unterbrochen –

Verwandte Themen