From c38e1a55e6a889e7f483567e9fea41e83cf56894 Mon Sep 17 00:00:00 2001 From: Moses Gunesch Date: Tue, 21 Apr 2015 13:31:10 -0700 Subject: [PATCH 1/5] UUProgressView animated:NO support --- UUProgressView.m | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/UUProgressView.m b/UUProgressView.m index 0bace96..c84db6c 100644 --- a/UUProgressView.m +++ b/UUProgressView.m @@ -147,12 +147,24 @@ - (void) updateMessage:(NSString*)message - (void) show:(BOOL)animated { - [self showProgressViewWithBounceAnimation]; + if (animated) { + [self showProgressViewWithBounceAnimation]; + } + else { + [self.layer removeAllAnimations]; + self.transform = CGAffineTransformIdentity; + self.hidden = NO; + } } - (void) hide:(BOOL)animated { - [self hideProgressViewWithBounceAnimation]; + if (animated) { + [self hideProgressViewWithBounceAnimation]; + } + else { + self.hidden = YES; + } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////// From 3e7caad68501dc34bb3e02c935edd0db927c88a0 Mon Sep 17 00:00:00 2001 From: mosesoak Date: Thu, 7 May 2015 13:10:36 -0700 Subject: [PATCH 2/5] UULocationMonitoringConfiguration requestStartWhenInUseTracking method --- UULocation.h | 1 + UULocation.m | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/UULocation.h b/UULocation.h index da9b58c..bdf6bd3 100644 --- a/UULocation.h +++ b/UULocation.h @@ -45,6 +45,7 @@ + (BOOL) isTrackingDenied; + (void) requestStartTracking:(void(^)(BOOL authorized))callback; + + (void)requestStartWhenInUseTracking:(void (^)(BOOL))callback; + (void) requestStopTracking; + (void) startTrackingSignificantLocationChanges; + (void) stopTrackingSignficantLocationChanges; diff --git a/UULocation.m b/UULocation.m index 8749fc9..8a0d656 100644 --- a/UULocation.m +++ b/UULocation.m @@ -116,16 +116,29 @@ + (BOOL) isAuthorizedToTrack } + (void) requestStartTracking:(void(^)(BOOL authorized))callback +{ + [self requestTrackingWithSelector:@selector(requestAlwaysAuthorization) callback:callback]; +} + ++ (void)requestStartWhenInUseTracking:(void (^)(BOOL))callback +{ + [self requestTrackingWithSelector:@selector(requestWhenInUseAuthorization) callback:callback]; +} + ++ (void)requestTrackingWithSelector:(SEL)selector callback:(void (^)(BOOL))callback { [UUSystemLocation sharedLocation].authorizationCallback = callback; CLLocationManager* locationManager = [UUSystemLocation sharedLocation].clLocationManager; - if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) + if ([locationManager respondsToSelector:selector]) { NSString* usageDescription = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]; NSAssert(usageDescription != nil, @"You must set a description in your plist for NSLocationAlwaysUsageDescription"); - [locationManager performSelector:@selector(requestAlwaysAuthorization)]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" + [locationManager performSelector:selector]; +#pragma clang diagnostic pop } else { From 4ab474ad6b651925419c2b6e1ee23c4a6e81ef69 Mon Sep 17 00:00:00 2001 From: mosesoak Date: Fri, 15 May 2015 13:19:03 -0700 Subject: [PATCH 3/5] UULocation improvements --- UULocation.h | 1 + UULocation.m | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/UULocation.h b/UULocation.h index bdf6bd3..eca1ffa 100644 --- a/UULocation.h +++ b/UULocation.h @@ -43,6 +43,7 @@ //Global settings interface. + (BOOL) isAuthorizedToTrack; + (BOOL) isTrackingDenied; + + (BOOL) canRequestTracking; // Returns NO if status is anything but kCLAuthorizationStatusNotDetermined, which will result in nothing happening when tracking is requested + (void) requestStartTracking:(void(^)(BOOL authorized))callback; + (void)requestStartWhenInUseTracking:(void (^)(BOOL))callback; diff --git a/UULocation.m b/UULocation.m index 8a0d656..c426360 100644 --- a/UULocation.m +++ b/UULocation.m @@ -110,9 +110,14 @@ + (BOOL) isTrackingDenied return [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied; } ++ (BOOL) canRequestTracking +{ + return [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined; +} + + (BOOL) isAuthorizedToTrack { - return ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways)); + return ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse)); } + (void) requestStartTracking:(void(^)(BOOL authorized))callback @@ -331,10 +336,12 @@ - (void) checkForNewLocation:(CLLocation*)reportedLocation - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { - if (self.authorizationCallback && (status != kCLAuthorizationStatusNotDetermined)) + if (status != kCLAuthorizationStatusNotDetermined && status != kCLAuthorizationStatusDenied) { [self startTracking]; - self.authorizationCallback(status == kCLAuthorizationStatusAuthorizedAlways); + } + if (self.authorizationCallback != nil) { + self.authorizationCallback(status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse); } } From 45077f38c4f98b57f56c4a0dd45ef4d1067c52a5 Mon Sep 17 00:00:00 2001 From: mosesoak Date: Mon, 18 May 2015 15:46:17 -0700 Subject: [PATCH 4/5] Change to UULocation monitoring: expose startTracking method to make it possible to start either full location monitoring or significantLocationChange monitoring independently. (Requires developer to call startTracking once requested and approved by user.) --- UULocation.h | 5 +++-- UULocation.m | 34 ++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/UULocation.h b/UULocation.h index eca1ffa..de1f4c6 100644 --- a/UULocation.h +++ b/UULocation.h @@ -46,9 +46,10 @@ + (BOOL) canRequestTracking; // Returns NO if status is anything but kCLAuthorizationStatusNotDetermined, which will result in nothing happening when tracking is requested + (void) requestStartTracking:(void(^)(BOOL authorized))callback; - + (void)requestStartWhenInUseTracking:(void (^)(BOOL))callback; + + (void) requestStartWhenInUseTracking:(void (^)(BOOL))callback; + + (void) startTracking; // You should call this in your requestStartTracking handler (or when isAuthorizedToTrack) to turn on full location monitoring (heavy battery use) + (void) requestStopTracking; - + (void) startTrackingSignificantLocationChanges; + + (void) startTrackingSignificantLocationChanges; // You should call this in your requestStartTracking handler (or when isAuthorizedToTrack) to turn on sporadic location monitoring (light battery use) + (void) stopTrackingSignficantLocationChanges; + (CLLocationDistance) distanceThreshold; diff --git a/UULocation.m b/UULocation.m index c426360..a1d6f86 100644 --- a/UULocation.m +++ b/UULocation.m @@ -151,6 +151,11 @@ + (void)requestTrackingWithSelector:(SEL)selector callback:(void (^)(BOOL))callb } } ++ (void) startTracking +{ + [[UUSystemLocation sharedLocation] startTracking]; +} + + (void) requestStopTracking { [[UUSystemLocation sharedLocation] stopTracking]; @@ -262,11 +267,14 @@ - (id) init - (void) startTracking { - [self.clLocationManager startUpdatingLocation]; - - if (self.clLocationManager.location) + if ([UULocationMonitoringConfiguration isAuthorizedToTrack]) { - [self checkForNewLocation:self.clLocationManager.location]; + [self.clLocationManager startUpdatingLocation]; + + if (self.clLocationManager.location) + { + [self checkForNewLocation:self.clLocationManager.location]; + } } } @@ -277,7 +285,10 @@ - (void) stopTracking - (void) startTrackingSignificantLocationChanges { - [self.clLocationManager startMonitoringSignificantLocationChanges]; + if ([UULocationMonitoringConfiguration isAuthorizedToTrack]) + { + [self.clLocationManager startMonitoringSignificantLocationChanges]; + } } - (void) stopTrackingSignificantLocationChanges @@ -336,12 +347,9 @@ - (void) checkForNewLocation:(CLLocation*)reportedLocation - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { - if (status != kCLAuthorizationStatusNotDetermined && status != kCLAuthorizationStatusDenied) - { - [self startTracking]; - } if (self.authorizationCallback != nil) { self.authorizationCallback(status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse); + self.authorizationCallback = nil; } } @@ -350,7 +358,7 @@ - (BOOL) shouldUseLocationUpdate:(CLLocation*)reportedLocation if (!self.lastReportedLocation || //!CLLocationCoordinate2DIsValid(self.clLocation.coordinate) || [self.lastReportedLocation.clLocation distanceFromLocation:reportedLocation] > self.distanceThreshold || - [self.lastReportedLocation.clLocation.timestamp timeIntervalSinceDate:reportedLocation.timestamp] > self.timeThreshold || + [self.lastReportedLocation.clLocation.timestamp timeIntervalSinceDate:reportedLocation.timestamp] * -1.0 > self.timeThreshold || reportedLocation.horizontalAccuracy < self.lastReportedLocation.clLocation.horizontalAccuracy) { return YES; @@ -359,6 +367,12 @@ - (BOOL) shouldUseLocationUpdate:(CLLocation*)reportedLocation return NO; } +- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations +{ + [self checkForNewLocation:[locations lastObject]]; +} + +// For iOS 6 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)reportedLocation fromLocation:(CLLocation *)oldLocation; { [self checkForNewLocation:reportedLocation]; From 7e1ec0ade92018ec0910f5135feb15d97cf9428e Mon Sep 17 00:00:00 2001 From: mosesoak Date: Tue, 26 May 2015 11:23:49 -0700 Subject: [PATCH 5/5] Makes UUProgressView block user interaction with the window while showing --- UUProgressView.m | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/UUProgressView.m b/UUProgressView.m index c84db6c..0055295 100644 --- a/UUProgressView.m +++ b/UUProgressView.m @@ -29,6 +29,7 @@ @interface UUProgressView () +@property (nonatomic, retain) UIView* scrimView; @property (nonatomic, retain) UIView* backgroundView; @property (nonatomic, retain) UILabel* label; @property (nonatomic, retain) UIActivityIndicatorView* spinner; @@ -59,7 +60,7 @@ + (UUProgressView*) globalProgressView if (theProgressView == nil) { theProgressView = [[UUProgressView alloc] initWithMessage:@"Loading..."]; - + UIView* parent = [[UIApplication sharedApplication] keyWindow]; theProgressView.center = parent.center; [parent addSubview:theProgressView]; @@ -78,6 +79,7 @@ - (id) initWithMessage:(NSString*)message if (self != nil) { + [self createScrimView]; [self createBackgroundView]; [self createSpinnerView]; [self createLabelView]; @@ -103,6 +105,14 @@ - (void) dealloc #endif } +- (void) createScrimView +{ + UIView* parent = [[UIApplication sharedApplication] keyWindow]; + self.scrimView = UU_AUTORELEASE([[UIView alloc] initWithFrame:parent.frame]); + self.backgroundView.backgroundColor = [UIColor clearColor]; + [parent addSubview:self.scrimView]; +} + - (void) createBackgroundView { self.backgroundView = UU_AUTORELEASE([[UIView alloc] initWithFrame:self.frame]); @@ -154,6 +164,7 @@ - (void) show:(BOOL)animated [self.layer removeAllAnimations]; self.transform = CGAffineTransformIdentity; self.hidden = NO; + self.scrimView.hidden = NO; } } @@ -164,6 +175,7 @@ - (void) hide:(BOOL)animated } else { self.hidden = YES; + self.scrimView.hidden = YES; } } @@ -175,6 +187,7 @@ - (void) showProgressViewWithBounceAnimation { self.transform = CGAffineTransformMakeScale(0.001, 0.001); self.hidden = NO; + self.scrimView.hidden = NO; [UIView animateWithDuration:0.2f delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^ { @@ -207,6 +220,7 @@ - (void) hideProgressViewWithBounceAnimation completion:^(BOOL finished) { self.hidden = YES; + self.scrimView.hidden = YES; }]; }