cocoa - How to load NSURL that contains “#” with WebView? -


i have url string contains "#".for example,

nsstring* urlstr = @"https://developer.apple.com/library/ios/#/legacy/library/documentation/xcode/conceptual/ios_development_workflow/10-configuring_development_and_distribution_assets/identities_and_devices.html#//apple_ref/doc/uid/tp40007959-ch4-sw"; urlstr = [urlstr stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]; nsurl* url = [nsurl urlwithstring:urlstr]; [[self.webviewsample mainframe] loadrequest:[nsurlrequest requestwithurl:url]]; 

after using encoding ,the "#" replaced "%23".if don't use encoding, nsurl nil. problem webview load incorrect webpage different browser.how can handle url string can load correct webpage?

so think question now, root problem apple's documentation uses rather oddly formed urls. contain more 1 # character, isn't technically valid url. first valid (and important); others should escaped.

safari able handle this, think because more display/use raw url string. best solution i've found date hand off webview's pasteboard handling, so:

- (nsurl *)urlfromstring:(nsstring *)string; {     static nspasteboard *pboard;     if (!pboard) pboard = [[nspasteboard pasteboardwithuniquename] retain];      [pboard clearcontents];     [pboard writeobjects:@[string]];      nsurl *result = [webview urlfrompasteboard:pboard];     return result; } 

more details @ http://www.mikeabdullah.net/webkit-encode-unescaped-urls.html


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -