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

Disable geo location by default #172

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][unreleased]
### Changed
- Changed geo location to be disabled by default. Users will now have to explicitly call `enableGeoLocation` to ask for user's location permission. #157
- Updated Swift example project to Swift 3 syntax. #175
- Added method to disable automatically requesting CoreLocation authentication.

Expand Down
17 changes: 0 additions & 17 deletions KeenClient/KeenClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,6 @@ @implementation KeenClient

# pragma mark - Class lifecycle

+ (void)initialize {
// initialize the cached client exactly once.

if (self != [KeenClient class]) {
/*
Without this extra check, your initializations could run twice if you ever have a subclass that
doesn't implement its own +initialize method. This is not just a theoretical concern, even if
you don't write any subclasses. Apple's Key-Value Observing creates dynamic subclasses which
don't override +initialize.
*/
return;
}

[KeenClient disableLogging];
[KeenClient enableGeoLocation];
}

+ (void)disableLogging {
loggingEnabled = NO;
}
Expand Down
4 changes: 1 addition & 3 deletions KeenClientTests/KeenClientTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,12 @@ - (void)testEventWithDictionary {
- (void)testGeoLocation {
// set up a client with a location
KeenClient *client = [KeenClient sharedClientWithProjectID:@"id" andWriteKey:@"wk" andReadKey:@"rk"];
KeenClient *clientI = [[KeenClient alloc] initWithProjectID:@"id" andWriteKey:@"wk" andReadKey:@"rk"];
[KeenClient enableGeoLocation];

CLLocation *location = [[CLLocation alloc] initWithLatitude:37.73 longitude:-122.47];
client.currentLocation = location;
// add an event
[client addEvent:@{@"a": @"b"} toEventCollection:@"foo" error:nil];
[clientI addEvent:@{@"a": @"b"} toEventCollection:@"foo" error:nil];
// now get the stored event
NSDictionary *eventsForCollection = [[[KeenClient getDBStore] getEventsWithMaxAttempts:3 andProjectID:client.projectID] objectForKey:@"foo"];
// Grab the first event we get back
Expand All @@ -318,7 +317,6 @@ - (void)testGeoLocationDisabled {
KeenClient *client = [KeenClient sharedClientWithProjectID:@"id" andWriteKey:@"wk" andReadKey:@"rk"];
KeenClient *clientI = [[KeenClient alloc] initWithProjectID:@"id" andWriteKey:@"wk" andReadKey:@"rk"];

[KeenClient disableGeoLocation];
// add an event
[client addEvent:@{@"a": @"b"} toEventCollection:@"bar" error:nil];
[clientI addEvent:@{@"a": @"b"} toEventCollection:@"bar" error:nil];
Expand Down
54 changes: 33 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,39 @@ The block takes in a single string parameter which corresponds to the name of th

##### Geo Location

Like any good mobile-first service, Keen supports geo localization so you can track where events happened. This is enabled by default. Just use the client as you normally would and your users will be asked to allow geo location services. All events will be automatically tagged with the current location.
Like any good mobile-first service, Keen supports geo localization so you can track where events happened. This is **disabled by default**. To enable it, use:

Objective-C:
```objc
[KeenClient enableGeoLocation];
```

Swift:
```swift
KeenClient.enableGeoLocation()
```

Your users will be asked to allow geo location services. If the user chooses "Allow", all events will be automatically tagged with the current location.

###### Requesting Authorization for Location in iOS 8+

iOS 8 introduced a new method for requesting authorization that requires a few additional steps before location will automatically be appended to your events:

1. Add one or both of the following keys to your Info.plist file: `NSLocationWhenInUseUsageDescription`,`NSLocationAlwaysUsageDescription`
2. Call the appropriate authorization method to authorize your app to use location services. `authorizeGeoLocationWhenInUse` and `authorizeGeoLocationAlways` were both added as of version 3.2.16 of this SDK. `authorizeGeoLocationWhenInUse` is enabled by default as long as `NSLocationWhenInUseUsageDescription` is specified in your Info.plist file, so you don't need to call it if you're going the 'When in Use' route. `authorizeGeoLocationAlways` on the other hand must be called explicitly.

Example:

Objective C
```objc
[KeenClient authorizeGeoLocationAlways];
[KeenClient sharedClientWithProjectID:@"your_project_id" andWriteKey:@"your_write_key" andReadKey:@"your_read_key"];
```
Swift
```Swift
KeenClient.authorizeGeoLocationAlways()
KeenClient.sharedClientWithProjectID("your_project_id", andWriteKey: "your_write_key", andReadKey: "your_read_key")
```

If you want to control when you request authentication for location services, you can tell Keen not to request permissions automatically. You do this by calling:

Expand Down Expand Up @@ -352,26 +384,6 @@ do {
}
```

###### Requesting Authorization for Location in iOS 8+

iOS 8 introduced a new method for requesting authorization that requires a few additional steps before location will automatically be appended to your events:

1. Add one or both of the following keys to your Info.plist file: `NSLocationWhenInUseUsageDescription`,`NSLocationAlwaysUsageDescription`
2. Call the appropriate authorization method to authorize your app to use location services. `authorizeGeoLocationWhenInUse` and `authorizeGeoLocationAlways` were both added as of version 3.2.16 of this SDK. `authorizeGeoLocationWhenInUse` is enabled by default as long as `NSLocationWhenInUseUsageDescription` is specified in your Info.plist file, so you don't need to call it if you're going the 'When in Use' route. `authorizeGeoLocationAlways` on the other hand must be called explicitly.

Example:

Objective C
```objc
[KeenClient authorizeGeoLocationAlways];
[KeenClient sharedClientWithProjectID:@"your_project_id" andWriteKey:@"your_write_key" andReadKey:@"your_read_key"];
```
Swift
```Swift
KeenClient.authorizeGeoLocationAlways()
KeenClient.sharedClient(withProjectID: "your_project_id", andWriteKey: "your_write_key", andReadKey: "your_read_key");
```

##### Upload Events to Keen IO

Upload the captured events to the Keen service. This must be done explicitly. We recommend doing the upload when your application is sent to the background, but you can do it whenever you’d like (for example, if your application typically has very long user sessions). The uploader spawns its own background thread so the main UI thread is not blocked.
Expand Down