Skip to content

Commit

Permalink
added reachability check to http://github.com and error view
Browse files Browse the repository at this point in the history
  • Loading branch information
sschroed committed Jan 17, 2009
1 parent f327036 commit 7b1536e
Show file tree
Hide file tree
Showing 10 changed files with 385 additions and 2 deletions.
238 changes: 238 additions & 0 deletions ApplicationError.xib
@@ -0,0 +1,238 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.03">
<data>
<int key="IBDocument.SystemTarget">528</int>
<string key="IBDocument.SystemVersion">9G55</string>
<string key="IBDocument.InterfaceBuilderVersion">677</string>
<string key="IBDocument.AppKitVersion">949.43</string>
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="33"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
<object class="NSMutableDictionary" key="IBDocument.Metadata">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
</object>
<object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBProxyObject" id="372490531">
<string key="IBProxiedObjectIdentifier">IBFilesOwner</string>
</object>
<object class="IBProxyObject" id="975951072">
<string key="IBProxiedObjectIdentifier">IBFirstResponder</string>
</object>
<object class="IBUIView" id="191373211">
<reference key="NSNextResponder"/>
<int key="NSvFlags">292</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBUIImageView" id="523286871">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">274</int>
<string key="NSFrame">{{26, 50}, {266, 204}}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<int key="IBUIContentMode">4</int>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<object class="NSCustomResource" key="IBUIImage">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">octocat_sad.png</string>
</object>
</object>
<object class="IBUILabel" id="268771180">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{101, 268}, {115, 23}}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="IBUIText">Octocat is sad.</string>
<object class="NSColor" key="IBUITextColor" id="361346917">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MCAwIDAAA</bytes>
</object>
<nil key="IBUIHighlightedColor"/>
<int key="IBUIBaselineAdjustment">1</int>
<float key="IBUIMinimumFontSize">1.000000e+01</float>
</object>
<object class="IBUITextView" id="667860017">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{19, 324}, {280, 79}}</string>
<reference key="NSSuperview" ref="191373211"/>
<object class="NSColor" key="IBUIBackgroundColor" id="655035782">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDEAA</bytes>
</object>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<bool key="IBUIBounces">NO</bool>
<bool key="IBUIScrollEnabled">NO</bool>
<bool key="IBUIShowsHorizontalScrollIndicator">NO</bool>
<bool key="IBUIShowsVerticalScrollIndicator">NO</bool>
<bool key="IBUIDelaysContentTouches">NO</bool>
<bool key="IBUICanCancelContentTouches">NO</bool>
<bool key="IBUIBouncesZoom">NO</bool>
<string key="IBUIText">Error Message</string>
<reference key="IBUITextColor" ref="361346917"/>
<int key="IBUITextAlignment">1</int>
</object>
</object>
<string key="NSFrameSize">{320, 480}</string>
<reference key="NSSuperview"/>
<reference key="IBUIBackgroundColor" ref="655035782"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIUserInteractionEnabled">NO</bool>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">view</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="191373211"/>
</object>
<int key="connectionID">39</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">errorMessageTextView</string>
<reference key="source" ref="372490531"/>
<reference key="destination" ref="667860017"/>
</object>
<int key="connectionID">43</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBObjectRecord">
<int key="objectID">0</int>
<object class="NSArray" key="object" id="360949347">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<reference key="children" ref="1000"/>
<nil key="parent"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">-1</int>
<reference key="object" ref="372490531"/>
<reference key="parent" ref="360949347"/>
<string type="base64-UTF8" key="objectName">RmlsZSdzIE93bmVyA</string>
</object>
<object class="IBObjectRecord">
<int key="objectID">-2</int>
<reference key="object" ref="975951072"/>
<reference key="parent" ref="360949347"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">33</int>
<reference key="object" ref="191373211"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="268771180"/>
<reference ref="523286871"/>
<reference ref="667860017"/>
</object>
<reference key="parent" ref="360949347"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">34</int>
<reference key="object" ref="523286871"/>
<reference key="parent" ref="191373211"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">35</int>
<reference key="object" ref="268771180"/>
<reference key="parent" ref="191373211"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">42</int>
<reference key="object" ref="667860017"/>
<reference key="parent" ref="191373211"/>
<string key="objectName">Error Message Text View</string>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMutableArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>-1.CustomClassName</string>
<string>-2.CustomClassName</string>
<string>33.IBEditorWindowLastContentRect</string>
<string>33.IBPluginDependency</string>
<string>34.IBPluginDependency</string>
<string>35.IBPluginDependency</string>
<string>42.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>ApplicationErrorViewController</string>
<string>UIResponder</string>
<string>{{284, 157}, {320, 480}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
</object>
<nil key="activeLocalization"/>
<object class="NSMutableDictionary" key="localizations">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">43</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">ApplicationErrorViewController</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="outlets">
<string key="NS.key.0">errorMessageTextView</string>
<string key="NS.object.0">UITextView</string>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">Classes/ApplicationErrorViewController.h</string>
</object>
</object>
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.LastKnownRelativeProjectPath">git-phone.xcodeproj</string>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
</data>
</archive>
19 changes: 19 additions & 0 deletions Classes/ApplicationErrorViewController.h
@@ -0,0 +1,19 @@
//
// ApplicationErrorViewController.h
// git-phone
//
// Created by Sam Schroeder on 1/17/09.
// Copyright 2009 Proton Microsystems, LLC. All rights reserved.
//

@interface ApplicationErrorViewController : UIViewController {
NSString *errorMessage;
UITextView *errorMessageTextView;
}

@property (nonatomic, retain) IBOutlet UITextView *errorMessageTextView;

- (void) setErrorMessage:(NSString *)error;


@end
33 changes: 33 additions & 0 deletions Classes/ApplicationErrorViewController.m
@@ -0,0 +1,33 @@
//
// ApplicationErrorViewController.m
// git-phone
//
// Created by Sam Schroeder on 1/17/09.
// Copyright 2009 Proton Microsystems, LLC. All rights reserved.
//

#import "ApplicationErrorViewController.h"


@implementation ApplicationErrorViewController
@synthesize errorMessageTextView;


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[errorMessageTextView setFont:[UIFont systemFontOfSize:12.0]];
[errorMessageTextView setText:errorMessage == nil ? @"An unknown error has occurred." : errorMessage];
}

