Skip to content

Commit 1a09583

Browse files
authored
Merge pull request #930 from segmentio/migs647/remove-public-configuration
Deprecated configuration access and updated associated tests
2 parents 34d00ff + 1de8814 commit 1a09583

File tree

6 files changed

+48
-38
lines changed

6 files changed

+48
-38
lines changed

Analytics/Classes/SEGAnalytics.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ NS_SWIFT_NAME(Analytics)
1717
/**
1818
* Used by the analytics client to configure various options.
1919
*/
20-
@property (nonatomic, strong, readonly) SEGAnalyticsConfiguration *configuration;
20+
@property (nullable, nonatomic, strong, readonly) SEGAnalyticsConfiguration *configuration DEPRECATED_MSG_ATTRIBUTE("One time use object");
2121

2222
/**
2323
* Setup this analytics client instance.
@@ -218,9 +218,6 @@ NS_SWIFT_NAME(Analytics)
218218
/** Returns the registered device token of this device */
219219
- (NSString *)getDeviceToken;
220220

221-
/** Returns the configuration used to create the analytics client. */
222-
- (SEGAnalyticsConfiguration *)configuration;
223-
224221
@end
225222

226223
NS_ASSUME_NONNULL_END

Analytics/Classes/SEGAnalytics.m

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
@interface SEGAnalytics ()
2424

2525
@property (nonatomic, assign) BOOL enabled;
26-
@property (nonatomic, strong) SEGAnalyticsConfiguration *configuration;
26+
@property (nonatomic, strong) SEGAnalyticsConfiguration *oneTimeConfiguration;
2727
@property (nonatomic, strong) SEGStoreKitTracker *storeKitTracker;
2828
@property (nonatomic, strong) SEGIntegrationsManager *integrationsManager;
2929
@property (nonatomic, strong) SEGMiddlewareRunner *runner;
30-
3130
@end
3231

3332

@@ -46,7 +45,7 @@ - (instancetype)initWithConfiguration:(SEGAnalyticsConfiguration *)configuration
4645
NSCParameterAssert(configuration != nil);
4746

