Skip to content

Commit 0ed64b8

Browse files
bsneedfathyb
andauthored
Backports some fixes from 3.8 series to 3.7 series (#867)
* 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 <[email protected]>
1 parent 49ecc73 commit 0ed64b8

File tree

10 files changed

+61
-47
lines changed

10 files changed

+61
-47
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2
33
jobs:
44
build_and_test:
55
macos:
6-
xcode: "9.4.1"
6+
xcode: "11.3.1"
77
steps:
88
- checkout
99
- run: xcrun simctl list

Analytics.xcodeproj/project.pbxproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@
486486
developmentRegion = English;
487487
hasScannedForEncodings = 0;
488488
knownRegions = (
489+
English,
489490
en,
490491
);
491492
mainGroup = EADEB8511DECD080005322DA;
@@ -541,7 +542,7 @@
541542
files = (
542543
);
543544
inputPaths = (
544-
"${SRCROOT}/Pods/Target Support Files/Pods-AnalyticsTests/Pods-AnalyticsTests-frameworks.sh",
545+
"${PODS_ROOT}/Target Support Files/Pods-AnalyticsTests/Pods-AnalyticsTests-frameworks.sh",
545546
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
546547
"${BUILT_PRODUCTS_DIR}/Alamofire-Synchronous/Alamofire_Synchronous.framework",
547548
"${BUILT_PRODUCTS_DIR}/Nimble/Nimble.framework",
@@ -560,7 +561,7 @@
560561
);
561562
runOnlyForDeploymentPostprocessing = 0;
562563
shellPath = /bin/sh;
563-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AnalyticsTests/Pods-AnalyticsTests-frameworks.sh\"\n";
564+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-AnalyticsTests/Pods-AnalyticsTests-frameworks.sh\"\n";
564565
showEnvVarsInLog = 0;
565566
};
566567
/* End PBXShellScriptBuildPhase section */
@@ -676,7 +677,7 @@
676677
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
677678
GCC_WARN_UNUSED_FUNCTION = YES;
678679
GCC_WARN_UNUSED_VARIABLE = YES;
679-
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
680+
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
680681
MTL_ENABLE_DEBUG_INFO = YES;
681682
ONLY_ACTIVE_ARCH = YES;
682683
SDKROOT = iphoneos;
@@ -729,7 +730,7 @@
729730
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
730731
GCC_WARN_UNUSED_FUNCTION = YES;
731732
GCC_WARN_UNUSED_VARIABLE = YES;
732-
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
733+
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
733734
MTL_ENABLE_DEBUG_INFO = NO;
734735
SDKROOT = iphoneos;
735736
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";

Analytics/Classes/Integrations/SEGIntegrationsManager.m

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,19 @@ - (void)refreshSettings
378378
if (success) {
379379
[self setCachedSettings:settings];
380380
} else {
381-
// If settings request fail, fall back to using just Segment integration.
382-
// Doesn't address situations where this callback never gets called (though we don't expect that to ever happen).
383-
[self setCachedSettings:@{
384-
@"integrations" : @{
385-
@"Segment.io" : @{@"apiKey" : self.configuration.writeKey},
386-
},
387-
@"plan" : @{@"track" : @{}}
388-
}];
381+
NSDictionary *previouslyCachedSettings = [self cachedSettings];
382+
if (previouslyCachedSettings) {
383+
[self setCachedSettings:previouslyCachedSettings];
384+
} else {
385+
// If settings request fail, fall back to using just Segment integration.
386+
// Doesn't address situations where this callback never gets called (though we don't expect that to ever happen).
387+
[self setCachedSettings:@{
388+
@"integrations" : @{
389+
@"Segment.io" : @{@"apiKey" : self.configuration.writeKey},
390+
},
391+
@"plan" : @{@"track" : @{}}
392+
}];
393+
}
389394
}
390395
self.settingsRequest = nil;
391396
});

