I found that you can enter some URLs that look fine but are rejected by the NSURL creation methods. Therefore, we have a way to avoid the string first, to make sure that it is in good format. Here is his meat:
NSString * escapedURLString =
NSMakeCollectable (CFURLCreateStringByAddingPercentEscapes (NULL,
(CFStringRef) URLString,
(CFStringRef) @ "% + #", // Characters to leave unescaped
NULL
kCFStringEncodingUTF8));
source share