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

Add option to enable/disable bluetooth collection. #597

Merged
merged 1 commit into from
Sep 13, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Analytics/Classes/Internal/SEGBluetooth.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#import "SEGBluetooth.h"
#import <CoreBluetooth/CoreBluetooth.h>

const NSString *SEGCentralManagerClass = @"CBCentralManager";


@interface SEGBluetooth () <CBCentralManagerDelegate>

Expand Down
6 changes: 4 additions & 2 deletions Analytics/Classes/Internal/SEGSegmentIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ - (id)initWithAnalytics:(SEGAnalytics *)analytics
self.httpClient = analytics.httpClient;
self.apiURL = [NSURL URLWithString:@"https://api.segment.io/v1/import"];
self.userId = [self getUserId];
self.bluetooth = [[SEGBluetooth alloc] init];
if (self.configuration.shouldUseBluetooth) {
self.bluetooth = [[SEGBluetooth alloc] init];
}
self.reachability = [SEGReachability reachabilityWithHostname:@"google.com"];
[self.reachability startNotifier];
self.cachedStaticContext = [self staticContext];
Expand Down Expand Up @@ -236,7 +238,7 @@ - (NSDictionary *)liveContext
context[@"network"] = ({
NSMutableDictionary *network = [[NSMutableDictionary alloc] init];

if (self.bluetooth.hasKnownState)
if (self.bluetooth && self.bluetooth.hasKnownState)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW in Objc if self.bluetooth is nil then self.bluetooth.hasKnownState will evaluate to NO automatically. It's kind of an idiomatic objc thing, but of course both way works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was considering not adding the self.bluetooth check - I don't have a strong preference either way so I ended up adding it.

network[@"bluetooth"] = @(self.bluetooth.isEnabled);

if (self.reachability.isReachable) {
Expand Down
10 changes: 9 additions & 1 deletion Analytics/Classes/SEGAnalytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ typedef NSMutableURLRequest * (^SEGRequestFactory)(NSURL *);
@property (nonatomic, copy, readonly) NSString *writeKey;

/**
* Whether the analytics client should use location services. If `YES` and the host app hasn't asked for permission to use location services then the user will be presented with an alert view asking to do so. `NO` by default.
* Whether the analytics client should use location services.
* If `YES` and the host app hasn't asked for permission to use location services then the user will be presented with an alert view asking to do so. `NO` by default.
* If `YES`, please make sure to add a description for `NSLocationAlwaysUsageDescription` in your `Info.plist` explaining why your app is accessing Location APIs.
*/
@property (nonatomic, assign) BOOL shouldUseLocationServices;

Expand All @@ -51,6 +53,12 @@ typedef NSMutableURLRequest * (^SEGRequestFactory)(NSURL *);
*/
@property (nonatomic, assign) BOOL trackApplicationLifecycleEvents;


/**
* Whether the analytics client should record bluetooth information. If `YES`, please make sure to add a description for `NSBluetoothPeripheralUsageDescription` in your `Info.plist` explaining explaining why your app is accessing Bluetooth APIs. `NO` by default.
*/
@property (nonatomic, assign) BOOL shouldUseBluetooth;

/**
* Whether the analytics client should automatically make a screen call when a view controller is added to a view hierarchy. Because the underlying implementation uses method swizzling, we recommend initializing the analytics client as early as possible (before any screens are displayed), ideally during the Application delegate's applicationDidFinishLaunching method.
*/
Expand Down
1 change: 1 addition & 0 deletions Analytics/Classes/SEGAnalytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ - (instancetype)init
if (self = [super init]) {
self.shouldUseLocationServices = NO;
self.enableAdvertisingTracking = YES;
self.shouldUseBluetooth = NO;
self.flushAt = 20;
_factories = [NSMutableArray array];
[_factories addObject:[SEGSegmentIntegrationFactory instance]];
Expand Down
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- Analytics (3.3.0)
- Analytics (3.4.0)
- Expecta (1.0.5)
- Nimble (4.1.0)
- Nocilla (0.10.0)
Expand All @@ -16,10 +16,10 @@ DEPENDENCIES:

EXTERNAL SOURCES:
Analytics:
:path: "../"
:path: ../

SPEC CHECKSUMS:
Analytics: 5ebaf07a5067e730ca749c184f04db7752724e97
Analytics: 3efde438f4f1e03f20525a0552784551a2e6037f
Expecta: e1c022fcd33910b6be89c291d2775b3fe27a89fe
Nimble: 97a0a4cae5124c117115634b2d055d8c97d0af19
Nocilla: ae0a2b05f3087b473624ac2b25903695df51246a
Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/Analytics.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Example/Pods/Target Support Files/Analytics/Info.plist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Example/Tests/Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
expect(analytics.configuration.writeKey).to.equal(@"QUI5ydwIGeFFTa1IvCBUhxL9PyW5B0jE");
expect(analytics.configuration.shouldUseLocationServices).to.equal(@NO);
expect(analytics.configuration.enableAdvertisingTracking).to.equal(@YES);
expect(analytics.configuration.shouldUseBluetooth).to.equal(@NO);
});
});

Expand Down