Skip to content

Commit 3eeccfc

Browse files
bsneedBrandon Sneed
andauthored
Added type enum param to update(settings:) (#53)
Co-authored-by: Brandon Sneed <[email protected]>
1 parent c62a45a commit 3eeccfc

File tree

13 files changed

+98
-28
lines changed

13 files changed

+98
-28
lines changed

Examples/destination_plugins/AdjustDestination.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ class AdjustDestination: NSObject, DestinationPlugin, RemoteNotifications {
5555

5656
internal var settings: AdjustSettings? = nil
5757

58-
public func update(settings: Settings) {
58+
public func update(settings: Settings, type: UpdateType) {
59+
// we've already set up this singleton SDK, can't do it again, so skip.
60+
guard type == .initial else { return }
61+
5962
guard let settings: AdjustSettings = settings.integrationSettings(forPlugin: self) else { return }
6063
self.settings = settings
6164

Examples/destination_plugins/AmplitudeSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class AmplitudeSession: EventPlugin, iOSLifecycle {
5252
private var sessionID: TimeInterval?
5353
private let fireTime = TimeInterval(300)
5454

55-
func update(settings: Settings) {
55+
func update(settings: Settings, type: UpdateType) {
5656
if settings.isDestinationEnabled(key: key) {
5757
active = true
5858
} else {

Examples/destination_plugins/AppsFlyerDestination.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ class AppsFlyerDestination: UIResponder, DestinationPlugin {
5454

5555
fileprivate var settings: AppsFlyerSettings? = nil
5656

57-
public func update(settings: Settings) {
57+
public func update(settings: Settings, type: UpdateType) {
58+
// we've already set up this singleton SDK, can't do it again, so skip.
59+
guard type == .initial else { return }
60+
5861
guard let settings: AppsFlyerSettings = settings.integrationSettings(forPlugin: self) else { return }
5962
self.settings = settings
6063

Examples/destination_plugins/FirebaseDestination.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ class FirebaseDestination: DestinationPlugin {
5353
let key = "Firebase"
5454
var analytics: Segment.Analytics? = nil
5555

56-
func update(settings: Settings) {
56+
func update(settings: Settings, type: UpdateType) {
57+
// we've already set up this singleton SDK, can't do it again, so skip.
58+
guard type == .initial else { return }
59+
5760
guard let firebaseSettings: FirebaseSettings = settings.integrationSettings(forPlugin: self) else { return }
5861
if let deepLinkURLScheme = firebaseSettings.deepLinkURLScheme {
5962
FirebaseOptions.defaultOptions()?.deepLinkURLScheme = deepLinkURLScheme

Examples/destination_plugins/FlurryDestination.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ class FlurryDestination: DestinationPlugin {
5757

5858
var screenTracksEvents = false
5959

60-
func update(settings: Settings) {
60+
func update(settings: Settings, type: UpdateType) {
61+
// we've already set up this singleton SDK, can't do it again, so skip.
62+
guard type == .initial else { return }
63+
6164
guard let flurrySettings: FlurrySettings = settings.integrationSettings(forPlugin: self) else { return }
6265

6366
let builder = FlurrySessionBuilder()

Examples/destination_plugins/MixpanelDestination.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class MixpanelDestination: DestinationPlugin, RemoteNotifications {
4747
private var mixpanel: MixpanelInstance? = nil
4848
private var settings: [String: Any]? = nil
4949

50-
func update(settings: Settings) {
50+
func update(settings: Settings, type: UpdateType) {
51+
// we've already set up this singleton SDK, can't do it again, so skip.
52+
guard type == .initial else { return }
5153

5254
// If we have a mixpanel instance, dump all the data first
5355
mixpanel?.flush()

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,18 +301,19 @@ class AppsFlyerDestination: UIResponder, DestinationPlugin, UserActivities, Remo
301301
analytics?.track(name: "AppsFlyer Loaded")
302302
}
303303

304-
public func update(settings: Settings) {
305-
306-
guard let settings: AppsFlyerSettings = settings.integrationSettings(name: "AppsFlyer") else {return}
307-
self.settings = settings
304+
public func update(settings: Settings, type: UpdateType) {
305+
if type == .initial {
306+
// AppsFlyerLib is a singleton, we only want to set it up once.
307+
guard let settings: AppsFlyerSettings = settings.integrationSettings(name: "AppsFlyer") else {return}
308+
self.settings = settings
309+
310+
AppsFlyerLib.shared().appsFlyerDevKey = settings.appsFlyerDevKey
311+
AppsFlyerLib.shared().appleAppID = settings.appleAppID
312+
AppsFlyerLib.shared().isDebug = true
313+
AppsFlyerLib.shared().deepLinkDelegate = self
314+
}
308315

309-
310-
AppsFlyerLib.shared().appsFlyerDevKey = settings.appsFlyerDevKey
311-
AppsFlyerLib.shared().appleAppID = settings.appleAppID
312-
AppsFlyerLib.shared().isDebug = true
313-
AppsFlyerLib.shared().deepLinkDelegate = self
314-
315-
// additional update logic
316+
// additional update logic
316317
}
317318

318319
// ...

Segment.xcodeproj/project.pbxproj

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@
121121
46A018D325E6C9C200F9CCD8 /* LinuxUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxUtils.swift; sourceTree = "<group>"; };
122122
46A018D925E97FDF00F9CCD8 /* AppleUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleUtils.swift; sourceTree = "<group>"; };
123123
46A018ED25E9A74F00F9CCD8 /* VendorSystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VendorSystem.swift; sourceTree = "<group>"; };
124+
46D98E3D26D6FEF300E7A86A /* FlurryDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlurryDestination.swift; sourceTree = "<group>"; };
125+
46D98E3E26D6FEF300E7A86A /* AdjustDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdjustDestination.swift; sourceTree = "<group>"; };
126+
46D98E3F26D6FEF300E7A86A /* MixpanelDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MixpanelDestination.swift; sourceTree = "<group>"; };
127+
46D98E4026D6FEF300E7A86A /* AppsFlyerDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppsFlyerDestination.swift; sourceTree = "<group>"; };
128+
46D98E4126D6FEF300E7A86A /* FirebaseDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseDestination.swift; sourceTree = "<group>"; };
129+
46D98E4226D6FEF300E7A86A /* AmplitudeSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AmplitudeSession.swift; sourceTree = "<group>"; };
130+
46D98E4426D6FEF300E7A86A /* UIKitScreenTracking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitScreenTracking.swift; sourceTree = "<group>"; };
131+
46D98E4526D6FEF300E7A86A /* ConsentTracking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsentTracking.swift; sourceTree = "<group>"; };
132+
46D98E4626D6FEF300E7A86A /* IDFACollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IDFACollection.swift; sourceTree = "<group>"; };
133+
46D98E4726D6FEF300E7A86A /* ConsoleLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsoleLogger.swift; sourceTree = "<group>"; };
124134
46E382E62654429A00BA2502 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
125135
46F7485B26C718710042798E /* ObjCAnalytics.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjCAnalytics.swift; sourceTree = "<group>"; };
126136
46F7485C26C718710042798E /* ObjCConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjCConfiguration.swift; sourceTree = "<group>"; };
@@ -217,6 +227,41 @@
217227
path = Vendors;
218228
sourceTree = "<group>";
219229
};
230+
46D98E3B26D6FED300E7A86A /* Examples */ = {
231+
isa = PBXGroup;
232+
children = (
233+
46D98E3C26D6FEF300E7A86A /* destination_plugins */,
234+
46D98E4326D6FEF300E7A86A /* other_plugins */,
235+
);
236+
name = Examples;
237+
sourceTree = "<group>";
238+
};
239+
46D98E3C26D6FEF300E7A86A /* destination_plugins */ = {
240+
isa = PBXGroup;
241+
children = (
242+
46D98E3D26D6FEF300E7A86A /* FlurryDestination.swift */,
243+
46D98E3E26D6FEF300E7A86A /* AdjustDestination.swift */,
244+
46D98E3F26D6FEF300E7A86A /* MixpanelDestination.swift */,
245+
46D98E4026D6FEF300E7A86A /* AppsFlyerDestination.swift */,
246+
46D98E4126D6FEF300E7A86A /* FirebaseDestination.swift */,
247+
46D98E4226D6FEF300E7A86A /* AmplitudeSession.swift */,
248+
);
249+
name = destination_plugins;
250+
path = Examples/destination_plugins;
251+
sourceTree = "<group>";
252+
};
253+
46D98E4326D6FEF300E7A86A /* other_plugins */ = {
254+
isa = PBXGroup;
255+
children = (
256+
46D98E4426D6FEF300E7A86A /* UIKitScreenTracking.swift */,
257+
46D98E4526D6FEF300E7A86A /* ConsentTracking.swift */,
258+
46D98E4626D6FEF300E7A86A /* IDFACollection.swift */,
259+
46D98E4726D6FEF300E7A86A /* ConsoleLogger.swift */,
260+
);
261+
name = other_plugins;
262+
path = Examples/other_plugins;
263+
sourceTree = "<group>";
264+
};
220265
96208624256DC23F00314F8D /* Frameworks */ = {
221266
isa = PBXGroup;
222267
children = (
@@ -330,6 +375,7 @@
330375
OBJ_5 = {
331376
isa = PBXGroup;
332377
children = (
378+
46D98E3B26D6FED300E7A86A /* Examples */,
333379
OBJ_7 /* Sources */,
334380
OBJ_10 /* Tests */,
335381
OBJ_6 /* Package.swift */,

Sources/Segment/Plugins.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ public enum PluginType: Int, CaseIterable {
2323
case utility
2424
}
2525

26+
public enum UpdateType {
27+
case initial
28+
case refresh
29+
}
30+
2631
public protocol Plugin: AnyObject {
2732
var type: PluginType { get }
2833
var analytics: Analytics? { get set }
2934

3035
func configure(analytics: Analytics)
31-
func update(settings: Settings)
36+
func update(settings: Settings, type: UpdateType)
3237
func execute<T: RawEvent>(event: T?) -> T?
3338
func shutdown()
3439
}

Sources/Segment/Plugins/SegmentDestination.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class SegmentDestination: DestinationPlugin {
5959
}
6060
}
6161

62-
public func update(settings: Settings) {
62+
public func update(settings: Settings, type: UpdateType) {
6363
let segmentInfo = settings.integrationSettings(forKey: self.key)
6464
apiKey = segmentInfo?[Self.Constants.apiKey.rawValue] as? String
6565
apiHost = segmentInfo?[Self.Constants.apiHost.rawValue] as? String

0 commit comments

Comments
 (0)