Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-11178]Implementation for Autopause API. #3963

Merged
merged 3 commits into from
Mar 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
126 changes: 125 additions & 1 deletion apidoc/Titanium/Geolocation/Geolocation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ description: |
* [ACCURACY_KILOMETER](Titanium.Geolocation.ACCURACY_KILOMETER)
* [ACCURACY_LOW](Titanium.Geolocation.ACCURACY_LOW)
* [ACCURACY_THREE_KILOMETERS](Titanium.Geolocation.ACCURACY_THREE_KILOMETERS) (lowest
accuracy and power consumption).
accuracy and power consumption).
* [ACCURACY_BEST_FOR_NAVIGATION](Titanium.Geolocation.ACCURACY_BEST_FOR_NAVIGATION)
(Available in iOS 6.0 and above)

Based on the accuracy you choose, iOS uses its own logic to select location providers
and filter location updates to provide location updates that meet your accuracy
Expand Down Expand Up @@ -281,6 +283,25 @@ events:
summary: If `success` is false, a string describing the error.
type: String

- name: locationupdatepaused
summary: Fired when location updates are paused by the OS. Available in iOS 6.0 and later.
description: |
This event is fired when [pauseLocationUpdateAutomatically](Titanium.Geolocation.pauseLocationUpdateAutomatically)
is set to `true` and if the OS detects that the device's location is not changing,
causing it to pause the delivery of updates in order to shut down the appropriate
hardware and save power.
platforms: [iphone, ipad]
since: "3.1.0"

- name: locationupdateresumed
summary: Fired when location manager is resumed by the OS. Available in iOS 6.0 and later.
description: |
When location updates are paused and need to be resumed (perhaps because the user
is moving again), this event is fired to let the app know that it is about to
begin the delivery of those updates again.
platforms: [iphone, ipad]
since: "3.1.0"

properties:

- name: ACCURACY_BEST
Expand Down Expand Up @@ -351,6 +372,20 @@ properties:
permission: read-only
platforms: [android, iphone, ipad, mobileweb]
since: "2.0.0"

- name: ACCURACY_BEST_FOR_NAVIGATION
summary: |
Use with [accuracy](Titanium.Geolocation.accuracy) to request highest possible
accuracy and combine it with additional sensor data.
description: |
Using this value is intended for use in navigation applications that require
precise position information at all times and are intended to be used only while
the device is plugged in.
type: Number
permission: read-only
platforms: [iphone, ipad]
since: "3.1.0"


- name: ACCURACY_LOW
summary: |
Expand Down Expand Up @@ -500,6 +535,53 @@ properties:
permission: read-only
platforms: [android]

- name: ACTIVITYTYPE_OTHER
summary: The location data is being used for an unknown activity.
description: |
Used with [activityType](Titanium.Geolocation.activityType). Available in iOS 6.0 and later.
type: String
permission: read-only
platforms: [iphone,ipad]
since: "3.1.0"

- name: ACTIVITYTYPE_AUTOMOTIVE_NAVIGATION
summary: The location data is used for tracking location changes to the automobile specifically during vehicular navigation.
description: |
Used with [activityType](Titanium.Geolocation.activityType). This activity might
cause location updates to be paused only when the vehicle does not move for an
extended period of time. Available in iOS 6.0 and later.
type: String
permission: read-only
platforms: [iphone,ipad]
since: "3.1.0"

- name: ACTIVITYTYPE_FITNESS
summary: The location data is used for tracking any pedestrian-related activity.
description: |
Used with [activityType](Titanium.Geolocation.activityType). This activity might
cause location updates to be paused only when the user does not move a significant
distance over a period of time.Available in iOS 6.0 and later.
type: String
permission: read-only
platforms: [iphone,ipad]
since: "3.1.0"

- name: ACTIVITYTYPE_OTHER_NAVIGATION
summary: |
The location data is used for tracking movements of other types of vehicular
navigation that are not automobile related.
description: |
Used with [activityType](Titanium.Geolocation.activityType). You would use this
to track navigation by boat, train, or plane. Do not use this type for pedestrian
navigation tracking. This activity might cause location updates to be paused only
when the vehicle does not move a significant distance over a period of time.
Available in iOS 6.0 and later.
type: String
permission: read-only
platforms: [iphone,ipad]
since: "3.1.0"


- name: accuracy
summary: Specifies the requested accuracy for location updates.
description: |
Expand Down Expand Up @@ -652,6 +734,48 @@ properties:
platforms: [iphone, ipad]
since: "2.1.2"

