NSURL for IOS development

Source: Internet
Author: User

NSURL for IOS development

1: NSURL initialization method:


  1. 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

    1. NSString* StrLocalHtml=@ File: // Users/amarishuyi/Desktop/MyIPhoneLife/WebDeveloper/WebPlug-in/ExtEditor/DataPage/KMQT/Ext-HTMLEditor.html;
    2. StrLocalHtml=[NSStringStringWithFormat: @ % @? Value00000000@,strlocalhtml,self.txt Url. text];
    3. StrLocalHtml =[StrLocalHtmlStringByAddingPercentEscApesUsingEncoding: NSUTF8StringEncoding];
    4. NSURL*Url = [NSURLURLWithString: strLocalHtml];

      2: Solution for fileURLWithPath initialization failure

      1. Self. filePathString=[Self. filePathStringStringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
      2. 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)

         

        1. NSURL* Url=[NSURLURLWithString: @ Www.bkjia.com? Tn = baiduhome_pg & bs = nsul & f = 8 & rsv_bp = 1 & rsv_spt = 1 & wd = NSurl & inputT = 2709];
        2. NSLog (@ Scheme:% @,[UrlScheme]);
        3. NSLog (@ Host:% @,[UrlHost]);
        4. NSLog (@ Port:% @,[UrlPort]);
        5. NSLog (@ Path:% @,[UrlPath]);
        6. NSLog (@ RelativePath:% @,[UrlRelativePath]);
        7. NSLog (@ PathComponentsAsArray:% @,[UrlPathComponents]);
        8. NSLog (@ ParameterString:% @,[UrlParameterString]);
        9. NSLog (@ Query:% @,[UrlQuery]);
        10. NSLog (@ Fragment:% @,[UrlFragment]);
        11. NSLog (@ User:% @,[UrlUser]);
        12. NSLog (@ Password:% @,[UrlPassword]);

          The result is as follows:

          1. 2012-03-3118:22:20. 904SmallDemoList [5473: 11603]12131232
          2. 2012-03-3118:22:20. 907SmallDemoList [5473: 11603]Scheme:Http
          3. 2012-03-3118:22:20. 907SmallDemoList [5473: 11603]Host:Www.baidu.com
          4. 2012-03-3118:22:20. 907SmallDemoList [5473: 11603]Port:(Null)
          5. 2012-03-3118:22:20. 907SmallDemoList [5473: 11603]Path:/S
          6. 2012-03-3118:22:20. 907SmallDemoList [5473: 11603]RelativePath:/S
          7. 2012-03-3118:22:20. 907SmallDemoList [5473: 11603]PathComponentsAs Array:(
          8. /,
          9. S
          10. )
          11. 2012-03-3118:22:20. 916SmallDemoList [5473: 11603]ParameterString:(Null)
          12. 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
          13. 2012-03-3118:22:20. 917SmallDemoList [5473: 11603]Fragment:(Null)
          14. 2012-03-3118:22:20. 917SmallDemoList [5473: 11603]User:(Null)
          15. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.