/
GeolocationModule.h
130 lines (110 loc) 路 5.19 KB
/
GeolocationModule.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* Titanium SDK
* Copyright TiDev, Inc. 04/07/2022-Present. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
#ifdef USE_TI_GEOLOCATION
#import <JavaScriptCore/JavaScriptCore.h>
#import <TitaniumKit/ObjcModule.h>
#import <CoreLocation/CoreLocation.h>
NSString *const kTiGeolocationUsageDescriptionWhenInUse = @"NSLocationWhenInUseUsageDescription";
NSString *const kTiGeolocationUsageDescriptionAlways = @"NSLocationAlwaysUsageDescription";
NSString *const kTiGeolocationUsageDescriptionAlwaysAndWhenInUse = @"NSLocationAlwaysAndWhenInUseUsageDescription";
NSString *const kTiGeolocationTemporaryUsageDescriptionDictionary = @"NSLocationTemporaryUsageDescriptionDictionary";
@class KrollPromise;
@protocol GeolocationExports <JSExport>
// accuracy constants
CONSTANT(NSNumber *, ACCURACY_BEST_FOR_NAVIGATION);
CONSTANT(NSNumber *, ACCURACY_HIGH);
CONSTANT(NSNumber *, ACCURACY_LOW);
CONSTANT(NSNumber *, ACCURACY_REDUCED);
// iOS-specific values, (deprecated on Android)
CONSTANT(NSNumber *, ACCURACY_BEST);
CONSTANT(NSNumber *, ACCURACY_HUNDRED_METERS);
CONSTANT(NSNumber *, ACCURACY_KILOMETER);
CONSTANT(NSNumber *, ACCURACY_NEAREST_TEN_METERS);
CONSTANT(NSNumber *, ACCURACY_THREE_KILOMETERS);
// To specify the geolocation activity type
CONSTANT(NSNumber *, ACTIVITYTYPE_AUTOMOTIVE_NAVIGATION); // for automotive navigation
CONSTANT(NSNumber *, ACTIVITYTYPE_FITNESS); // includes any pedestrian activities
CONSTANT(NSNumber *, ACTIVITYTYPE_OTHER); // default
CONSTANT(NSNumber *, ACTIVITYTYPE_OTHER_NAVIGATION); // for other navigation cases (excluding pedestrian navigation), e.g. navigation for boats, trains or planes.
// Authorization to use location
CONSTANT(NSNumber *, AUTHORIZATION_ALWAYS);
CONSTANT(NSNumber *, AUTHORIZATION_DENIED);
CONSTANT(NSNumber *, AUTHORIZATION_RESTRICTED);
CONSTANT(NSNumber *, AUTHORIZATION_UNKNOWN);
CONSTANT(NSNumber *, AUTHORIZATION_WHEN_IN_USE);
//Accuracy Authorization to use location
CONSTANT(NSNumber *, ACCURACY_AUTHORIZATION_FULL);
CONSTANT(NSNumber *, ACCURACY_AUTHORIZATION_REDUCED);
// Error codes
CONSTANT(NSNumber *, ERROR_DENIED);
CONSTANT(NSNumber *, ERROR_HEADING_FAILURE);
CONSTANT(NSNumber *, ERROR_LOCATION_UNKNOWN);
CONSTANT(NSNumber *, ERROR_NETWORK);
CONSTANT(NSNumber *, ERROR_REGION_MONITORING_DELAYED);
CONSTANT(NSNumber *, ERROR_REGION_MONITORING_DENIED);
CONSTANT(NSNumber *, ERROR_REGION_MONITORING_FAILURE);
// Properties
PROPERTY(CLLocationAccuracy, accuracy, Accuracy);
PROPERTY(CLActivityType, activityType, ActivityType);
PROPERTY(bool, allowsBackgroundLocationUpdates, AllowsBackgroundLocationUpdates);
PROPERTY(CLLocationDistance, distanceFilter, DistanceFilter);
READONLY_PROPERTY(bool, hasCompass, HasCompass);
PROPERTY(CLLocationDegrees, headingFilter, HeadingFilter);
READONLY_PROPERTY(NSString *, lastGeolocation, LastGeolocation);
READONLY_PROPERTY(CLAuthorizationStatus, locationServicesAuthorization, LocationServicesAuthorization);
READONLY_PROPERTY(CLAccuracyAuthorization, locationAccuracyAuthorization, AccuracyAuthorization);
READONLY_PROPERTY(bool, locationServicesEnabled, LocationServicesEnabled);
PROPERTY(bool, pauseLocationUpdateAutomatically, PauseLocationUpdateAutomatically);
PROPERTY(bool, showBackgroundLocationIndicator, ShowBackgroundLocationIndicator);
PROPERTY(bool, showCalibration, ShowCalibration);
PROPERTY(bool, trackSignificantLocationChange, TrackSignificantLocationChange);
// methods
JSExportAs(forwardGeocoder,
-(JSValue *)forwardGeocoder
: (NSString *)address withCallback
: (JSValue *)callback);
- (JSValue *)getCurrentHeading:(JSValue *)callback;
- (JSValue *)getCurrentPosition:(JSValue *)callback;
- (bool)hasLocationPermissions:(CLAuthorizationStatus)authorizationType;
JSExportAs(requestLocationPermissions,
-(JSValue *)requestLocationPermissions
: (CLAuthorizationStatus)authorizationType withCallback
: (JSValue *)callback);
JSExportAs(reverseGeocoder,
-(JSValue *)reverseGeocoder
: (double)latitude longitude
: (double)longitude withCallback
: (JSValue *)callback);
JSExportAs(requestTemporaryFullAccuracyAuthorization,
-(void)requestTemporaryFullAccuracyAuthorization
: (NSString *)purposeString withCallback
: (JSValue *)callback);
@end
@interface GeolocationModule : ObjcModule <GeolocationExports, CLLocationManagerDelegate> {
CLLocationManager *locationManager;
CLLocationManager *locationPermissionManager; // used for just permissions requests
CLLocationAccuracy accuracy;
CLLocationDistance distance;
CLLocationDegrees heading;
NSMutableArray *singleHeading;
NSMutableArray *singleLocation;
NSString *purpose; // the reason for using Location services
BOOL trackingHeading;
BOOL trackingLocation;
BOOL trackSignificantLocationChange;
bool allowsBackgroundLocationUpdates;
BOOL showBackgroundLocationIndicator;
JSValue *authorizationCallback;
KrollPromise *authorizationPromise;
CLAuthorizationStatus requestedAuthorizationStatus;
CLActivityType activityType;
BOOL pauseLocationUpdateAutomatically;
NSDictionary *lastLocationDict;
NSRecursiveLock *lock;
}
@end
#endif