(ibaction) Open URL in safari


/ Published in: Objective C
Save to your folder(s)

simple snippet to open url with an ibaction in safari


Copy this code and paste it in your HTML
  1. - (IBAction)LauchURLAction:(id)sender
  2. {
  3.  
  4. NSLog(@"***[STARTING] - open URL in Safari ");
  5. [self launchURL:@"http://www.someurl.com"];
  6. }
  7.  
  8.  
  9.  
  10. - (void)launchURL:(NSString *) urlToLaunch
  11. {
  12. NSLog(@"***[STARTING] - launch url ");
  13. NSString *urlToOpen = [NSString stringWithFormat:urlToLaunch];
  14. urlToOpen = [urlToOpen stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
  15. NSURL *url = [NSURL URLWithString:urlToOpen];
  16. if (![[UIApplication sharedApplication] openURL:url])
  17. NSLog(@"%@%@", @"Failed ton open url:",[url description]);
  18. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.