- (void) setErrorMessage:(NSString *)error {
errorMessage = [error copy];
}

- (void)dealloc {
[errorMessage release];
[errorMessageTextView release];
[super dealloc];
}

@end
2 changes: 2 additions & 0 deletions Classes/Config.h
Expand Up @@ -11,9 +11,11 @@

@interface Config : NSObject {
NSString *gitHubUserName;
NSString *baseURL;
}

@property (copy) NSString *gitHubUserName;
@property (copy) NSString *baseURL;

+ (Config *)instance;

Expand Down
2 changes: 2 additions & 0 deletions Classes/Config.m
Expand Up @@ -12,6 +12,7 @@
@implementation Config

@synthesize gitHubUserName;
@synthesize baseURL;

// Make model a singleton
+ (Config *)instance
Expand All @@ -28,6 +29,7 @@ + (Config *)instance

- (void) dealloc {
[gitHubUserName release];
[baseURL release];
[super dealloc];
}

Expand Down
15 changes: 15 additions & 0 deletions Classes/ConnectivityController.h
@@ -0,0 +1,15 @@
//
// ConnectivityController.h
// git-phone
//
// Created by Sam Schroeder on 1/17/09.
// Copyright 2009 Proton Microsystems, LLC. All rights reserved.
//

#import "Reachability.h"

@interface ConnectivityController : NSObject

+ (BOOL)isGitHubWebServiceReachable:(NSString *)url;

@end
19 changes: 19 additions & 0 deletions Classes/ConnectivityController.m
@@ -0,0 +1,19 @@
//
// ConnectivityController.m
// git-phone
//
// Created by Sam Schroeder on 1/17/09.
// Copyright 2009 Proton Microsystems, LLC. All rights reserved.
//

#import "ConnectivityController.h"

@implementation ConnectivityController


+ (BOOL)isGitHubWebServiceReachable:(NSString *)url {
[[Reachability sharedReachability] setHostName:[[NSURL URLWithString:url] host]];
return [[Reachability sharedReachability] remoteHostStatus] != NotReachable;
}

@end
17 changes: 17 additions & 0 deletions Classes/git_phoneAppDelegate.m
Expand Up @@ -8,8 +8,13 @@

#import "git_phoneAppDelegate.h"
#import "RootViewController.h"
#import "ConnectivityController.h"
#import "ApplicationErrorViewController.h"
#import "Models.h"

@interface git_phoneAppDelegate()
- (void) showError:(NSString *)errorMessage;
@end

@implementation git_phoneAppDelegate

Expand Down Expand Up @@ -37,6 +42,13 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];

// Ensure we have connectivity.
[[Config instance] setBaseURL:@"http://github.com"];
if(![ConnectivityController isGitHubWebServiceReachable:[[Config instance] baseURL]]) {
[self showError:@"Octocat cannot connect to GitHub."];
return;
}

[self loadPreferencess];
}

Expand All @@ -45,6 +57,11 @@ - (void)applicationWillTerminate:(UIApplication *)application {
// Save data if appropriate
}

- (void) showError:(NSString *)errorMessage {
ApplicationErrorViewController *errorController = [[ApplicationErrorViewController alloc] initWithNibName:@"ApplicationError" bundle:nil];
[errorController setErrorMessage:errorMessage];
[[self window] addSubview:errorController.view];
}

- (void)dealloc {
[navigationController release];
Expand Down

0 comments on commit 7b1536e

Please sign in to comment.