NSURL for IOS development
1: NSURL initialization method:
- NSURL* Url = [NSURLURLWithString: @ www. bkjia. comid = 1];
2: solutions to NSURL initialization failures.
Transcode the passed NSString to UTF8.
1: solution to URLWithString initialization failure
- NSString* StrLocalHtml=@ File: // Users/amarishuyi/Desktop/MyIPhoneLife/WebDeveloper/WebPlug-in/ExtEditor/DataPage/KMQT/Ext-HTMLEditor.html;
- StrLocalHtml=[NSStringStringWithFormat: @ % @? Value00000000@,strlocalhtml,self.txt Url. text];
- StrLocalHtml =[StrLocalHtmlStringByAddingPercentEscApesUsingEncoding: NSUTF8StringEncoding];
- NSURL*Url = [NSURLURLWithString: strLocalHtml];
2: Solution for fileURLWithPath initialization failure
- Self. filePathString=[Self. filePathStringStringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
- NSURL* Url=[NSURLFileURLWithPath: self. filePathString];
After transcoding is successful, it is automatically added to the left side of the string.File :///
3: parameters that can be obtained after successful NSURL initialization (from: NSURL Learning)
- NSURL* Url=[NSURLURLWithString: @ Www.bkjia.com? Tn = baiduhome_pg & bs = nsul & f = 8 & rsv_bp = 1 & rsv_spt = 1 & wd = NSurl & inputT = 2709];
- NSLog (@ Scheme:% @,[UrlScheme]);
- NSLog (@ Host:% @,[UrlHost]);
- NSLog (@ Port:% @,[UrlPort]);
- NSLog (@ Path:% @,[UrlPath]);
- NSLog (@ RelativePath:% @,[UrlRelativePath]);
- NSLog (@ PathComponentsAsArray:% @,[UrlPathComponents]);
- NSLog (@ ParameterString:% @,[UrlParameterString]);
- NSLog (@ Query:% @,[UrlQuery]);
- NSLog (@ Fragment:% @,[UrlFragment]);
- NSLog (@ User:% @,[UrlUser]);
- NSLog (@ Password:% @,[UrlPassword]);
The result is as follows:
- 2012-03-3118:22:20. 904SmallDemoList [5473: 11603]12131232
- 2012-03-3118:22:20. 907SmallDemoList [5473: 11603]Scheme:Http
- 2012-03-3118:22:20. 907SmallDemoList [5473: 11603]Host:Www.baidu.com
- 2012-03-3118:22:20. 907SmallDemoList [5473: 11603]Port:(Null)
- 2012-03-3118:22:20. 907SmallDemoList [5473: 11603]Path:/S
- 2012-03-3118:22:20. 907SmallDemoList [5473: 11603]RelativePath:/S
- 2012-03-3118:22:20. 907SmallDemoList [5473: 11603]PathComponentsAs Array:(
- /,
- S
- )
- 2012-03-3118:22:20. 916SmallDemoList [5473: 11603]ParameterString:(Null)
- 2012-03-3118:22:20. 917SmallDemoList [5473: 11603]Query:Tn = baiduhome_pg & bs = nsul & f = 8 & rsv_bp = 1 & rsv_spt = 1 & wd = NSurl & inputT = 2709
- 2012-03-3118:22:20. 917SmallDemoList [5473: 11603]Fragment:(Null)
- 2012-03-3118:22:20. 917SmallDemoList [5473: 11603]User:(Null)
- 2012-03-18:22:20. 917SmallDemoList [5473: 11603]Password:(Null)
4. Obtain the path of the package Content File Based on the file name and suffix.
NSURL* UrlKindEditor = [[NSBundlemainBundle] URLForResource: @ simplewithExtension: @ htmlsubdirectory: @ KindEditor/examples];
URLForResource: File Name
WithExtension: file suffix
Subdirectory: Which subdirectory of the package to search.
If not found, nil is returned.
The following path is returned:File: // localhost/Users/amarishuyi/Library/Application Support/iPhone Simulator/5.1/Applications/FB0CDABC-D0E2-45FF-AA2C-959E8A65ADB4/SmallDemoList. app/KindEditor/examples/simple.html