How to find out if a NSString
is an website URL in Objective-c
.It will be better if you provide source code. If not, tell me which class is useful is good enough.
Finally i found a way to judge,may not the best way,but useful :
NSURL *url = [NSURL URLWithString:urlStr];
NSURL *lazyUrlStr = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@",urlStr]];
if([[UIApplication sharedApplication] canOpenURL:url]){
NSLog(@"it's a url");
}else if([[UIApplication sharedApplication] canOpenURL:lazyUrlStr]){
NSLog(@"it's a url");
}else{NSLog(@"it isn't a url");
}
FYI: urlStr is the NSString to be judged