This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Improve/refactor BVMOpenLinkManager browser availability testing code

  • Loading branch information...
cdzombak committed Mar 29, 2013
1 parent 4311851 commit 343e6afd258b0b59c7179ee38989817323d22311
Showing with 11 additions and 10 deletions.
  1. +11 −10 buyvmmanager/BVMLinkOpenManager.m
@@ -3,13 +3,18 @@
static NSString *kBVMBrowserPrefsKey = @"BVMBrowserPrefsKey";
static NSString *kBVMBrowserNames[BVMNumBrowsers];
+static NSURL *kBVMBrowserTestURLs[BVMNumBrowsers];
__attribute__((constructor)) static void __BVMBrowserConstantsInit(void)
{
@autoreleasepool {
kBVMBrowserNames[BVMBrowserSafari] = NSLocalizedString(@"Safari", nil);
kBVMBrowserNames[BVMBrowserOnePassword] = NSLocalizedString(@"1Password", nil);
kBVMBrowserNames[BVMBrowserChrome] = NSLocalizedString(@"Google Chrome", nil);
+
+ kBVMBrowserTestURLs[BVMBrowserSafari] = [NSURL URLWithString:@"http://google.com"];
+ kBVMBrowserTestURLs[BVMBrowserChrome] = [NSURL URLWithString:@"googlechrome://google.com"];
+ kBVMBrowserTestURLs[BVMBrowserOnePassword] = [NSURL URLWithString:@"onepassword://search"];
}
}
@@ -19,17 +24,13 @@ @implementation BVMLinkOpenManager
+ (BOOL)browserAvailable:(BVMBrowser)browser
{
- switch(browser) {
- case BVMBrowserSafari:
- return YES;
- case BVMBrowserChrome:
- return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"googlechrome://google.com"]];
- case BVMBrowserOnePassword:
- return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"onepassword://search"]];
- default:
- NSLog(@"Unknown browser %d in %s", browser, __PRETTY_FUNCTION__);
- return NO;
+ if (browser >= BVMNumBrowsers || browser < 0) {
+ NSLog(@"Unknown browser %d in %s", browser, __PRETTY_FUNCTION__);
+ return NO;
}
+
+ NSURL *testURL = kBVMBrowserTestURLs[browser];
+ return [[UIApplication sharedApplication] canOpenURL:testURL];
}
#pragma mark Default browser management

0 comments on commit 343e6af

Please sign in to comment.