Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/zsh

# Set Project name
PROJECT_NAME="Segment-Package"

# set framework folder name
FRAMEWORK_FOLDER_NAME="${PROJECT_NAME}_XCFramework"

# set framework name or read it from project by this variable
FRAMEWORK_NAME="Segment"

#xcframework path
FRAMEWORK_PATH="${HOME}/Desktop/${FRAMEWORK_FOLDER_NAME}/${FRAMEWORK_NAME}.xcframework"

# set path for iOS simulator archive
SIMULATOR_ARCHIVE_PATH="${HOME}/Desktop/${FRAMEWORK_FOLDER_NAME}/simulator.xcarchive"

# set path for iOS device archive
IOS_DEVICE_ARCHIVE_PATH="${HOME}/Desktop/${FRAMEWORK_FOLDER_NAME}/iOS.xcarchive"

rm -rf "${HOME}/Desktop/${FRAMEWORK_FOLDER_NAME}"
echo "Deleted ${FRAMEWORK_FOLDER_NAME}"

mkdir "${HOME}/Desktop/${FRAMEWORK_FOLDER_NAME}"
echo "Created ${FRAMEWORK_FOLDER_NAME}"

echo "Archiving ${FRAMEWORK_NAME}"

xcodebuild archive -scheme ${PROJECT_NAME} -destination="iOS Simulator" -archivePath "${SIMULATOR_ARCHIVE_PATH}" -sdk iphonesimulator SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

xcodebuild archive -scheme ${PROJECT_NAME} -destination="iOS" -archivePath "${IOS_DEVICE_ARCHIVE_PATH}" -sdk iphoneos SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

