Last active
August 29, 2015 14:21
-
-
Save luoph/98b4dcfb15119431df36 to your computer and use it in GitHub Desktop.
iOS url endcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 1. [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] 会导致=等符号转换 | |
| * 成urf8的编码\u003d导致url无法正常解析 | |
| * 2. [NSURL URLWithString:url] 又会导致中文等字符无法encode | |
| */ | |
| - (NSString*)encodeUrl:(NSString*)string | |
| { | |
| NSString* encodedString = (NSString*)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, | |
| (CFStringRef)self, | |
| (CFStringRef) @"!$&'()*+,-./:;=?@_~%#[]", | |
| NULL, | |
| kCFStringEncodingUTF8)); | |
| return encodedString; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment