Skip to content

Instantly share code, notes, and snippets.

@hebertialmeida
Created March 21, 2014 06:34
Show Gist options
  • Save hebertialmeida/9680780 to your computer and use it in GitHub Desktop.
Save hebertialmeida/9680780 to your computer and use it in GitHub Desktop.
Open native Apps or open on Safari if don't have the App
- (void)openThisURL:(NSString *)launchUrl withFallback:(NSString *)fallback
{
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:launchUrl]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:launchUrl]];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:fallback]];
}
}
// Usage
- (IBAction)didTouchOnButton:(UIButton *)sender
{
[self openThisURL:@"twitter://user?screen_name=hebertialmeida" withFallback:@"https://twitter.com/hebertialmeida"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment