Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: segmentio/analytics-ios
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: voteplz/analytics-ios
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 4 commits
  • 6 files changed
  • 2 contributors

Commits on Sep 26, 2016

  1. Fix Segment usage in extensions

    Conrad Kramer committed Sep 26, 2016
    Copy the full SHA
    34841eb View commit details
  2. Support proper state change notifications in extensions

    Conrad Kramer committed Sep 26, 2016
    Copy the full SHA
    a09bc11 View commit details
  3. Remove Bluetooth integration

    Conrad Kramer committed Sep 26, 2016
    Copy the full SHA
    a971f13 View commit details
  4. Fixed crash due to the referrer dictionary being assign

    `assign` is a synonym for `unsafe_unretained` in ARC - this is bad!
    AriX committed Sep 26, 2016
    Copy the full SHA
    f4b5b8a View commit details
9 changes: 0 additions & 9 deletions Analytics/Classes/Internal/SEGBluetooth.h

This file was deleted.

37 changes: 0 additions & 37 deletions Analytics/Classes/Internal/SEGBluetooth.m

This file was deleted.

22 changes: 7 additions & 15 deletions Analytics/Classes/Internal/SEGSegmentIntegration.m
Original file line number Diff line number Diff line change
@@ -4,11 +4,11 @@
#import "SEGAnalytics.h"
#import "SEGAnalyticsUtils.h"
#import "SEGSegmentIntegration.h"
#import "SEGBluetooth.h"
#import "SEGReachability.h"
#import "SEGLocation.h"
#import "SEGHTTPClient.h"
#import "SEGStorage.h"
#import "WFBackgroundAssertion.h"

#if TARGET_OS_IOS
#import <CoreTelephony/CTCarrier.h>
@@ -64,16 +64,15 @@ @interface SEGSegmentIntegration ()
@property (nonatomic, strong) NSMutableArray *queue;
@property (nonatomic, strong) NSDictionary *cachedStaticContext;
@property (nonatomic, strong) NSURLSessionUploadTask *batchRequest;
@property (nonatomic, assign) UIBackgroundTaskIdentifier flushTaskID;
@property (nonatomic, strong) SEGBluetooth *bluetooth;
@property (nonatomic, strong) WFBackgroundAssertion *flushAssertion;
@property (nonatomic, strong) SEGReachability *reachability;
@property (nonatomic, strong) SEGLocation *location;
@property (nonatomic, strong) NSTimer *flushTimer;
@property (nonatomic, strong) dispatch_queue_t serialQueue;
@property (nonatomic, strong) NSMutableDictionary *traits;
@property (nonatomic, assign) SEGAnalytics *analytics;
@property (nonatomic, assign) SEGAnalyticsConfiguration *configuration;
@property (nonatomic, assign) NSDictionary *referrer;
@property (nonatomic, copy) NSDictionary *referrer;
@property (nonatomic, copy) NSString *userId;
@property (nonatomic, strong) NSURL *apiURL;
@property (nonatomic, strong) SEGHTTPClient *httpClient;
@@ -99,14 +98,10 @@ - (id)initWithAnalytics:(SEGAnalytics *)analytics
self.httpClient = analytics.httpClient;
self.apiURL = [NSURL URLWithString:@"https://api.segment.io/v1/import"];
self.userId = [self getUserId];
if (self.configuration.shouldUseBluetooth) {
self.bluetooth = [[SEGBluetooth alloc] init];
}
self.reachability = [SEGReachability reachabilityWithHostname:@"google.com"];
[self.reachability startNotifier];
self.cachedStaticContext = [self staticContext];
self.serialQueue = seg_dispatch_queue_create_specific("io.segment.analytics.segmentio", DISPATCH_QUEUE_SERIAL);
self.flushTaskID = UIBackgroundTaskInvalid;

#if !TARGET_OS_TV
// Check for previous queue/track data in NSUserDefaults and remove if present
@@ -238,9 +233,6 @@ - (NSDictionary *)liveContext
context[@"network"] = ({
NSMutableDictionary *network = [[NSMutableDictionary alloc] init];

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

if (self.reachability.isReachable) {
network[@"wifi"] = @(self.reachability.isReachableViaWiFi);
network[@"cellular"] = @(self.reachability.isReachableViaWWAN);
@@ -288,17 +280,17 @@ - (void)beginBackgroundTask
{
[self endBackgroundTask];

self.flushTaskID = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
self.flushAssertion = [WFBackgroundAssertion backgroundAssertionWithName:@"Segment" expirationHandler:^{
[self endBackgroundTask];
}];
}

- (void)endBackgroundTask
{
[self dispatchBackgroundAndWait:^{
if (self.flushTaskID != UIBackgroundTaskInvalid) {
[[UIApplication sharedApplication] endBackgroundTask:self.flushTaskID];
self.flushTaskID = UIBackgroundTaskInvalid;
if (self.flushAssertion) {
[self.flushAssertion end];
self.flushAssertion = nil;
}
}];
}
4 changes: 2 additions & 2 deletions Analytics/Classes/Internal/UIViewController+SEGScreen.m
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
#import <objc/runtime.h>
#import "SEGAnalytics.h"
#import "SEGAnalyticsUtils.h"

#import "WFApplicationContext.h"

@implementation UIViewController (SEGScreen)

@@ -38,7 +38,7 @@ + (void)seg_swizzleViewDidAppear

+ (UIViewController *)seg_topViewController
{
UIViewController *root = [UIApplication sharedApplication].delegate.window.rootViewController;
UIViewController *root = [[[WFApplicationContext sharedContext] keyWindow] rootViewController];
return [self seg_topViewController:root];
}

5 changes: 0 additions & 5 deletions Analytics/Classes/SEGAnalytics.h
Original file line number Diff line number Diff line change
@@ -54,11 +54,6 @@ 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.
*/
23 changes: 14 additions & 9 deletions Analytics/Classes/SEGAnalytics.m
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@
#import "SEGStorage.h"
#import "SEGFileStorage.h"
#import "SEGUserDefaultsStorage.h"
#import "WFApplicationContextPrivate.h"
#import "WFApplicationContextProvider.h"
#import <objc/runtime.h>

static SEGAnalytics *__sharedInstance = nil;
@@ -46,7 +48,6 @@ - (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]];
@@ -130,12 +131,14 @@ - (instancetype)initWithConfiguration:(SEGAnalyticsConfiguration *)configuration
[nc addObserver:self selector:@selector(onAppForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];

// Pass through for application state change events
for (NSString *name in @[ UIApplicationDidEnterBackgroundNotification,
WFApplicationContext *context = [WFApplicationContext sharedContext];
id<WFApplicationContextProvider> provider = context.provider;
for (NSString *name in @[ [provider notificationNameForApplicationStateEvent:WFApplicationDidEnterBackgroundEvent applicationContext:context],
UIApplicationDidFinishLaunchingNotification,
UIApplicationWillEnterForegroundNotification,
[provider notificationNameForApplicationStateEvent:WFApplicationWillEnterForegroundEvent applicationContext:context],
UIApplicationWillTerminateNotification,
UIApplicationWillResignActiveNotification,
UIApplicationDidBecomeActiveNotification ]) {
[provider notificationNameForApplicationStateEvent:WFApplicationWillResignActiveEvent applicationContext:context],
[provider notificationNameForApplicationStateEvent:WFApplicationDidBecomeActiveEvent applicationContext:context] ]) {
[nc addObserver:self selector:@selector(handleAppStateNotification:) name:name object:nil];
}

@@ -215,18 +218,20 @@ - (void)handleAppStateNotification:(NSNotification *)note
static NSDictionary *selectorMapping;
static dispatch_once_t selectorMappingOnce;
dispatch_once(&selectorMappingOnce, ^{
WFApplicationContext *context = [WFApplicationContext sharedContext];
id<WFApplicationContextProvider> provider = context.provider;
selectorMapping = @{
UIApplicationDidFinishLaunchingNotification :
NSStringFromSelector(@selector(applicationDidFinishLaunching:)),
UIApplicationDidEnterBackgroundNotification :
[provider notificationNameForApplicationStateEvent:WFApplicationDidEnterBackgroundEvent applicationContext:context] :
NSStringFromSelector(@selector(applicationDidEnterBackground)),
UIApplicationWillEnterForegroundNotification :
[provider notificationNameForApplicationStateEvent:WFApplicationWillEnterForegroundEvent applicationContext:context] :
NSStringFromSelector(@selector(applicationWillEnterForeground)),
UIApplicationWillTerminateNotification :
NSStringFromSelector(@selector(applicationWillTerminate)),
UIApplicationWillResignActiveNotification :
[provider notificationNameForApplicationStateEvent:WFApplicationWillResignActiveEvent applicationContext:context] :
NSStringFromSelector(@selector(applicationWillResignActive)),
UIApplicationDidBecomeActiveNotification :
[provider notificationNameForApplicationStateEvent:WFApplicationDidBecomeActiveEvent applicationContext:context] :
NSStringFromSelector(@selector(applicationDidBecomeActive))
};
});