Skip to content

Commit

Permalink
Backports some fixes from 3.8 series to 3.7 series (#867)
Browse files Browse the repository at this point in the history
* Look at previously cached settings before blowing them away. (#866)

* Differences observed in how iOS/android pass userId/anonId; Corrected.

* Fix GCD mutual dependency (#785)

* Fixed hanging test. Removed `nil` example as that’s changed in later versions.

* Moved minimum iOS version to 10.0 from 10.1

* Updated config.yml to use latest xcode.

* Fixed makefile for iPhone 11 simulator.

* Fixed test further. :S

Co-authored-by: Fathy Boundjadj <fathy.boundjadj@gmail.com>
  • Loading branch information
bsneed and fathyb authored Feb 21, 2020
1 parent 49ecc73 commit 0ed64b8
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
jobs:
build_and_test:
macos:
xcode: "9.4.1"
xcode: "11.3.1"
steps:
- checkout
- run: xcrun simctl list
Expand Down
9 changes: 5 additions & 4 deletions Analytics.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = EADEB8511DECD080005322DA;
Expand Down Expand Up @@ -541,7 +542,7 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-AnalyticsTests/Pods-AnalyticsTests-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-AnalyticsTests/Pods-AnalyticsTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
"${BUILT_PRODUCTS_DIR}/Alamofire-Synchronous/Alamofire_Synchronous.framework",
"${BUILT_PRODUCTS_DIR}/Nimble/Nimble.framework",
Expand All @@ -560,7 +561,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AnalyticsTests/Pods-AnalyticsTests-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-AnalyticsTests/Pods-AnalyticsTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand Down Expand Up @@ -676,7 +677,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -729,7 +730,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
21 changes: 13 additions & 8 deletions Analytics/Classes/Integrations/SEGIntegrationsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,19 @@ - (void)refreshSettings
if (success) {
[self setCachedSettings:settings];
} else {
// If settings request fail, fall back to using just Segment integration.
// Doesn't address situations where this callback never gets called (though we don't expect that to ever happen).
[self setCachedSettings:@{
@"integrations" : @{
@"Segment.io" : @{@"apiKey" : self.configuration.writeKey},
},
@"plan" : @{@"track" : @{}}
}];
NSDictionary *previouslyCachedSettings = [self cachedSettings];
if (previouslyCachedSettings) {
[self setCachedSettings:previouslyCachedSettings];
} else {
// If settings request fail, fall back to using just Segment integration.
// Doesn't address situations where this callback never gets called (though we don't expect that to ever happen).
[self setCachedSettings:@{
@"integrations" : @{
@"Segment.io" : @{@"apiKey" : self.configuration.writeKey},
},
@"plan" : @{@"track" : @{}}
}];
}
}
self.settingsRequest = nil;
});
Expand Down
24 changes: 8 additions & 16 deletions Analytics/Classes/Internal/SEGSegmentIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,18 @@ - (id)initWithAnalytics:(SEGAnalytics *)analytics httpClient:(SEGHTTPClient *)ht
[self trackAttributionData:self.configuration.trackAttributionData];
}];

if ([NSThread isMainThread]) {
[self setupFlushTimer];
} else {
dispatch_sync(dispatch_get_main_queue(), ^{
[self setupFlushTimer];
});
}
self.flushTimer = [NSTimer timerWithTimeInterval:self.configuration.flushInterval
target:self
selector:@selector(flush)
userInfo:nil
repeats:YES];

[NSRunLoop.mainRunLoop addTimer:self.flushTimer
forMode:NSDefaultRunLoopMode];
}
return self;
}

- (void)setupFlushTimer
{
self.flushTimer = [NSTimer scheduledTimerWithTimeInterval:self.configuration.flushInterval
target:self
selector:@selector(flush)
userInfo:nil
repeats:YES];
}

/*
* There is an iOS bug that causes instances of the CTTelephonyNetworkInfo class to
* sometimes get notifications after they have been deallocated.
Expand Down
18 changes: 16 additions & 2 deletions Analytics/Classes/SEGAnalytics.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,24 @@ - (void)identify:(NSString *)userId traits:(NSDictionary *)traits
- (void)identify:(NSString *)userId traits:(NSDictionary *)traits options:(NSDictionary *)options
{
NSCAssert2(userId.length > 0 || traits.count > 0, @"either userId (%@) or traits (%@) must be provided.", userId, traits);

// this is done here to match functionality on android where these are inserted BEFORE being spread out amongst destinations.
// it will be set globally later when it runs through SEGIntegrationManager.identify.
NSString *anonId = [options objectForKey:@"anonymousId"];
if (anonId == nil) {
anonId = [self getAnonymousId];
}
// configure traits to match what is seen on android.
NSMutableDictionary *newTraits = [traits mutableCopy];
newTraits[@"anonymousId"] = anonId;
if (userId != nil) {
newTraits[@"userId"] = userId;
}

[self run:SEGEventTypeIdentify payload:
[[SEGIdentifyPayload alloc] initWithUserId:userId
anonymousId:[options objectForKey:@"anonymousId"]
traits:SEGCoerceDictionary(traits)
anonymousId:anonId
traits:SEGCoerceDictionary(newTraits)
context:SEGCoerceDictionary([options objectForKey:@"context"])
integrations:[options objectForKey:@"integrations"]]];
}
Expand Down
13 changes: 7 additions & 6 deletions AnalyticsTests/AnalyticsUtilTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ class AnalyticsUtilTests: QuickSpec {

it("works with nested dictionaries") {
let data = [
"foo": [1, nil, "qfoob", ["baz": "foo"]],
"foo": [1, "qfoob", ["baz": "foo"]],
"bar": "foo"
] as [String : Any]
let input = SEGUtils.traverseJSON(data, andReplaceWithFilters: filters)
] as [String: Any]
let input = SEGUtils.traverseJSON(data, andReplaceWithFilters: filters) as! NSDictionary
let output = [
"foo": [1, nil, "qfoo-barb", ["baz": "foo-bar"]],
"foo": [1, "qfoo-barb", ["baz": "foo-bar"]],
"bar": "foo-bar"
] as [String : Any]
] as [String: Any]

expect(equals(a: input!, b: output)) == true
let dictsEqual = input.isEqual(to: output)
expect(dictsEqual) == true
}

it("works with nested arrays") {
Expand Down
2 changes: 1 addition & 1 deletion AnalyticsTests/TrackingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TrackingTests: QuickSpec {
expect(passthrough.lastContext?.eventType) == SEGEventType.identify
let identify = passthrough.lastContext?.payload as? SEGIdentifyPayload
expect(identify?.userId) == "testUserId1"
expect(identify?.anonymousId).to(beNil())
expect(identify?.anonymousId).toNot(beNil())
expect(identify?.traits?["firstName"] as? String) == "Peter"
}

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SDK ?= "iphonesimulator"
DESTINATION ?= "platform=iOS Simulator,name=iPhone X"
DESTINATION ?= "platform=iOS Simulator,name=iPhone 11"
PROJECT := Analytics
XC_ARGS := -workspace $(PROJECT).xcworkspace -scheme $(PROJECT) -destination $(DESTINATION) GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES
XC_BUILD_ARGS := ONLY_ACTIVE_ARCH=NO
Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ target 'AnalyticsTests' do
use_frameworks!

pod 'Quick', '~> 1.2.0'
pod 'Nimble', '~> 7.3.1'
pod 'Nimble', '~> 7.3.4'
pod 'Nocilla', '~> 0.11.0'
pod 'Alamofire', '~> 4.5'
pod 'Alamofire-Synchronous', '~> 4.0'
Expand Down
15 changes: 8 additions & 7 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@ PODS:
- Alamofire (4.6.0)
- Alamofire-Synchronous (4.0.0):
- Alamofire (~> 4.0)
- Nimble (7.3.1)
- Nimble (7.3.4)
- Nocilla (0.11.0)
- Quick (1.2.0)
- SwiftTryCatch (1.0.0)

DEPENDENCIES:
- Alamofire (~> 4.5)
- Alamofire-Synchronous (~> 4.0)
- Nimble (~> 7.3.1)
- Nimble (~> 7.3.4)
- Nocilla (~> 0.11.0)
- Quick (~> 1.2.0)
- SwiftTryCatch (from `https://github.com/segmentio/SwiftTryCatch.git`)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
https://github.com/CocoaPods/Specs.git:
- Alamofire
- Alamofire-Synchronous
- Nimble
- Nocilla
- Quick
trunk:
- Nimble

EXTERNAL SOURCES:
SwiftTryCatch:
Expand All @@ -35,11 +36,11 @@ CHECKOUT OPTIONS:
SPEC CHECKSUMS:
Alamofire: f41a599bd63041760b26d393ec1069d9d7b917f4
Alamofire-Synchronous: eedf1e6e961c3795a63c74990b3f7d9fbfac7e50
Nimble: 04f732da099ea4d153122aec8c2a88fd0c7219ae
Nimble: 051e3d8912d40138fa5591c78594f95fb172af37
Nocilla: 7af7a386071150cc8aa5da4da97d060f049dd61c
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
SwiftTryCatch: 2f4ef36cf5396bdb450006b70633dbce5260d3b3

PODFILE CHECKSUM: cf4abb4263c7b514d71c70514284ac657d90865d
PODFILE CHECKSUM: 96037d813a3e1239ea354ede97146038cd4a31bb

COCOAPODS: 1.5.3
COCOAPODS: 1.8.4

0 comments on commit 0ed64b8

Please sign in to comment.