You are using the wrong method. Instead of using stringByAddingPercentEncodingWithAllowedCharacters
use this stringByAddingPercentEscapesUsingEncoding
If you wan't to use this method stringByAddingPercentEncodingWithAllowedCharacters
you have to pass a set of allowed characters.
Try this.
NSURL *candidatesURL = [NSURL URLWithString:[str_url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
Or if you app development target is IOS 9.0 and above.
stringByAddingPercentEscapesUsingEncoding
is deprecated so you can use stringByAddingPercentEncodingWithAllowedCharacters
and use URLHostAllowedCharacterSet
.
NSURL *candidatesURL = [NSURL URLWithString:[str_url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];