- name: activityType
summary: |
The type of user activity to be associated with the location updates. Available in iOS 6.0 and later.
description: |
Set the activiyType of location updates to either:

* [ACTIVITYTYPE_OTHER](Titanium.Geolocation.ACTIVITYTYPE_OTHER) for an unknown activity
* [ACTIVITYTYPE_AUTOMOTIVE_NAVIGATION](Titanium.Geolocation.ACTIVITYTYPE_AUTOMOTIVE_NAVIGATION)
for tracking location changes to the automobile specifically during vehicular navigation.
* [ACTIVITYTYPE_FITNESS](Titanium.Geolocation.ACTIVITYTYPE_FITNESS) for tracking
any pedestrian-related activity.
* [ACTIVITYTYPE_OTHER_NAVIGATION](Titanium.Geolocation.ACTIVITYTYPE_OTHER_NAVIGATION)
for tracking movements of other types of vehicular navigation that are not
automobile related.

The information in this property is used as a cue to determine when location
updates may be automatically paused. Pausing updates gives the system the
opportunity to save power in situations where the user's location is not likely
to be changing. For example, if the activity type is
[ACTIVITYTYPE_AUTOMOTIVE_NAVIGATION](Titanium.Geolocation.ACTIVITYTYPE_AUTOMOTIVE_NAVIGATION)
and no location changes have occurred recently, the radios might be powered down
until movement is detected again.
type: Number
default: <Titanium.Geolocation.ACTIVITYTYPE_OTHER>
since: "3.1.0"
platforms: [iphone,ipad]

- name: pauseLocationUpdateAutomatically
summary: Indicates whether the location updates may be paused. Available in iOS 6.0 and later.
description: |
Allowing the location updates to be paused can improve battery life on the
target device without sacrificing location data. When this property is set to YES,
the location updates are paused (and powers down the appropriate hardware) at
times when the location data is unlikely to change. For example, if the user stops
for food while using a navigation app, the location manager might pause updates for
a period of time. You can help the determination of when to pause location updates
by assigning a value to the [activityType](Titanium.Geolocation.activityType) property.
type: Boolean
default: false
platforms: [iphone,ipad]
since: "3.1.0"

---
name: LocationResults
summary: |
Expand Down
19 changes: 19 additions & 0 deletions iphone/Classes/GeolocationModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
BOOL trackingHeading;
BOOL trackingLocation;
BOOL trackSignificantLocationChange;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
CLActivityType activityType;
BOOL pauseLocationUpdateAutomatically;
#endif

NSRecursiveLock* lock;
}
Expand All @@ -37,6 +41,10 @@
@property(nonatomic,readonly) NSNumber *locationServicesEnabled;
@property(nonatomic,readonly) NSNumber* locationServicesAuthorization;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
@property(nonatomic,readwrite,assign) NSNumber *activityType;
#endif

// Error codes
@property(nonatomic, readonly) NSNumber* ERROR_LOCATION_UNKNOWN;
@property(nonatomic, readonly) NSNumber* ERROR_DENIED;
Expand All @@ -57,6 +65,7 @@
@property(nonatomic,readonly) NSNumber *ACCURACY_KILOMETER;
@property(nonatomic,readonly) NSNumber *ACCURACY_LOW;
@property(nonatomic,readonly) NSNumber *ACCURACY_THREE_KILOMETERS;
@property(nonatomic,readonly) NSNumber *ACCURACY_BEST_FOR_NAVIGATION; //Since 3.1.0

// Authorization to use location, 4.2+ only
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_2
Expand All @@ -66,6 +75,16 @@
#endif
@property(nonatomic,readonly) NSNumber* AUTHORIZATION_UNKNOWN; // We still need the 'authorization unknown' constant, though.


// To specify the geolocation activity type
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
@property(nonatomic,readonly) NSNumber* ACTIVITYTYPE_OTHER;// default
@property(nonatomic,readonly) NSNumber* ACTIVITYTYPE_AUTOMOTIVE_NAVIGATION;// for automotive navigation
@property(nonatomic,readonly) NSNumber* ACTIVITYTYPE_FITNESS;// includes any pedestrian activities
@property(nonatomic,readonly) NSNumber* ACTIVITYTYPE_OTHER_NAVIGATION;// for other navigation cases (excluding pedestrian navigation), e.g. navigation for boats, trains or planes.
#endif


@end

#endif
81 changes: 81 additions & 0 deletions iphone/Classes/GeolocationModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ -(void)_configure

