原文:blog.csdn.net/zhiyou007/article/details/8257942
1:NSURL初始化方法:
NSURL?*url=[NSURL?URLWithString:@"http://www.baidu.com?id=1"];
2:解決NSURL初始化失敗的方法.
將傳進來的NSString 進行 UTF8 轉碼即可.
NSString?*strLocalHtml?=?@"file:///Users/amarishuyi/Desktop/My?IPhone?Life/WebDeveloper/WebPlug-in/ExtEditor/DataPage/KMQT/Ext-HTMLEditor.html";
strLocalHtml?=?[NSString?stringWithFormat:@"%@?Value=%@",strLocalHtml,self.txtUrl.text];
strLocalHtml=?[strLocalHtml?stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL?*?url=[NSURL?URLWithString:strLocalHtml];
3:NSURL 成功初始化后可以獲取的參數(shù)?
NSURL?*url?=?[NSURL?URLWithString:??@"http://www.baidu.com/s?tn=baiduhome_pg&bs=NSRUL&f=8&rsv_bp=1&rsv_spt=1&wd=NSurl&inputT=2709"];
NSLog(@"Scheme: %@", [url scheme]);? 結果:Scheme: http
NSLog(@"Host: %@", [url host]);? 結果:Host: www.baidu.com
NSLog(@"Port: %@", [url port]);? 結果:Port: (null)
NSLog(@"Path: %@", [url path]); 結果:Path: /s
NSLog(@"Relative path: %@", [url relativePath]);結果:Relative path: /s
NSLog(@"Path components as array: %@", [url pathComponents]);結果:Path componentsasarray: (
"/",
s
)
NSLog(@"Parameter string: %@", [url parameterString]);結果:Parameterstring: (null)
NSLog(@"Query: %@", [url query]);結果:Query: tn=baiduhome_pg&bs=NSRUL&f=8&rsv_bp=1&rsv_spt=1&wd=NSurl&inputT=2709
NSLog(@"Fragment: %@", [url fragment]);結果:Fragment: (null)
NSLog(@"User: %@", [url user]);結果:User: (null)
NSLog(@"Password: %@", [url password]);結果:Password: (null)
4:根據文件名稱和文件后綴獲取程序包內容文件的路徑
NSURL*urlKindEditor = [[NSBundlemainBundle]URLForResource:@"simple"withExtension:@"html"subdirectory:@"KindEditor/examples"];
URLForResource:文件名稱
withExtension:文件后綴
subdirectory:在程序包中的哪個子目錄中尋找.
如果沒有找到將會返回nil
找到后返回如下路徑:file://localhost/Users/amarishuyi/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/FB0CDABC-D0E2-45FF-AA2C-959E8A65ADB4/SmallDemoList.app/KindEditor/examples/simple.htmlblog.c