Analytics/Classes/Internal/SEGSegmentIntegration.m

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,18 @@ - (id)initWithAnalytics:(SEGAnalytics *)analytics httpClient:(SEGHTTPClient *)ht
106106
[self trackAttributionData:self.configuration.trackAttributionData];
107107
}];
108108

109-
if ([NSThread isMainThread]) {
110-
[self setupFlushTimer];
111-
} else {
112-
dispatch_sync(dispatch_get_main_queue(), ^{
113-
[self setupFlushTimer];
114-
});
115-
}
109+
self.flushTimer = [NSTimer timerWithTimeInterval:self.configuration.flushInterval
110+
target:self
111+
selector:@selector(flush)
112+
userInfo:nil
113+
repeats:YES];
114+
115+
[NSRunLoop.mainRunLoop addTimer:self.flushTimer
116+
forMode:NSDefaultRunLoopMode];
116117
}
117118
return self;
118119
}
119120

120-
- (void)setupFlushTimer
121-
{
122-
self.flushTimer = [NSTimer scheduledTimerWithTimeInterval:self.configuration.flushInterval
123-
target:self
124-
selector:@selector(flush)
125-
userInfo:nil
126-
repeats:YES];
127-
}
128-
129121
/*
130122
* There is an iOS bug that causes instances of the CTTelephonyNetworkInfo class to
131123
* sometimes get notifications after they have been deallocated.

Analytics/Classes/SEGAnalytics.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,24 @@ - (void)identify:(NSString *)userId traits:(NSDictionary *)traits
199199
- (void)identify:(NSString *)userId traits:(NSDictionary *)traits options:(NSDictionary *)options
200200
{
201201
NSCAssert2(userId.length > 0 || traits.count > 0, @"either userId (%@) or traits (%@) must be provided.", userId, traits);
202+
203+
// this is done here to match functionality on android where these are inserted BEFORE being spread out amongst destinations.
204+
// it will be set globally later when it runs through SEGIntegrationManager.identify.
205+
NSString *anonId = [options objectForKey:@"anonymousId"];
206+
if (anonId == nil) {
207+
anonId = [self getAnonymousId];
208+
}
209+
// configure traits to match what is seen on android.
210+
NSMutableDictionary *newTraits = [traits mutableCopy];
211+
newTraits[@"anonymousId"] = anonId;
212+
if (userId != nil) {
213+
newTraits[@"userId"] = userId;
214+
}
215+
202216
[self run:SEGEventTypeIdentify payload:
203217
[[SEGIdentifyPayload alloc] initWithUserId:userId
204-
anonymousId:[options objectForKey:@"anonymousId"]
205-
traits:SEGCoerceDictionary(traits)
218+
anonymousId:anonId
219+
traits:SEGCoerceDictionary(newTraits)
206220
context:SEGCoerceDictionary([options objectForKey:@"context"])
207221
integrations:[options objectForKey:@"integrations"]]];
208222
}

AnalyticsTests/AnalyticsUtilTests.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,17 @@ class AnalyticsUtilTests: QuickSpec {
8585

8686
it("works with nested dictionaries") {
8787
let data = [
88-
"foo": [1, nil, "qfoob", ["baz": "foo"]],
88+
"foo": [1, "qfoob", ["baz": "foo"]],
8989
"bar": "foo"
90-
] as [String : Any]
91-
let input = SEGUtils.traverseJSON(data, andReplaceWithFilters: filters)
90+
] as [String: Any]
91+
let input = SEGUtils.traverseJSON(data, andReplaceWithFilters: filters) as! NSDictionary
9292
let output = [
93-
"foo": [1, nil, "qfoo-barb", ["baz": "foo-bar"]],
93+
"foo": [1, "qfoo-barb", ["baz": "foo-bar"]],
9494
"bar": "foo-bar"
95-
] as [String : Any]
95+
] as [String: Any]
9696

97-
expect(equals(a: input!, b: output)) == true
97+
let dictsEqual = input.isEqual(to: output)
98+
expect(dictsEqual) == true
9899
}
99100

100101
it("works with nested arrays") {

AnalyticsTests/TrackingTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TrackingTests: QuickSpec {
3636
expect(passthrough.lastContext?.eventType) == SEGEventType.identify
3737
let identify = passthrough.lastContext?.payload as? SEGIdentifyPayload
3838
expect(identify?.userId) == "testUserId1"
39-
expect(identify?.anonymousId).to(beNil())
39+
expect(identify?.anonymousId).toNot(beNil())
4040
expect(identify?.traits?["firstName"] as? String) == "Peter"
4141
}
4242

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
SDK ?= "iphonesimulator"
2-
DESTINATION ?= "platform=iOS Simulator,name=iPhone X"
2+
DESTINATION ?= "platform=iOS Simulator,name=iPhone 11"
33
PROJECT := Analytics
44
XC_ARGS := -workspace $(PROJECT).xcworkspace -scheme $(PROJECT) -destination $(DESTINATION) GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES
55
XC_BUILD_ARGS := ONLY_ACTIVE_ARCH=NO

Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ target 'AnalyticsTests' do
44
use_frameworks!
55

66
pod 'Quick', '~> 1.2.0'
7-
pod 'Nimble', '~> 7.3.1'
7+
pod 'Nimble', '~> 7.3.4'
88
pod 'Nocilla', '~> 0.11.0'
99
pod 'Alamofire', '~> 4.5'
1010
pod 'Alamofire-Synchronous', '~> 4.0'

Podfile.lock

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@ PODS:
22
- Alamofire (4.6.0)
33
- Alamofire-Synchronous (4.0.0):
44
- Alamofire (~> 4.0)
5-
- Nimble (7.3.1)
5+
- Nimble (7.3.4)
66
- Nocilla (0.11.0)
77
- Quick (1.2.0)
88
- SwiftTryCatch (1.0.0)
99

1010
DEPENDENCIES:
1111
- Alamofire (~> 4.5)
1212
- Alamofire-Synchronous (~> 4.0)
13-
- Nimble (~> 7.3.1)
13+
- Nimble (~> 7.3.4)
1414
- Nocilla (~> 0.11.0)
1515
- Quick (~> 1.2.0)
1616
- SwiftTryCatch (from `https://github.com/segmentio/SwiftTryCatch.git`)
1717

1818
SPEC REPOS:
19-
https://github.com/cocoapods/specs.git:
19+
https://github.com/CocoaPods/Specs.git:
2020
- Alamofire
2121
- Alamofire-Synchronous
22-
- Nimble
2322
- Nocilla
2423
- Quick
24+
trunk:
25+
- Nimble
2526

2627
EXTERNAL SOURCES:
2728
SwiftTryCatch:
@@ -35,11 +36,11 @@ CHECKOUT OPTIONS:
3536
SPEC CHECKSUMS:
3637
Alamofire: f41a599bd63041760b26d393ec1069d9d7b917f4
3738
Alamofire-Synchronous: eedf1e6e961c3795a63c74990b3f7d9fbfac7e50
38-
Nimble: 04f732da099ea4d153122aec8c2a88fd0c7219ae
39+
Nimble: 051e3d8912d40138fa5591c78594f95fb172af37
3940
Nocilla: 7af7a386071150cc8aa5da4da97d060f049dd61c
4041
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
4142
SwiftTryCatch: 2f4ef36cf5396bdb450006b70633dbce5260d3b3
4243

43-
PODFILE CHECKSUM: cf4abb4263c7b514d71c70514284ac657d90865d
44+
PODFILE CHECKSUM: 96037d813a3e1239ea354ede97146038cd4a31bb
4445

45-
COCOAPODS: 1.5.3
46+
COCOAPODS: 1.8.4

0 commit comments

Comments
 (0)