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

extract browser selection stuff to its own CocoaPod

  • Loading branch information...
cdzombak committed Mar 29, 2013
1 parent 1537b9c commit e4c36ecbd416561bb8edf9c4f59fae79f73ab0ce
View
@@ -8,3 +8,4 @@ pod 'ZBarSDK'
pod 'iRate'
pod 'QuincyKit'
pod 'CDZPinger', :podspec => 'https://raw.github.com/cdzombak/CDZPinger/master/CDZPinger.podspec'
+pod 'CDZLinkOpenManager', :podspec => 'https://raw.github.com/cdzombak/CDZLinkOpenManager/master/CDZLinkOpenManager.podspec'
View
@@ -1,5 +1,6 @@
PODS:
- AFNetworking (1.0.1)
+ - CDZLinkOpenManager (1.0)
- CDZPinger (1.0)
- iRate (1.7.2)
- KissXML (5.0)
@@ -10,6 +11,7 @@ PODS:
DEPENDENCIES:
- AFNetworking
+ - CDZLinkOpenManager (from `https://raw.github.com/cdzombak/CDZLinkOpenManager/master/CDZLinkOpenManager.podspec`)
- CDZPinger (from `https://raw.github.com/cdzombak/CDZPinger/master/CDZPinger.podspec`)
- iRate
- KissXML
@@ -19,11 +21,14 @@ DEPENDENCIES:
- ZBarSDK
EXTERNAL SOURCES:
+ CDZLinkOpenManager:
+ :podspec: https://raw.github.com/cdzombak/CDZLinkOpenManager/master/CDZLinkOpenManager.podspec
CDZPinger:
:podspec: https://raw.github.com/cdzombak/CDZPinger/master/CDZPinger.podspec
SPEC CHECKSUMS:
AFNetworking: 0bce3ae41023e080e96b8a2e0d07c94709f72a81
+ CDZLinkOpenManager: 3085d07c7572b2fdc80217d8a3bc350a977f19b9
CDZPinger: 90f5eb629f26b780d08a3359ba4d504896359fbb
iRate: eb1d02ff0a2bfee220f5fe028583b4ce5f3ef3bd
KissXML: 8dfe0fb6d4e987fec63656ff07d5e697f49976f8
@@ -54,8 +54,6 @@
93ADFEE1168F487F00F8256C /* BVMAddEditServerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 93ADFEE0168F487F00F8256C /* BVMAddEditServerViewController.m */; };
93BADD411683C19900B0CD6F /* UIColor+BVMColors.m in Sources */ = {isa = PBXBuildFile; fileRef = 93BADD401683C19900B0CD6F /* UIColor+BVMColors.m */; };
93BADD481684DE9D00B0CD6F /* BVMAPIResponseParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 93BADD471684DE9D00B0CD6F /* BVMAPIResponseParser.m */; };
- 93E5D84416EE727B00C57111 /* CDZBrowserSelectorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 93E5D84316EE727A00C57111 /* CDZBrowserSelectorViewController.m */; };
- 93E5D84716EE73D400C57111 /* CDZLinkOpenManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 93E5D84616EE73D200C57111 /* CDZLinkOpenManager.m */; };
93E5D84916EE83EA00C57111 /* 072-Settings@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 93E5D84816EE83EA00C57111 /* 072-Settings@2x.png */; };
93E5D84B16EE83FE00C57111 /* 072-Settings.png in Resources */ = {isa = PBXBuildFile; fileRef = 93E5D84A16EE83FE00C57111 /* 072-Settings.png */; };
/* End PBXBuildFile section */
@@ -136,10 +134,6 @@
93BADD491684E47A00B0CD6F /* NSError+BVMErrors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+BVMErrors.h"; sourceTree = "<group>"; };
93BADD4A1684E47A00B0CD6F /* NSError+BVMErrors.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+BVMErrors.m"; sourceTree = "<group>"; };
93BADD4C1684E60A00B0CD6F /* BVMErrorDomain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BVMErrorDomain.h; sourceTree = "<group>"; };
- 93E5D84216EE727900C57111 /* CDZBrowserSelectorViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDZBrowserSelectorViewController.h; sourceTree = "<group>"; };
- 93E5D84316EE727A00C57111 /* CDZBrowserSelectorViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDZBrowserSelectorViewController.m; sourceTree = "<group>"; };
- 93E5D84516EE73D200C57111 /* CDZLinkOpenManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDZLinkOpenManager.h; sourceTree = "<group>"; };
- 93E5D84616EE73D200C57111 /* CDZLinkOpenManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDZLinkOpenManager.m; sourceTree = "<group>"; };
93E5D84816EE83EA00C57111 /* 072-Settings@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "072-Settings@2x.png"; sourceTree = "<group>"; };
93E5D84A16EE83FE00C57111 /* 072-Settings.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "072-Settings.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -206,8 +200,6 @@
937CCC441684F5B70075BD01 /* BVMErrorDomain.m */,
93270A031682726F0013DEB5 /* BVMHumanValueTransformer.h */,
93270A041682726F0013DEB5 /* BVMHumanValueTransformer.m */,
- 93E5D84516EE73D200C57111 /* CDZLinkOpenManager.h */,
- 93E5D84616EE73D200C57111 /* CDZLinkOpenManager.m */,
935FEECF1682BC3700BE3892 /* BVMServersManager.h */,
935FEED01682BC3700BE3892 /* BVMServersManager.m */,
938662D81691F7F60049D6A1 /* CDZViewControllerModalDismissal.h */,
@@ -267,8 +259,6 @@
93ADFEE0168F487F00F8256C /* BVMAddEditServerViewController.m */,
83D310D41706154500BBE53D /* BVMBrowserSelectorViewController.h */,
83D310D51706154500BBE53D /* BVMBrowserSelectorViewController.m */,
- 93E5D84216EE727900C57111 /* CDZBrowserSelectorViewController.h */,
- 93E5D84316EE727A00C57111 /* CDZBrowserSelectorViewController.m */,
9382C96F16E3F36B00191302 /* BVMEmptyDetailViewController.h */,
9382C97016E3F36B00191302 /* BVMEmptyDetailViewController.m */,
9382C97116E3F36B00191302 /* BVMEmptyDetailViewController.xib */,
@@ -450,8 +440,6 @@
93ADFEDD168EB82C00F8256C /* KCMutableDictionary.m in Sources */,
93ADFEE1168F487F00F8256C /* BVMAddEditServerViewController.m in Sources */,
9382C97216E3F36B00191302 /* BVMEmptyDetailViewController.m in Sources */,
- 93E5D84416EE727B00C57111 /* CDZBrowserSelectorViewController.m in Sources */,
- 93E5D84716EE73D400C57111 /* CDZLinkOpenManager.m in Sources */,
83D310D61706154500BBE53D /* BVMBrowserSelectorViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -1,28 +0,0 @@
-#import <UIKit/UIKit.h>
-#import "CDZLinkOpenManager.h"
-
-typedef void (^CDZBrowserSelectedBlock)(CDZBrowser browser);
-
-@interface CDZBrowserSelectorViewController : UITableViewController
-
-/**
- * This block will be called when the user selects a browser.
- *
- * You might take this opportunity to dismiss a popover or pop your
- * navigation controller, for example.
- */
-@property (nonatomic, copy) CDZBrowserSelectedBlock browserSelectedBlock;
-
-/**
- * You can customize the UItableView's cell selection style here.
- */
-@property (nonatomic, assign) UITableViewCellSelectionStyle tableViewCellSelectionStyle;
-
-/**
- * Designated initializer
- */
-- (id)init;
-
-// Override -[ viewDidLoad] to customize appearance, if UIAppearance won't work well enough for you
-
-@end
@@ -1,101 +0,0 @@
-#import "CDZBrowserSelectorViewController.h"
-
-@interface CDZBrowserSelectorViewController ()
-
-@property (nonatomic, strong) NSIndexPath *previouslySelectedIndexPath;
-
-@end
-
-@implementation CDZBrowserSelectorViewController
-
-- (id)init
-{
- self = [super initWithStyle:UITableViewStyleGrouped];
- if (self) {
- self.tableViewCellSelectionStyle = UITableViewCellSelectionStyleBlue;
- }
- return self;
-}
-
-- (void)viewDidLoad
-{
- [super viewDidLoad];
-
- self.contentSizeForViewInPopover = CGSizeMake(320, 44*CDZNumBrowsers + 20);
-}
-
-#pragma mark UI Help
-
-- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
-{
- cell.textLabel.text = [CDZLinkOpenManager nameForBrowser:indexPath.row];
-
- if ([CDZLinkOpenManager browserAvailable:indexPath.row]) {
- cell.textLabel.textColor = [UIColor darkTextColor];
- cell.selectionStyle = self.tableViewCellSelectionStyle;
- } else {
- cell.textLabel.textColor = [UIColor lightGrayColor];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
-
- if ([CDZLinkOpenManager selectedBrowser] == indexPath.row) {
- cell.accessoryType = UITableViewCellAccessoryCheckmark;
- } else {
- cell.accessoryType = UITableViewCellAccessoryNone;
- }
-}
-
-#pragma mark UITableViewDataSource
-
-- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
-{
- return 1;
-}
-
-- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-{
- return CDZNumBrowsers;
-}
-
-- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-{
- static NSString * const CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (!cell) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- }
-
- [self configureCell:cell atIndexPath:indexPath];
- return cell;
-}
-
-#pragma mark UITableViewDelegate
-
-- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
-{
- CDZBrowser selectedBrowser = indexPath.row;
- [CDZLinkOpenManager setSelectedBrowser:selectedBrowser];
-
- [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- [self.tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
-
- if (self.previouslySelectedIndexPath && [indexPath compare:self.previouslySelectedIndexPath] != NSOrderedSame) {
- [self.tableView cellForRowAtIndexPath:self.previouslySelectedIndexPath].accessoryType = UITableViewCellAccessoryNone;
- }
-
- if (self.browserSelectedBlock) {
- self.browserSelectedBlock(selectedBrowser);
- }
-}
-
-- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
-{
- // hack:
- self.previouslySelectedIndexPath = [NSIndexPath indexPathForRow:[CDZLinkOpenManager selectedBrowser] inSection:0];
-
- if ([CDZLinkOpenManager browserAvailable:indexPath.row]) return indexPath;
- else return nil;
-}
-
-@end
@@ -1,40 +0,0 @@
-#import <Foundation/Foundation.h>
-
-typedef NS_ENUM(NSInteger, CDZBrowser) {
- CDZBrowserSafari = 0,
- CDZBrowserChrome,
- CDZBrowserOnePassword,
- CDZNumBrowsers
-};
-
-@interface CDZLinkOpenManager : NSObject
-
-/**
- * Returns YES if the given browser is available on this device.
- */
-+ (BOOL)browserAvailable:(CDZBrowser)browser;
-
-/**
- * Returns the user's selected default browser.
- */
-+ (CDZBrowser)selectedBrowser;
-
-/**
- * Sets the user's selected default browser.
- */
-+ (void)setSelectedBrowser:(CDZBrowser)browser;
-
-/**
- * Opens the given URL.
- *
- * If HTTP or HTTPS, uses the defaut browser.
- */
-+ (void)openURL:(NSURL *)url;
-+ (void)openURLString:(NSString *)urlString;
-
-/**
- * Returns the human-friendly name for the given browser.
- */
-+ (NSString *)nameForBrowser:(CDZBrowser)browser;
-
-@end
@@ -1,107 +0,0 @@
-#import "CDZLinkOpenManager.h"
-
-static NSString *kCDZBrowserPrefsKey = @"BVMBrowserPrefsKey"; // "BVM" for historical reasons
-
-static NSString *kCDZBrowserNames[CDZNumBrowsers];
-static NSURL *kCDZBrowserTestURLs[CDZNumBrowsers];
-
-__attribute__((constructor)) static void __CDZBrowserConstantsInit(void)
-{
- @autoreleasepool {
- kCDZBrowserNames[CDZBrowserSafari] = NSLocalizedString(@"Safari", nil);
- kCDZBrowserNames[CDZBrowserOnePassword] = NSLocalizedString(@"1Password", nil);
- kCDZBrowserNames[CDZBrowserChrome] = NSLocalizedString(@"Google Chrome", nil);
-
- kCDZBrowserTestURLs[CDZBrowserSafari] = [NSURL URLWithString:@"http://google.com"];
- kCDZBrowserTestURLs[CDZBrowserChrome] = [NSURL URLWithString:@"googlechrome://google.com"];
- kCDZBrowserTestURLs[CDZBrowserOnePassword] = [NSURL URLWithString:@"onepassword://search"];
- }
-}
-
-@implementation CDZLinkOpenManager
-
-#pragma mark Browser availability
-
-+ (BOOL)browserAvailable:(CDZBrowser)browser
-{
- if (browser >= CDZNumBrowsers || browser < 0) {
- NSLog(@"Unknown browser %d in %s", browser, __PRETTY_FUNCTION__);
- return NO;
- }
-
- NSURL *testURL = kCDZBrowserTestURLs[browser];
- return [[UIApplication sharedApplication] canOpenURL:testURL];
-}
-
-#pragma mark Default browser management
-
-+ (CDZBrowser)selectedBrowser {
- // note: if not set, this falls back to 0 == CDZBrowserSafari
- return [[NSUserDefaults standardUserDefaults] integerForKey:kCDZBrowserPrefsKey];
-}
-
-+ (void)setSelectedBrowser:(CDZBrowser)browser
-{
- NSParameterAssert(browser >= 0 && browser < CDZNumBrowsers);
-
- [[NSUserDefaults standardUserDefaults] setInteger:browser forKey:kCDZBrowserPrefsKey];
-}
-
-#pragma mark URL Actions
-
-+ (void)openURL:(NSURL *)url
-{
- NSString *replacementScheme = [CDZLinkOpenManager replacementSchemeForScheme:url.scheme];
-
- if (replacementScheme) {
- // https://developers.google.com/chrome/mobile/docs/ios-links
- NSString *absoluteString = [url absoluteString];
- NSRange rangeForScheme = [absoluteString rangeOfString:@":"];
- NSString *urlNoScheme = [absoluteString substringFromIndex:rangeForScheme.location];
- NSString *replacedURLString = [replacementScheme stringByAppendingString:urlNoScheme];
- url = [NSURL URLWithString:replacedURLString];
- }
-
- [[UIApplication sharedApplication] openURL:url];
-}
-
-+ (void)openURLString:(NSString *)urlString
-{
- [CDZLinkOpenManager openURL:[NSURL URLWithString:urlString]];
-}
-
-+ (NSString *)replacementSchemeForScheme:(NSString *)scheme
-{
- NSString *urlScheme = [scheme lowercaseString];
- NSString *replacementScheme = nil;
-
- CDZBrowser selectedBrowser = [CDZLinkOpenManager selectedBrowser];
- if (selectedBrowser == CDZBrowserSafari) return nil;
-
- if (selectedBrowser == CDZBrowserChrome && ![CDZLinkOpenManager browserAvailable:CDZBrowserChrome]) return nil;
- if (selectedBrowser == CDZBrowserOnePassword && ![CDZLinkOpenManager browserAvailable:CDZBrowserOnePassword]) return nil;
-
- if ([urlScheme isEqualToString:@"http"]) {
- if (selectedBrowser == CDZBrowserOnePassword) replacementScheme = @"ophttp";
- else if (selectedBrowser == CDZBrowserChrome) replacementScheme = @"googlechrome";
- } else if ([urlScheme isEqualToString:@"https"]) {
- if (selectedBrowser == CDZBrowserOnePassword) replacementScheme = @"ophttps";
- else if (selectedBrowser == CDZBrowserChrome) replacementScheme = @"googlechromes";
- }
-
- return replacementScheme;
-}
-
-#pragma mark UI/Naming
-
-+ (NSString *)nameForBrowser:(CDZBrowser)browser
-{
- if (browser >= CDZNumBrowsers || browser < 0) {
- NSLog(@"Unknown browser %d in %s", browser, __PRETTY_FUNCTION__);
- return nil;
- }
-
- return kCDZBrowserNames[browser];
-}
-
-@end

0 comments on commit e4c36ec

Please sign in to comment.