Permalink
Browse files

4.0 Compatibility changes

  • Loading branch information...
1 parent 54c0b54 commit 73683cb214c8e457b464e01d0e8631313dd4f283 @deepwinter committed Apr 30, 2012
@@ -96,6 +96,8 @@
F4AA3F4D14DA5B3E00ED3CCE /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4AA3F4C14DA5B3E00ED3CCE /* Security.framework */; };
F4AA3F4F14DA5B4A00ED3CCE /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F4AA3F4E14DA5B4A00ED3CCE /* libz.dylib */; };
F4AA3F5314DA5BBA00ED3CCE /* libstdc++.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F4AA3F5214DA5BBA00ED3CCE /* libstdc++.dylib */; };
+ F4C1734F154B698100A929E1 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = F4C1734E154B698100A929E1 /* Reachability.m */; };
+ F4C17352154B74FF00A929E1 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4C17351154B74FF00A929E1 /* SystemConfiguration.framework */; };
F4CE8858150C08A3009AE0FC /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4CE8857150C08A3009AE0FC /* CoreLocation.framework */; };
F4D3929414BBA6660051E831 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4D3929314BBA6660051E831 /* UIKit.framework */; };
F4D3929614BBA6660051E831 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F4D3929514BBA6660051E831 /* Foundation.framework */; };
@@ -234,6 +236,9 @@
F4AA3F4E14DA5B4A00ED3CCE /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
F4AA3F5214DA5BBA00ED3CCE /* libstdc++.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libstdc++.dylib"; path = "usr/lib/libstdc++.dylib"; sourceTree = SDKROOT; };
F4C0624514BE6D0A0008FBB5 /* GHUnitIOS.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GHUnitIOS.framework; path = "../../IphoneDevelopment/Libs/gh-unit/Project-iOS/build/Framework/GHUnitIOS.framework"; sourceTree = "<group>"; };
+ F4C1734D154B698100A929E1 /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = "<group>"; };
+ F4C1734E154B698100A929E1 /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Reachability.m; sourceTree = "<group>"; };
+ F4C17351154B74FF00A929E1 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks/SystemConfiguration.framework; sourceTree = DEVELOPER_DIR; };
F4CE8857150C08A3009AE0FC /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; };
F4D3928F14BBA6660051E831 /* Rhus.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Rhus.app; sourceTree = BUILT_PRODUCTS_DIR; };
F4D3929314BBA6660051E831 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
@@ -251,6 +256,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ F4C17352154B74FF00A929E1 /* SystemConfiguration.framework in Frameworks */,
F4CE8858150C08A3009AE0FC /* CoreLocation.framework in Frameworks */,
F4AA3F5314DA5BBA00ED3CCE /* libstdc++.dylib in Frameworks */,
F4AA3F4F14DA5B4A00ED3CCE /* libz.dylib in Frameworks */,
@@ -336,6 +342,7 @@
F414D9AF1549F325008A38F5 /* Source */ = {
isa = PBXGroup;
children = (
+ F4C1734C154B698100A929E1 /* Third Party */,
F414D9B01549F325008A38F5 /* Categories */,
F414D9B71549F325008A38F5 /* DataModels */,
F414D9C01549F325008A38F5 /* Maps */,
@@ -448,6 +455,15 @@
path = Settings;
sourceTree = "<group>";
};
+ F4C1734C154B698100A929E1 /* Third Party */ = {
+ isa = PBXGroup;
+ children = (
+ F4C1734D154B698100A929E1 /* Reachability.h */,
+ F4C1734E154B698100A929E1 /* Reachability.m */,
+ );
+ path = "Third Party";
+ sourceTree = "<group>";
+ };
F4CE8B30150C10AA009AE0FC /* Targets */ = {
isa = PBXGroup;
children = (
@@ -473,6 +489,7 @@
F4D3928414BBA6650051E831 = {
isa = PBXGroup;
children = (
+ F4C17351154B74FF00A929E1 /* SystemConfiguration.framework */,
F414DA3B1549F3D2008A38F5 /* Settings */,
F4CE8B30150C10AA009AE0FC /* Targets */,
A6A620D814BBBB670096CA01 /* Graphics */,
@@ -698,6 +715,7 @@
F414DA311549F325008A38F5 /* SwoopTabViewController.m in Sources */,
F414DA371549F325008A38F5 /* TimelineVisualizationView.m in Sources */,
F4F942A4154B25B00091279C /* RHSettings_Rhus.m in Sources */,
+ F4C1734F154B698100A929E1 /* Reachability.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -19,10 +19,13 @@ typedef void ( ^CompletedBlock )();
CouchPersistentReplication* _pull;
CouchPersistentReplication* _push;
CompletedBlock syncCompletedBlock;
+ BOOL syncStarted;
+ NSTimer * syncTimeoutTimer;
}
@property (nonatomic, strong) CouchDatabase *database;
@property (nonatomic, strong) CouchLiveQuery* query;
+@property (nonatomic, strong) NSTimer * syncTimeoutTimer;
- (id) initWithBlock: ( void ( ^ )() ) didStartBlock ;
@@ -24,6 +24,7 @@ + (id)instance
@synthesize database;
@synthesize query;
+@synthesize syncTimeoutTimer;
- (id) initWithBlock:( void ( ^ )() ) didStartBlock {
@@ -363,15 +364,39 @@ - (void)showAlert: (NSString*)message error: (NSError*)error fatal: (BOOL)fatal
}
+-(void)syncTimeout {
+ if(!syncStarted){
+ NSLog(@"Sync Timeout");
+
+ UIAlertView* alert = [[UIAlertView alloc] initWithTitle: @"No Sync"
+ message: @"Timed out while trying to sync, either there is nothing to sync or you aren't connected to the internet. Make sure you are connected to the internet and try again!"
+ delegate: nil
+ cancelButtonTitle: @"OK"
+ otherButtonTitles: nil];
+ [alert show];
+ [self forgetSync];
+ if(syncCompletedBlock){
+ syncCompletedBlock();
+ }
+ syncCompletedBlock = nil;
+ }
+}
+
- (void)updateSyncURL {
[self updateSyncURLWithCompletedBlock: nil];
}
+
- (void)updateSyncURLWithCompletedBlock: ( CompletedBlock ) setCompletedBlock {
+ //Should check for reachability of data.winterroot.net
+ //http://stackoverflow.com/questions/1083701/how-to-check-for-an-active-internet-connection-on-iphone-sdk
- NSInteger count = [self.database getDocumentCount];
+
+ //Test for network
+ NSInteger count = [self.database getDocumentCount];
+
if (!self.database){
NSLog(@"No Database in updateSyncURL");
return;
@@ -387,33 +412,49 @@ - (void)updateSyncURLWithCompletedBlock: ( CompletedBlock ) setCompletedBlock {
NSArray* repls = [self.database replicateWithURL: newRemoteURL exclusively: YES];
_pull = [repls objectAtIndex: 0];
_push = [repls objectAtIndex: 1];
- // _pull.filter = @"design/excludeDesignDocs";
- // _push.filter = @"rhusMobile/excludeDesignDocs";
+ //_pull.continuous = NO; //we might want these not to be continuous for user initialized replications
+ //_push.continuous = NO;
+ // _pull.filter = @"design/excludeDesignDocs";
+ // _push.filter = @"rhusMobile/excludeDesignDocs";
[_pull addObserver: self forKeyPath: @"completed" options: 0 context: NULL];
[_push addObserver: self forKeyPath: @"completed" options: 0 context: NULL];
- [_pull addObserver: self forKeyPath: @"state" options: 0 context: NULL];
- [_push addObserver: self forKeyPath: @"state" options: 0 context: NULL];
+
+
syncCompletedBlock = setCompletedBlock;
+ //set a timeout to detect when there are in fact no changes
+ //This is only relevant when sync is NOT continuous
+
+ /*NSInvocation * invocation = [[NSInvocation alloc] init];
+ [invocation setTarget:self];
+ [invocation setSelector:@selector(syncTimeout)];
+ syncStarted = FALSE;
+ self.syncTimeoutTimer = [NSTimer timerWithTimeInterval:5.0 invocation:invocation repeats:NO];
+ */
+ syncStarted = FALSE;
+ self.syncTimeoutTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(syncTimeout) userInfo:nil repeats:NO];
+
+
}
+
- (void) forgetSync {
[_pull removeObserver: self forKeyPath: @"completed"];
- [_pull removeObserver: self forKeyPath: @"state"];
_pull = nil;
[_push removeObserver: self forKeyPath: @"completed"];
- [_push removeObserver: self forKeyPath: @"state"];
_push = nil;
}
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
if (object == _pull || object == _push) {
+ syncStarted = TRUE;
+
unsigned completed = _pull.completed + _push.completed;
unsigned total = _pull.total + _push.total;
NSLog(@"SYNC progress: %u / %u", completed, total);
@@ -0,0 +1,93 @@
+/*
+ Copyright (c) 2011, Tony Million.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+#import <SystemConfiguration/SystemConfiguration.h>
+
+#import <sys/socket.h>
+#import <netinet/in.h>
+#import <netinet6/in6.h>
+#import <arpa/inet.h>
+#import <ifaddrs.h>
+#import <netdb.h>
+
+extern NSString *const kReachabilityChangedNotification;
+
+typedef enum
+{
+ // Apple NetworkStatus Compatible Names.
+ NotReachable = 0,
+ ReachableViaWiFi = 2,
+ ReachableViaWWAN = 1
+} NetworkStatus;
+
+@class Reachability;
+
+typedef void (^NetworkReachable)(Reachability * reachability);
+typedef void (^NetworkUnreachable)(Reachability * reachability);
+
+@interface Reachability : NSObject
+
+@property (nonatomic, copy) NetworkReachable reachableBlock;
+@property (nonatomic, copy) NetworkUnreachable unreachableBlock;
+
+@property (nonatomic, assign) SCNetworkReachabilityRef reachabilityRef;
+@property (nonatomic, assign) dispatch_queue_t reachabilitySerialQueue;
+
+@property (nonatomic, assign) BOOL reachableOnWWAN;
+
+@property (nonatomic, strong) id reachabilityObject;
+
++(Reachability*)reachabilityWithHostname:(NSString*)hostname;
++(Reachability*)reachabilityForInternetConnection;
++(Reachability*)reachabilityWithAddress:(const struct sockaddr_in*)hostAddress;
++(Reachability*)reachabilityForLocalWiFi;
+
+-(Reachability *)initWithReachabilityRef:(SCNetworkReachabilityRef)ref;
+
+-(BOOL)startNotifier;
+-(void)stopNotifier;
+
+-(BOOL)isReachable;
+-(BOOL)isReachableViaWWAN;
+-(BOOL)isReachableViaWiFi;
+
+// WWAN may be available, but not active until a connection has been established.
+// WiFi may require a connection for VPN on Demand.
+-(BOOL)isConnectionRequired; // Identical DDG variant.
+-(BOOL)connectionRequired; // Apple's routine.
+// Dynamic, on demand connection?
+-(BOOL)isConnectionOnDemand;
+// Is user intervention required?
+-(BOOL)isInterventionRequired;
+
+-(NetworkStatus)currentReachabilityStatus;
+-(SCNetworkReachabilityFlags)reachabilityFlags;
+-(NSString*)currentReachabilityString;
+-(NSString*)currentReachabilityFlags;
+
+@end
Oops, something went wrong.

0 comments on commit 73683cb

Please sign in to comment.