Skip to content

Commit 90d0956

Browse files
authored
Merge pull request #283 from IFTTT/bugfix/multi_device_sync_fixes
Fixing location event updating for multiple devices
2 parents 24812a9 + e105c01 commit 90d0956

10 files changed

Lines changed: 14 additions & 38 deletions

File tree

Examples/Examples.xcodeproj/project.pbxproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,7 @@
349349
isa = XCBuildConfiguration;
350350
buildSettings = {
351351
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
352-
CODE_SIGN_STYLE = Manual;
353352
CURRENT_PROJECT_VERSION = 35;
354-
DEVELOPMENT_TEAM = "";
355353
INFOPLIST_FILE = GroceryExpress/Info.plist;
356354
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
357355
LD_RUNPATH_SEARCH_PATHS = (
@@ -360,7 +358,6 @@
360358
);
361359
PRODUCT_BUNDLE_IDENTIFIER = com.ifttt.sdk.example;
362360
PRODUCT_NAME = "$(TARGET_NAME)";
363-
PROVISIONING_PROFILE_SPECIFIER = "";
364361
SWIFT_VERSION = 5.0;
365362
TARGETED_DEVICE_FAMILY = "1,2";
366363
};

IFTTT SDK/ConnectionsMonitor.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ class ConnectionsMonitor: SynchronizationSubscriber {
6464
let startingCount = connections.count
6565

6666
let completionOperation = BlockOperation {
67-
DispatchQueue.main.async {
68-
completion(self.connectionsRegistry.getConnectionsCount() == startingCount, error)
69-
}
67+
completion(self.connectionsRegistry.getConnectionsCount() == startingCount, error)
7068
}
7169

7270
let credentialProvider = UserAuthenticatedRequestCredentialProvider()

IFTTT SDK/ConnectionsSynchronizer.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,7 @@ private class NativeServicesCoordinator {
296296
}
297297

298298
func processConnectionUpdate(_ updates: Set<Connection.ConnectionStorage>) {
299-
DispatchQueue.main.async {
300-
self.permissionsRequestor.processUpdate(with: updates)
301-
self.locationService.updateRegions(from: updates)
302-
}
299+
permissionsRequestor.processUpdate(with: updates)
300+
locationService.updateRegions(from: updates)
303301
}
304302
}