4847
if (self = [self init]) {
49-
self.configuration = configuration;
48+
self.oneTimeConfiguration = configuration;
5049
self.enabled = YES;
5150

5251
// In swift this would not have been OK... But hey.. It's objc
@@ -161,7 +160,7 @@ - (void)handleAppStateNotification:(NSNotification *)note
161160

162161
- (void)_applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
163162
{
164-
if (!self.configuration.trackApplicationLifecycleEvents) {
163+
if (!self.oneTimeConfiguration.trackApplicationLifecycleEvents) {
165164
return;
166165
}
167166
// Previously SEGBuildKey was stored an integer. This was incorrect because the CFBundleVersion
@@ -218,7 +217,7 @@ - (void)_applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
218217

219218
- (void)_applicationWillEnterForeground
220219
{
221-
if (!self.configuration.trackApplicationLifecycleEvents) {
220+
if (!self.oneTimeConfiguration.trackApplicationLifecycleEvents) {
222221
return;
223222
}
224223
NSString *currentVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
@@ -234,7 +233,7 @@ - (void)_applicationWillEnterForeground
234233

235234
- (void)_applicationDidEnterBackground
236235
{
237-
if (!self.configuration.trackApplicationLifecycleEvents) {
236+
if (!self.oneTimeConfiguration.trackApplicationLifecycleEvents) {
238237
return;
239238
}
240239
[self track: @"Application Backgrounded"];
@@ -248,6 +247,12 @@ - (NSString *)description
248247
return [NSString stringWithFormat:@"<%p:%@, %@>", self, [self class], [self dictionaryWithValuesForKeys:@[ @"configuration" ]]];
249248
}
250249

250+
- (nullable SEGAnalyticsConfiguration *)configuration
251+
{
252+
// Remove deprecated configuration on 4.2+
253+
return nil;
254+
}
255+
251256
#pragma mark - Identify
252257

253258
- (void)identify:(NSString *)userId
@@ -389,7 +394,7 @@ - (void)trackPushNotification:(NSDictionary *)properties fromLaunch:(BOOL)launch
389394

390395
- (void)receivedRemoteNotification:(NSDictionary *)userInfo
391396
{
392-
if (self.configuration.trackPushNotifications) {
397+
if (self.oneTimeConfiguration.trackPushNotifications) {
393398
[self trackPushNotification:userInfo fromLaunch:NO];
394399
}
395400
SEGRemoteNotificationPayload *payload = [[SEGRemoteNotificationPayload alloc] init];
@@ -427,7 +432,7 @@ - (void)continueUserActivity:(NSUserActivity *)activity
427432
payload.activity = activity;
428433
[self run:SEGEventTypeContinueUserActivity payload:payload];
429434

430-
if (!self.configuration.trackDeepLinks) {
435+
if (!self.oneTimeConfiguration.trackDeepLinks) {
431436
return;
432437
}
433438

@@ -442,7 +447,7 @@ - (void)continueUserActivity:(NSUserActivity *)activity
442447
properties[@"url"] = urlString;
443448
properties[@"title"] = activity.title ?: @"";
444449
properties = [SEGUtils traverseJSON:properties
445-
andReplaceWithFilters:self.configuration.payloadFilters];
450+
andReplaceWithFilters:self.oneTimeConfiguration.payloadFilters];
446451
[self track:@"Deep Link Opened" properties:[properties copy]];
447452
}
448453
}
@@ -451,11 +456,11 @@ - (void)openURL:(NSURL *)url options:(NSDictionary *)options
451456
{
452457
SEGOpenURLPayload *payload = [[SEGOpenURLPayload alloc] init];
453458
payload.url = [NSURL URLWithString:[SEGUtils traverseJSON:url.absoluteString
454-
andReplaceWithFilters:self.configuration.payloadFilters]];
459+
andReplaceWithFilters:self.oneTimeConfiguration.payloadFilters]];
455460
payload.options = options;
456461
[self run:SEGEventTypeOpenURL payload:payload];
457462

458-
if (!self.configuration.trackDeepLinks) {
463+
if (!self.oneTimeConfiguration.trackDeepLinks) {
459464
return;
460465
}
461466

@@ -468,7 +473,7 @@ - (void)openURL:(NSURL *)url options:(NSDictionary *)options
468473
[properties addEntriesFromDictionary:options];
469474
properties[@"url"] = urlString;
470475
properties = [SEGUtils traverseJSON:properties
471-
andReplaceWithFilters:self.configuration.payloadFilters];
476+
andReplaceWithFilters:self.oneTimeConfiguration.payloadFilters];
472477
[self track:@"Deep Link Opened" properties:[properties copy]];
473478
}
474479

@@ -535,7 +540,7 @@ - (void)run:(SEGEventType)eventType payload:(SEGPayload *)payload
535540
return;
536541
}
537542

538-
if (self.configuration.experimental.nanosecondTimestamps) {
543+
if (self.oneTimeConfiguration.experimental.nanosecondTimestamps) {
539544
payload.timestamp = iso8601NanoFormattedString([NSDate date]);
540545
} else {
541546
payload.timestamp = iso8601FormattedString([NSDate date]);

Analytics/Classes/SEGSegmentIntegration.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,19 @@ @interface SEGSegmentIntegration ()
5555

5656
@end
5757

58+
@interface SEGAnalytics ()
59+
@property (nonatomic, strong, readonly) SEGAnalyticsConfiguration *oneTimeConfiguration;
60+
@end
5861

5962
@implementation SEGSegmentIntegration
6063

6164
- (id)initWithAnalytics:(SEGAnalytics *)analytics httpClient:(SEGHTTPClient *)httpClient fileStorage:(id<SEGStorage>)fileStorage userDefaultsStorage:(id<SEGStorage>)userDefaultsStorage;
6265
{
6366
if (self = [super init]) {
6467
self.analytics = analytics;
65-
self.configuration = analytics.configuration;
68+
self.configuration = analytics.oneTimeConfiguration;
6669
self.httpClient = httpClient;
67-
self.httpClient.httpSessionDelegate = analytics.configuration.httpSessionDelegate;
70+
self.httpClient.httpSessionDelegate = analytics.oneTimeConfiguration.httpSessionDelegate;
6871
self.fileStorage = fileStorage;
6972
self.userDefaultsStorage = userDefaultsStorage;
7073
self.apiURL = [SEGMENT_API_BASE URLByAppendingPathComponent:@"import"];
@@ -125,7 +128,7 @@ - (void)beginBackgroundTask
125128

126129
seg_dispatch_specific_sync(_backgroundTaskQueue, ^{
127130

128-
id<SEGApplicationProtocol> application = [self.analytics configuration].application;
131+
id<SEGApplicationProtocol> application = [self.analytics oneTimeConfiguration].application;
129132
if (application && [application respondsToSelector:@selector(seg_beginBackgroundTaskWithName:expirationHandler:)]) {
130133
self.flushTaskID = [application seg_beginBackgroundTaskWithName:@"Segmentio.Flush"
131134
expirationHandler:^{
@@ -144,7 +147,7 @@ - (void)endBackgroundTask
144147
// See https://github.com/segmentio/analytics-ios/issues/683
145148
seg_dispatch_specific_sync(_backgroundTaskQueue, ^{
146149
if (self.flushTaskID != UIBackgroundTaskInvalid) {
147-
id<SEGApplicationProtocol> application = [self.analytics configuration].application;
150+
id<SEGApplicationProtocol> application = [self.analytics oneTimeConfiguration].application;
148151
if (application && [application respondsToSelector:@selector(seg_endBackgroundTask:)]) {
149152
[application seg_endBackgroundTask:self.flushTaskID];
150153
}
@@ -309,7 +312,7 @@ - (void)queuePayload:(NSDictionary *)payload
309312
{
310313
@try {
311314
// Trim the queue to maxQueueSize - 1 before we add a new element.
312-
trimQueue(self.queue, self.analytics.configuration.maxQueueSize - 1);
315+
trimQueue(self.queue, self.analytics.oneTimeConfiguration.maxQueueSize - 1);
313316
[self.queue addObject:payload];
314317
[self persistQueue];
315318
[self flushQueueByLength];

Analytics/Internal/SEGIntegrationsManager.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ @interface SEGIntegrationsManager ()
8080

8181
@end
8282

83+
@interface SEGAnalytics ()
84+
@property (nullable, nonatomic, strong, readonly) SEGAnalyticsConfiguration *oneTimeConfiguration;
85+
@end
86+
8387

8488
@implementation SEGIntegrationsManager
8589

@@ -88,7 +92,7 @@ @implementation SEGIntegrationsManager
8892

8993
- (instancetype _Nonnull)initWithAnalytics:(SEGAnalytics *_Nonnull)analytics
9094
{
91-
SEGAnalyticsConfiguration *configuration = analytics.configuration;
95+
SEGAnalyticsConfiguration *configuration = analytics.oneTimeConfiguration;
9296
NSCParameterAssert(configuration != nil);
9397

9498
if (self = [super init]) {

AnalyticsTests/AnalyticsTests.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ class AnalyticsTests: XCTestCase {
4444
}
4545

4646
func testInitializedCorrectly() {
47-
XCTAssertEqual(analytics.configuration.flushAt, 20)
48-
XCTAssertEqual(analytics.configuration.flushInterval, 30)
49-
XCTAssertEqual(analytics.configuration.maxQueueSize, 1000)
50-
XCTAssertEqual(analytics.configuration.writeKey, "QUI5ydwIGeFFTa1IvCBUhxL9PyW5B0jE")
51-
XCTAssertEqual(analytics.configuration.shouldUseLocationServices, false)
52-
XCTAssertEqual(analytics.configuration.enableAdvertisingTracking, true)
53-
XCTAssertEqual(analytics.configuration.shouldUseBluetooth, false)
54-
XCTAssertNil(analytics.configuration.httpSessionDelegate)
47+
XCTAssertEqual(config.flushAt, 20)
48+
XCTAssertEqual(config.flushInterval, 30)
49+
XCTAssertEqual(config.maxQueueSize, 1000)
50+
XCTAssertEqual(config.writeKey, "QUI5ydwIGeFFTa1IvCBUhxL9PyW5B0jE")
51+
XCTAssertEqual(config.shouldUseLocationServices, false)
52+
XCTAssertEqual(config.enableAdvertisingTracking, true)
53+
XCTAssertEqual(config.shouldUseBluetooth, false)
54+
XCTAssertNil(config.httpSessionDelegate)
5555
XCTAssertNotNil(analytics.getAnonymousId())
5656
}
5757

@@ -232,7 +232,7 @@ class AnalyticsTests: XCTestCase {
232232

233233
func testRedactsSensibleURLsFromDeepLinksTracking() {
234234
testMiddleware.swallowEvent = true
235-
analytics.configuration.trackDeepLinks = true
235+
config.trackDeepLinks = true
236236
analytics.open(URL(string: "fb123456789://authorize#access_token=hastoberedacted")!, options: [:])
237237

238238

@@ -243,8 +243,8 @@ class AnalyticsTests: XCTestCase {
243243

244244
func testRedactsSensibleURLsFromDeepLinksWithFilters() {
245245
testMiddleware.swallowEvent = true
246-
analytics.configuration.payloadFilters["(myapp://auth\\?token=)([^&]+)"] = "$1((redacted/my-auth))"
247-
analytics.configuration.trackDeepLinks = true
246+
config.payloadFilters["(myapp://auth\\?token=)([^&]+)"] = "$1((redacted/my-auth))"
247+
config.trackDeepLinks = true
248248
analytics.open(URL(string: "myapp://auth?token=hastoberedacted&other=stuff")!, options: [:])
249249

250250

AnalyticsTests/EndToEndTests.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import XCTest
44
class EndToEndTests: XCTestCase {
55

66
var analytics: Analytics!
7+
var configuration: AnalyticsConfiguration!
78

89
override func setUp() {
910
super.setUp()
1011

1112
// Write Key for https://app.segment.com/segment-libraries/sources/analytics_ios_e2e_test/overview
12-
let config = AnalyticsConfiguration(writeKey: "3VxTfPsVOoEOSbbzzbFqVNcYMNu2vjnr")
13-
config.flushAt = 1
13+
configuration = AnalyticsConfiguration(writeKey: "3VxTfPsVOoEOSbbzzbFqVNcYMNu2vjnr")
14+
configuration.flushAt = 1
1415

15-
Analytics.setup(with: config)
16+
Analytics.setup(with: configuration)
1617

1718
analytics = Analytics.shared()
1819
}
@@ -27,7 +28,7 @@ class EndToEndTests: XCTestCase {
2728
let uuid = UUID().uuidString
2829
let expectation = XCTestExpectation(description: "SegmentRequestDidSucceed")
2930

30-
Analytics.shared().configuration.experimental.rawSegmentModificationBlock = { data in
31+
configuration.experimental.rawSegmentModificationBlock = { data in
3132
if let properties = data["properties"] as? Dictionary<String, Any?>,
3233
let tempUUID = properties["id"] as? String, tempUUID == uuid {
3334
expectation.fulfill()

0 commit comments

Comments
 (0)