#Creating XCFramework
xcodebuild -create-xcframework -framework ${SIMULATOR_ARCHIVE_PATH}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework -framework ${IOS_DEVICE_ARCHIVE_PATH}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework -output "${FRAMEWORK_PATH}"
rm -rf "${SIMULATOR_ARCHIVE_PATH}"
rm -rf "${IOS_DEVICE_ARCHIVE_PATH}"
open "${HOME}/Desktop/${FRAMEWORK_FOLDER_NAME}"
4 changes: 4 additions & 0 deletions Segment.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
967C40E3258D4DAF008EB0B6 /* Metrics_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967C40E2258D4DAF008EB0B6 /* Metrics_Tests.swift */; };
9692724E25A4E5B7009B5298 /* Startup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9692724D25A4E5B7009B5298 /* Startup.swift */; };
9692726825A583A6009B5298 /* SegmentDestination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9692726725A583A6009B5298 /* SegmentDestination.swift */; };
96A9668927BC137F00078F8B /* iOSLifecycle_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A9668827BC137F00078F8B /* iOSLifecycle_Tests.swift */; };
96C33A9C25880A5E00F3D538 /* SegmentLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C33A9B25880A5E00F3D538 /* SegmentLog.swift */; };
96C33AB1258961F500F3D538 /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C33AB0258961F500F3D538 /* Settings.swift */; };
96C95B16271DE22700C3EB9A /* LogTarget_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96C95B15271DE22600C3EB9A /* LogTarget_Tests.swift */; };
Expand Down Expand Up @@ -158,6 +159,7 @@
967C40ED259A7311008EB0B6 /* HTTPClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPClient.swift; sourceTree = "<group>"; };
9692724D25A4E5B7009B5298 /* Startup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Startup.swift; sourceTree = "<group>"; };
9692726725A583A6009B5298 /* SegmentDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentDestination.swift; sourceTree = "<group>"; };
96A9668827BC137F00078F8B /* iOSLifecycle_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSLifecycle_Tests.swift; sourceTree = "<group>"; };
96C33A9B25880A5E00F3D538 /* SegmentLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentLog.swift; sourceTree = "<group>"; };
96C33AB0258961F500F3D538 /* Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = "<group>"; };
96C95B15271DE22600C3EB9A /* LogTarget_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogTarget_Tests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -383,6 +385,7 @@
4621082D2609206D00EBC4A8 /* Support */,
96DBF37A26F39B5500724B0B /* Timeline_Tests.swift */,
OBJ_13 /* XCTestManifests.swift */,
96A9668827BC137F00078F8B /* iOSLifecycle_Tests.swift */,
);
name = "Segment-Tests";
path = "Tests/Segment-Tests";
Expand Down Expand Up @@ -588,6 +591,7 @@
4658175425BA4C20006B2809 /* HTTPClient_Tests.swift in Sources */,
46210811260538BE00EBC4A8 /* KeyPath_Tests.swift in Sources */,
967C40E3258D4DAF008EB0B6 /* Metrics_Tests.swift in Sources */,
96A9668927BC137F00078F8B /* iOSLifecycle_Tests.swift in Sources */,
96C95B16271DE22700C3EB9A /* LogTarget_Tests.swift in Sources */,
A31A16512576C47400C9CDDF /* JSON_Tests.swift in Sources */,
46FE4D1D25A7A850003A7362 /* Storage_Tests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class iOSLifecycleEvents: PlatformPlugin, iOSLifecycle {
let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
let currentBuild = Bundle.main.infoDictionary?["CFBundleVersion"] as? String

if previousBuild != nil {
if previousBuild == nil {
analytics?.track(name: "Application Installed", properties: [
"version": currentVersion ?? "",
"build": currentBuild ?? ""
Expand Down
2 changes: 2 additions & 0 deletions Tests/Segment-Tests/Support/TestUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class OutputReaderPlugin: Plugin {
let type: PluginType
var analytics: Analytics?

var events = [RawEvent]()
var lastEvent: RawEvent? = nil

init() {
Expand All @@ -116,6 +117,7 @@ class OutputReaderPlugin: Plugin {
func execute<T>(event: T?) -> T? where T : RawEvent {
lastEvent = event
if let t = lastEvent as? TrackEvent {
events.append(t)
print("EVENT: \(t.event)")
}
return event
Expand Down
66 changes: 66 additions & 0 deletions Tests/Segment-Tests/iOSLifecycle_Tests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import XCTest
@testable import Segment

final class iOSLifecycle_Tests: XCTestCase {

func testInstallEventCreation() {
let analytics = Analytics(configuration: Configuration(writeKey: "test"))
let outputReader = OutputReaderPlugin()
analytics.add(plugin: outputReader)

let iosLifecyclePlugin = iOSLifecycleEvents()
analytics.add(plugin: iosLifecyclePlugin)

waitUntilStarted(analytics: analytics)

UserDefaults.standard.setValue(nil, forKey: "SEGBuildKeyV2")

// This is a hack that needs to be dealt with
RunLoop.current.run(until: Date(timeIntervalSinceNow: 2))

iosLifecyclePlugin.application(nil, didFinishLaunchingWithOptions: nil)

let trackEvent: TrackEvent? = outputReader.events.first as? TrackEvent
XCTAssertTrue(trackEvent?.event == "Application Installed")
XCTAssertTrue(trackEvent?.type == "track")
}

func testInstallEventUpdated() {
let analytics = Analytics(configuration: Configuration(writeKey: "test"))
let outputReader = OutputReaderPlugin()
analytics.add(plugin: outputReader)

let iosLifecyclePlugin = iOSLifecycleEvents()
analytics.add(plugin: iosLifecyclePlugin)

waitUntilStarted(analytics: analytics)

UserDefaults.standard.setValue("1337", forKey: "SEGBuildKeyV2")

// This is a hack that needs to be dealt with
RunLoop.current.run(until: Date(timeIntervalSinceNow: 2))

iosLifecyclePlugin.application(nil, didFinishLaunchingWithOptions: nil)

let trackEvent: TrackEvent? = outputReader.events.first as? TrackEvent
XCTAssertTrue(trackEvent?.event == "Application Updated")
XCTAssertTrue(trackEvent?.type == "track")
}

func testInstallEventOpened() {
let analytics = Analytics(configuration: Configuration(writeKey: "test"))
let outputReader = OutputReaderPlugin()
analytics.add(plugin: outputReader)

let iosLifecyclePlugin = iOSLifecycleEvents()
analytics.add(plugin: iosLifecyclePlugin)

waitUntilStarted(analytics: analytics)

iosLifecyclePlugin.application(nil, didFinishLaunchingWithOptions: nil)

let trackEvent: TrackEvent? = outputReader.events.last as? TrackEvent
XCTAssertTrue(trackEvent?.event == "Application Opened")
XCTAssertTrue(trackEvent?.type == "track")
}
}