0

I Referred a many links related to this issue,But I cannot able to find the answer.I am getting a dynamic url in my app...If the url contains http://www then it opens the link,If www is not present then this error occurs.Any Help on this.

I am using this code,

NSString *selectedurl=[self.SelectedItem objectForKey:@"url"];
selectedurl=[selectedurl stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

NSURL *url=[NSURL URLWithString:selectedurl];

   if (url.scheme.length == 0)
   {
    selectedurl = [@"http://" stringByAppendingString:selectedurl];
    url  = [[NSURL alloc] initWithString:selectedurl];
   }

  if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:selectedurl]])
   {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:selectedurl]];
   }

enter image description here

Shangari C
  • 792
  • 1
  • 5
  • 17
  • are you added the application query schema in your plist – Anbu.Karthik Jun 09 '16 at 06:52
  • No,I will check for that.I refered this link http://stackoverflow.com/questions/8201724/how-to-register-a-custom-app-opening-url-scheme-with-xcode-4..What should I need to add my plist,because I am getting url for webservice It can be anything – Shangari C Jun 09 '16 at 06:54

1 Answers1

0

only the URL will start in www your page does not open, you need to append thehttp:` in front of the string, so try this

NSString *sentence = @"www.google.com";
NSString *searchWord = @"http";
if ([sentence rangeOfString: searchWord].location != NSNotFound) {
    NSLog(@"Yes , the search word is available");
}else
{
  // add the http in front of www using stringWithFormat
 }

or the alternate way

 NSString *string = @"www.google.com";
if ([string containsString:@"http"]) {
  NSLog(@"string contains http..!");
} else {
  NSLog(@"string does not contain http...!");
}

choice-2

I think what you are searching for is Universal Links. Check this documentation for it here. It's pretty simple and straight forward. And here is a step by step explanation of how to support them. And afterwards, you can validate your own custom universal links here or hereenter link description here

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
  • are you try the deep linking, if yes check once in your plist contains valid url schema or not else try universal links – Anbu.Karthik Jun 09 '16 at 07:01
  • If the url http://www.hokeypokey.in/ It opens in safari..If it is like this http://zaica.dinein.in/veg/ it does not opens it shows me an error `the address is invalid`..No I didnt try with deep linking.Let me check – Shangari C Jun 09 '16 at 07:05
  • Thanks bro,will check – Shangari C Jun 09 '16 at 08:41