Andy Andy - 1 year ago 166
Objective-C Question

objective c convert special URL to NSURL

I have a

like this, and I can't convert it to the

NSString * mURL = @"";
NSString *pathComponent = [mURL stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSURL* uri = [NSURL URLWithString:pathComponent];
NSLog(@"uri host = %@",;
NSLog(@"uri path = %@", uri.path);

And, the host and path are (null). How can I fix this?

Answer Source

Please check below code, it is working,

NSString * mURL = @"";
NSString * webStringURL = [mURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
NSURL* url = [NSURL URLWithString:webStringURL];
NSLog(@"uri host = %@",;
NSLog(@"uri path = %@", url.path);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download