IFTTT SDK/LocationService.swift

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class RegionEventsSessionManager {
118118
if retryCount < numberOfRetries {
119119
let count = retryCount + 1
120120
ConnectButtonController.synchronizationLog("Failed to upload region events: \(events). Will retry \(numberOfRetries - retryCount) more times.")
121+
121122
DispatchQueue.main.asyncAfter(deadline: .now() + self.exponentialBackoffTiming(for: count)) {
122123
self.upload(events: events,
123124
credentialProvider: credentialProvider,
@@ -186,8 +187,6 @@ final class LocationService: NSObject, SynchronizationSubscriber {
186187
private let sessionManager: RegionEventsSessionManager
187188
/// The `EventPublisher<SynchronizationTriggerEvent>` that handles publishing synchronization events to listeners
188189
private let regionEventTriggerPublisher: EventPublisher<SynchronizationTriggerEvent>
189-
/// Determines whether or not a 0.1 second delay should be applied before publishing synchronization events
190-
private let applyDelayOnSyncTrigger: Bool
191190

192191
struct Constants {
193192
static let SanityThreshold = 20
@@ -201,21 +200,18 @@ final class LocationService: NSObject, SynchronizationSubscriber {
201200
/// - connectionsRegistry: An instance of `ConnectionsRegistry` that determines which connections are currently being monitored by the SDK.
202201
/// - sessionManager: An instance of `RegionEventsSessionManager` that uploads region events to the backend.
203202
/// - eventPublisher: An instance of `EventPublisher<SynchronizationTriggerEvent>` that handles publishing sync events to listeners.
204-
/// - applyDelayOnSyncTrigger: Determines whether or not a 0.1 second delay should be applied to trigger syncs. Defaults to `true`.
205203
/// - Returns: An initialized instance of `LocationService`.
206204
init(regionsMonitor: RegionsMonitor,
207205
regionEventsRegistry: RegionEventsRegistry,
208206
connectionsRegistry: ConnectionsRegistry,
209207
sessionManager: RegionEventsSessionManager,
210-
eventPublisher: EventPublisher<SynchronizationTriggerEvent>,
211-
applyDelayOnSyncTrigger: Bool = true) {
208+
eventPublisher: EventPublisher<SynchronizationTriggerEvent>) {
212209
self.regionsMonitor = regionsMonitor
213210
self.regionEventsRegistry = regionEventsRegistry
214211
self.connectionsRegistry = connectionsRegistry
215212
self.sessionManager = sessionManager
216213
self.regionEventTriggerPublisher = eventPublisher
217214

218-
self.applyDelayOnSyncTrigger = applyDelayOnSyncTrigger
219215
super.init()
220216
}
221217

@@ -275,21 +271,14 @@ final class LocationService: NSObject, SynchronizationSubscriber {
275271
let event = RegionEvent(kind: kind, triggerSubscriptionId: region.identifier)
276272
regionEventsRegistry.add(event)
277273

278-
let closure = {
279-
let event = SynchronizationTriggerEvent(source: .regionsUpdate,
280-
completionHandler: nil)
281-
282-
self.regionEventTriggerPublisher.onNext(event)
283-
284-
if let backgroundTaskIdentifier = backgroundTaskIdentifier, backgroundTaskIdentifier != UIBackgroundTaskIdentifier.invalid {
285-
UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
286-
}
287-
}
288-
289-
if applyDelayOnSyncTrigger {
290-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1, execute: closure)
291-
} else {
292-
closure()
274+
let triggerEvent = SynchronizationTriggerEvent(source: .regionsUpdate,
275+
completionHandler: nil)
276+
277+
self.regionEventTriggerPublisher.onNext(triggerEvent)
278+
279+
if let backgroundTaskIdentifier = backgroundTaskIdentifier,
280+
backgroundTaskIdentifier != UIBackgroundTaskIdentifier.invalid {
281+
UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
293282
}
294283
}
295284

SDKHostApp/AppDelegate.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// AppDelegate.swift
33
// SDKHostApp
44
//
5-
// Created by Siddharth Sathyam on 12/11/20.
65
// Copyright © 2020 IFTTT. All rights reserved.
76
//
87

SDKHostApp/ContentView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// ContentView.swift
33
// SDKHostApp
44
//
5-
// Created by Siddharth Sathyam on 12/11/20.
65
// Copyright © 2020 IFTTT. All rights reserved.
76
//
87

SDKHostApp/SceneDelegate.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SceneDelegate.swift
33
// SDKHostApp
44
//
5-
// Created by Siddharth Sathyam on 12/11/20.
65
// Copyright © 2020 IFTTT. All rights reserved.
76
//
87

SDKHostAppTests/ArrayHelpersTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// ArrayHelpersTests.swift
33
// SDKHostAppTests
44
//
5-
// Created by Siddharth Sathyam on 12/14/20.
65
// Copyright © 2020 IFTTT. All rights reserved.
76
//
87

SDKHostAppTests/LocationServiceTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class LocationServiceTests: XCTestCase {
4242
connectionsRegistry: connectionsRegistry,
4343
sessionManager: .init(networkController: regionEventsController,
4444
regionEventsRegistry: regionEventsRegistry),
45-
eventPublisher: eventPublisher,
46-
applyDelayOnSyncTrigger: false)
45+
eventPublisher: eventPublisher)
4746
}
4847

4948
override func tearDown() {

SDKHostAppUITests/SDKHostAppUITests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SDKHostAppUITests.swift
33
// SDKHostAppUITests
44
//
5-
// Created by Siddharth Sathyam on 12/11/20.
65
// Copyright © 2020 IFTTT. All rights reserved.
76
//
87

0 commit comments

Comments
 (0)