// track all location changes by default
trackSignificantLocationChange = NO;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
if ([TiUtils isIOS6OrGreater]) {
// activity Type by default
activityType = CLActivityTypeOther;

// pauseLocationupdateAutomatically by default NO
pauseLocationUpdateAutomatically = NO;

}
#endif

lock = [[NSRecursiveLock alloc] init];

Expand Down Expand Up @@ -289,6 +300,14 @@ -(CLLocationManager*)locationManager
[locationManager setPurpose:purpose];
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
if ([TiUtils isIOS6OrGreater]) {
locationManager.activityType = activityType;
locationManager.pausesLocationUpdatesAutomatically = pauseLocationUpdateAutomatically;

}
#endif

if ([CLLocationManager locationServicesEnabled]== NO)
{
//NOTE: this is from Apple example from LocateMe and it works well. the developer can still check for the
Expand Down Expand Up @@ -662,6 +681,39 @@ -(void)setTrackSignificantLocationChange:(id)value
}
}

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
// Activity Type for CLlocationManager.
-(NSNumber*)activityType
{
return NUMINT(activityType);
}

-(void)setActivityType:(NSNumber *)value
{
if ([TiUtils isIOS6OrGreater]) {
activityType = [TiUtils intValue:value];
TiThreadPerformOnMainThread(^{[locationManager setActivityType:accuracy];}, NO);
}

}

// Flag to decide whether or not the app should continue to send location updates while the app is in background.

-(NSNumber*)pauseLocationUpdateAutomatically
{
return NUMBOOL(pauseLocationUpdateAutomatically);
}

-(void)setPauseLocationUpdateAutomatically:(id)value
{
if ([TiUtils isIOS6OrGreater]) {
pauseLocationUpdateAutomatically = [TiUtils boolValue:value];
TiThreadPerformOnMainThread(^{[locationManager setPausesLocationUpdatesAutomatically:pauseLocationUpdateAutomatically];}, NO);
}
}
#endif


-(void)restart:(id)arg
{
[lock lock];
Expand All @@ -680,6 +732,7 @@ -(void)restart:(id)arg
MAKE_SYSTEM_PROP_DBL(ACCURACY_KILOMETER,kCLLocationAccuracyKilometer);
MAKE_SYSTEM_PROP_DBL(ACCURACY_THREE_KILOMETERS,kCLLocationAccuracyThreeKilometers);
MAKE_SYSTEM_PROP_DBL(ACCURACY_LOW, kCLLocationAccuracyThreeKilometers);
MAKE_SYSTEM_PROP(ACCURACY_BEST_FOR_NAVIGATION, kCLLocationAccuracyBestForNavigation);//Since 2.1.3

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_2
MAKE_SYSTEM_PROP(AUTHORIZATION_UNKNOWN, kCLAuthorizationStatusNotDetermined);
Expand All @@ -700,6 +753,13 @@ -(void)restart:(id)arg
MAKE_SYSTEM_PROP(ERROR_REGION_MONITORING_FAILURE, kCLErrorRegionMonitoringFailure);
MAKE_SYSTEM_PROP(ERROR_REGION_MONITORING_DELAYED, kCLErrorRegionMonitoringSetupDelayed);

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
MAKE_SYSTEM_PROP(ACTIVITYTYPE_OTHER, CLActivityTypeOther);
MAKE_SYSTEM_PROP(ACTIVITYTYPE_AUTOMOTIVE_NAVIGATION, CLActivityTypeAutomotiveNavigation);
MAKE_SYSTEM_PROP(ACTIVITYTYPE_FITNESS, CLActivityTypeFitness);
MAKE_SYSTEM_PROP(ACTIVITYTYPE_OTHER_NAVIGATION, CLActivityTypeOtherNavigation);
#endif

#pragma mark Internal

-(NSDictionary*)locationDictionary:(CLLocation*)newLocation;
Expand Down Expand Up @@ -827,6 +887,27 @@ -(void)fireApplicationAnalyticsIfNeeded:(NSArray *)locations{

#pragma mark Delegates

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0

- (void)locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager
{
if ([self _hasListeners:@"locationupdatepaused"])
{
[self fireEvent:@"locationupdatepaused" withObject:nil];
}
}

- (void)locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager
{
if ([self _hasListeners:@"locationupdateresumed"])
{
[self fireEvent:@"locationupdateresumed" withObject:nil];
}
}

#endif


//Using new delegate instead of the old deprecated method - (void)locationManager:didUpdateToLocation:fromLocation:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
Expand Down