diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index a5e2f48e..fb681164 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -141,26 +141,4 @@ jobs: run: | cd Examples/apps/SegmentUIKitExample xcodebuild -workspace "SegmentUIKitExample.xcworkspace" -scheme "SegmentUIKitExample" -destination 'platform=macOS,variant=Mac Catalyst' - - - build_and_test_dest_examples: - needs: cancel_previous - runs-on: macos-11 - steps: - - uses: maxim-lobanov/setup-xcode@v1 - with: - xcode-version: latest-stable - - uses: actions/checkout@v2 - - uses: actions/cache@v2 - with: - path: /Users/runner/Library/Developer/Xcode/DerivedData - key: ${{ runner.os }}-spm-dest-example-${{ hashFiles('**/Package.resolved') }} - restore-keys: | - ${{ runner.os }}-spm-dest-example - - uses: webfactory/ssh-agent@v0.5.3 - with: - ssh-private-key: ${{ secrets.SOVRAN_SSH_KEY }} - - name: build for ios simulator - run: | - cd Examples/apps/DestinationsExample - xcodebuild -workspace "DestinationsExample.xcworkspace" -scheme "DestinationsExample" -sdk iphonesimulator + \ No newline at end of file diff --git a/Examples/apps/DestinationsExample/README.txt b/Examples/apps/DestinationsExample/README.txt new file mode 100644 index 00000000..4254242c --- /dev/null +++ b/Examples/apps/DestinationsExample/README.txt @@ -0,0 +1,2 @@ +This DestinationsExample app is not maintained. Please see the individual device mode +destination repos for up-to-date examples on usage. \ No newline at end of file diff --git a/Sources/Segment/ObjC/ObjCAnalytics.swift b/Sources/Segment/ObjC/ObjCAnalytics.swift index 62efa9d9..ce1750cc 100644 --- a/Sources/Segment/ObjC/ObjCAnalytics.swift +++ b/Sources/Segment/ObjC/ObjCAnalytics.swift @@ -63,8 +63,18 @@ extension ObjCAnalytics { /// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc. /// In the case when user logs out, make sure to call ``reset()`` to clear user's identity info. @objc(identify:traits:) - public func identify(userId: String, traits: [String: Any]?) { - analytics.identify(userId: userId, traits: traits) + public func identify(userId: String?, traits: [String: Any]?) { + if let userId = userId { + // at first glance this looks like recursion. It's actually calling + // into the swift version of this call where userId is NOT optional. + analytics.identify(userId: userId, traits: traits) + } else if let traits = try? JSON(traits as Any) { + analytics.store.dispatch(action: UserInfo.SetTraitsAction(traits: traits)) + let userInfo: UserInfo? = analytics.store.currentState() + let userId = userInfo?.userId + let event = IdentifyEvent(userId: userId, traits: traits) + analytics.process(incomingEvent: event) + } } /// Track a screen change with a title, category and other properties. diff --git a/Sources/Segment/State.swift b/Sources/Segment/State.swift index 249a3442..8c49b540 100644 --- a/Sources/Segment/State.swift +++ b/Sources/Segment/State.swift @@ -110,7 +110,7 @@ struct UserInfo: Codable, State { } struct SetUserIdAndTraitsAction: Action { - let userId: String + let userId: String? let traits: JSON? func reduce(state: UserInfo) -> UserInfo { diff --git a/Tests/Segment-Tests/ObjC_Tests.swift b/Tests/Segment-Tests/ObjC_Tests.swift index 4968f323..61f434ca 100644 --- a/Tests/Segment-Tests/ObjC_Tests.swift +++ b/Tests/Segment-Tests/ObjC_Tests.swift @@ -50,6 +50,8 @@ class ObjC_Tests: XCTestCase { config.defaultSettings = ["integrations": ["Amplitude": true]] let analytics = ObjCAnalytics(configuration: config) + analytics.reset() + analytics.identify(userId: "testPerson", traits: ["email" : "blah@blah.com"]) waitUntilStarted(analytics: analytics.analytics) @@ -63,6 +65,25 @@ class ObjC_Tests: XCTestCase { let traits = analytics.traits() XCTAssertTrue(traits != nil) XCTAssertTrue(traits?["email"] as? String == "blah@blah.com") + + let userId = analytics.userId + XCTAssertTrue(userId == "testPerson") + } + + func testTraitsAndUserIdOptionality() { + let config = ObjCConfiguration(writeKey: "WRITE_KEY") + let analytics = ObjCAnalytics(configuration: config) + analytics.reset() + + analytics.identify(userId: nil, traits: ["email" : "blah@blah.com"]) + + waitUntilStarted(analytics: analytics.analytics) + let userId = analytics.userId + XCTAssertNil(userId) + let traits = analytics.traits() + XCTAssertTrue(traits != nil) + XCTAssertTrue(traits?["email"] as? String == "blah@blah.com") + } }