之前使用的副程式,遇到 iOS 9 已被停用,xcode 提示我請改用 stringByAddingPercentEncodingWithAllowedCharacters。
修改前副程式:
- (NSString*)escapePath:(NSString*)url { CFStringEncoding encoding = CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding); NSString *escapedPath = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)url, NULL, (CFStringRef)@":?=,!$&'()*+;[]@#~", encoding);
修改後副程式:
- (NSString*)escapePath:(NSString*)url { NSString *charactersToEscape = @"?!@#$^&%*+,:;='\"`<>()[]{}/\\| "; NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:charactersToEscape] invertedSet]; NSString *encodedUrl = [url stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];