diff --git a/CHANGELOG.md b/CHANGELOG.md index e7122ef..f4b9c33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/KeenClient/KeenClient.m b/KeenClient/KeenClient.m index 8f9f2a6..354db9e 100644 --- a/KeenClient/KeenClient.m +++ b/KeenClient/KeenClient.m @@ -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; } diff --git a/KeenClientTests/KeenClientTests.m b/KeenClientTests/KeenClientTests.m index bcea256..b111c58 100644 --- a/KeenClientTests/KeenClientTests.m +++ b/KeenClientTests/KeenClientTests.m @@ -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 @@ -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]; diff --git a/README.md b/README.md index 9303624..8afb3d7 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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.