diff --git a/.circleci/config.yml b/.circleci/config.yml index 958a1e18..619448ea 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -111,6 +111,11 @@ jobs: command: | cd Examples/apps/DestinationsExample xcodebuild -workspace "DestinationsExample.xcworkspace" -scheme "DestinationsExample" -sdk iphonesimulator + - run: + # build for ios simulator + command: | + cd Examples/apps/ObjCExample + xcodebuild -workspace "ObjCExample.xcworkspace" -scheme "ObjCExample" -sdk iphonesimulator - run: # build for ios simulator command: | diff --git a/Examples/apps/DestinationsExample/DestinationsExample.xcodeproj/project.pbxproj b/Examples/apps/DestinationsExample/DestinationsExample.xcodeproj/project.pbxproj index 52b279c1..4220055b 100644 --- a/Examples/apps/DestinationsExample/DestinationsExample.xcodeproj/project.pbxproj +++ b/Examples/apps/DestinationsExample/DestinationsExample.xcodeproj/project.pbxproj @@ -447,8 +447,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "git@github.com:flurry/FlurrySwiftPackage.git"; requirement = { - kind = upToNextMajorVersion; - minimumVersion = 11.2.1; + kind = exactVersion; + version = 11.2.1; }; }; 469F7B21266013100038E773 /* XCRemoteSwiftPackageReference "ios_sdk" */ = { diff --git a/Examples/apps/ObjCExample/ObjCExample.xcodeproj/project.pbxproj b/Examples/apps/ObjCExample/ObjCExample.xcodeproj/project.pbxproj new file mode 100644 index 00000000..0036027f --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample.xcodeproj/project.pbxproj @@ -0,0 +1,367 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 52; + objects = { + +/* Begin PBXBuildFile section */ + 464247BC26C6D7A700CAD301 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 464247BB26C6D7A700CAD301 /* AppDelegate.m */; }; + 464247BF26C6D7A700CAD301 /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 464247BE26C6D7A700CAD301 /* SceneDelegate.m */; }; + 464247C226C6D7A700CAD301 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 464247C126C6D7A700CAD301 /* ViewController.m */; }; + 464247C526C6D7A700CAD301 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 464247C326C6D7A700CAD301 /* Main.storyboard */; }; + 464247C726C6D7A800CAD301 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 464247C626C6D7A800CAD301 /* Assets.xcassets */; }; + 464247CA26C6D7A800CAD301 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 464247C826C6D7A800CAD301 /* LaunchScreen.storyboard */; }; + 464247CD26C6D7A800CAD301 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 464247CC26C6D7A800CAD301 /* main.m */; }; + 464247D526C6D7DC00CAD301 /* Segment in Frameworks */ = {isa = PBXBuildFile; productRef = 464247D426C6D7DC00CAD301 /* Segment */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 464247B726C6D7A700CAD301 /* ObjCExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ObjCExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 464247BA26C6D7A700CAD301 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 464247BB26C6D7A700CAD301 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 464247BD26C6D7A700CAD301 /* SceneDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SceneDelegate.h; sourceTree = ""; }; + 464247BE26C6D7A700CAD301 /* SceneDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SceneDelegate.m; sourceTree = ""; }; + 464247C026C6D7A700CAD301 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 464247C126C6D7A700CAD301 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 464247C426C6D7A700CAD301 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 464247C626C6D7A800CAD301 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 464247C926C6D7A800CAD301 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 464247CB26C6D7A800CAD301 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 464247CC26C6D7A800CAD301 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 464247B426C6D7A700CAD301 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 464247D526C6D7DC00CAD301 /* Segment in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 464247AE26C6D7A700CAD301 = { + isa = PBXGroup; + children = ( + 464247B926C6D7A700CAD301 /* ObjCExample */, + 464247B826C6D7A700CAD301 /* Products */, + 464247D326C6D7DC00CAD301 /* Frameworks */, + ); + sourceTree = ""; + }; + 464247B826C6D7A700CAD301 /* Products */ = { + isa = PBXGroup; + children = ( + 464247B726C6D7A700CAD301 /* ObjCExample.app */, + ); + name = Products; + sourceTree = ""; + }; + 464247B926C6D7A700CAD301 /* ObjCExample */ = { + isa = PBXGroup; + children = ( + 464247BA26C6D7A700CAD301 /* AppDelegate.h */, + 464247BB26C6D7A700CAD301 /* AppDelegate.m */, + 464247BD26C6D7A700CAD301 /* SceneDelegate.h */, + 464247BE26C6D7A700CAD301 /* SceneDelegate.m */, + 464247C026C6D7A700CAD301 /* ViewController.h */, + 464247C126C6D7A700CAD301 /* ViewController.m */, + 464247C326C6D7A700CAD301 /* Main.storyboard */, + 464247C626C6D7A800CAD301 /* Assets.xcassets */, + 464247C826C6D7A800CAD301 /* LaunchScreen.storyboard */, + 464247CB26C6D7A800CAD301 /* Info.plist */, + 464247CC26C6D7A800CAD301 /* main.m */, + ); + path = ObjCExample; + sourceTree = ""; + }; + 464247D326C6D7DC00CAD301 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 464247B626C6D7A700CAD301 /* ObjCExample */ = { + isa = PBXNativeTarget; + buildConfigurationList = 464247D026C6D7A800CAD301 /* Build configuration list for PBXNativeTarget "ObjCExample" */; + buildPhases = ( + 464247B326C6D7A700CAD301 /* Sources */, + 464247B426C6D7A700CAD301 /* Frameworks */, + 464247B526C6D7A700CAD301 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ObjCExample; + packageProductDependencies = ( + 464247D426C6D7DC00CAD301 /* Segment */, + ); + productName = ObjCExample; + productReference = 464247B726C6D7A700CAD301 /* ObjCExample.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 464247AF26C6D7A700CAD301 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1250; + TargetAttributes = { + 464247B626C6D7A700CAD301 = { + CreatedOnToolsVersion = 12.5.1; + }; + }; + }; + buildConfigurationList = 464247B226C6D7A700CAD301 /* Build configuration list for PBXProject "ObjCExample" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 464247AE26C6D7A700CAD301; + productRefGroup = 464247B826C6D7A700CAD301 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 464247B626C6D7A700CAD301 /* ObjCExample */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 464247B526C6D7A700CAD301 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 464247CA26C6D7A800CAD301 /* LaunchScreen.storyboard in Resources */, + 464247C726C6D7A800CAD301 /* Assets.xcassets in Resources */, + 464247C526C6D7A700CAD301 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 464247B326C6D7A700CAD301 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 464247C226C6D7A700CAD301 /* ViewController.m in Sources */, + 464247BC26C6D7A700CAD301 /* AppDelegate.m in Sources */, + 464247CD26C6D7A800CAD301 /* main.m in Sources */, + 464247BF26C6D7A700CAD301 /* SceneDelegate.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 464247C326C6D7A700CAD301 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 464247C426C6D7A700CAD301 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 464247C826C6D7A800CAD301 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 464247C926C6D7A800CAD301 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 464247CE26C6D7A800CAD301 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.5; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 464247CF26C6D7A800CAD301 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.5; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 464247D126C6D7A800CAD301 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = ObjCExample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.segment.ObjCExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 464247D226C6D7A800CAD301 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = ObjCExample/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.segment.ObjCExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 464247B226C6D7A700CAD301 /* Build configuration list for PBXProject "ObjCExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 464247CE26C6D7A800CAD301 /* Debug */, + 464247CF26C6D7A800CAD301 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 464247D026C6D7A800CAD301 /* Build configuration list for PBXNativeTarget "ObjCExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 464247D126C6D7A800CAD301 /* Debug */, + 464247D226C6D7A800CAD301 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCSwiftPackageProductDependency section */ + 464247D426C6D7DC00CAD301 /* Segment */ = { + isa = XCSwiftPackageProductDependency; + productName = Segment; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 464247AF26C6D7A700CAD301 /* Project object */; +} diff --git a/Examples/apps/ObjCExample/ObjCExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Examples/apps/ObjCExample/ObjCExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Examples/apps/ObjCExample/ObjCExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Examples/apps/ObjCExample/ObjCExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Examples/apps/ObjCExample/ObjCExample.xcworkspace/contents.xcworkspacedata b/Examples/apps/ObjCExample/ObjCExample.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..ed4c6383 --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/Examples/apps/ObjCExample/ObjCExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Examples/apps/ObjCExample/ObjCExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Examples/apps/ObjCExample/ObjCExample/AppDelegate.h b/Examples/apps/ObjCExample/ObjCExample/AppDelegate.h new file mode 100644 index 00000000..beae4528 --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample/AppDelegate.h @@ -0,0 +1,14 @@ +// +// AppDelegate.h +// ObjCExample +// +// Created by Brandon Sneed on 8/13/21. +// + +#import + +@interface AppDelegate : UIResponder + + +@end + diff --git a/Examples/apps/ObjCExample/ObjCExample/AppDelegate.m b/Examples/apps/ObjCExample/ObjCExample/AppDelegate.m new file mode 100644 index 00000000..3ea3371b --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample/AppDelegate.m @@ -0,0 +1,50 @@ +// +// AppDelegate.m +// ObjCExample +// +// Created by Brandon Sneed on 8/13/21. +// + +#import "AppDelegate.h" + +@import Segment; + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + SEGConfiguration *config = [[SEGConfiguration alloc] initWithWriteKey:@"WRITE_KEY"]; + config.trackApplicationLifecycleEvents = TRUE; + + SEGAnalytics *analytics = [[SEGAnalytics alloc] initWithConfiguration: config]; + + [analytics track:@"test"]; + [analytics track:@"testProps" properties:@{@"email": @"blah@blah.com"}]; + + return YES; +} + + +#pragma mark - UISceneSession lifecycle + + +- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role]; +} + + +- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet *)sceneSessions { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. +} + + +@end diff --git a/Examples/apps/ObjCExample/ObjCExample/Assets.xcassets/AccentColor.colorset/Contents.json b/Examples/apps/ObjCExample/ObjCExample/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 00000000..eb878970 --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Examples/apps/ObjCExample/ObjCExample/Assets.xcassets/AppIcon.appiconset/Contents.json b/Examples/apps/ObjCExample/ObjCExample/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..9221b9bb --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Examples/apps/ObjCExample/ObjCExample/Assets.xcassets/Contents.json b/Examples/apps/ObjCExample/ObjCExample/Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Examples/apps/ObjCExample/ObjCExample/Base.lproj/LaunchScreen.storyboard b/Examples/apps/ObjCExample/ObjCExample/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 00000000..865e9329 --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/apps/ObjCExample/ObjCExample/Base.lproj/Main.storyboard b/Examples/apps/ObjCExample/ObjCExample/Base.lproj/Main.storyboard new file mode 100644 index 00000000..808a21ce --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Examples/apps/ObjCExample/ObjCExample/Info.plist b/Examples/apps/ObjCExample/ObjCExample/Info.plist new file mode 100644 index 00000000..72bf2c4f --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample/Info.plist @@ -0,0 +1,66 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + SceneDelegate + UISceneStoryboardFile + Main + + + + + UIApplicationSupportsIndirectInputEvents + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/Examples/apps/ObjCExample/ObjCExample/SceneDelegate.h b/Examples/apps/ObjCExample/ObjCExample/SceneDelegate.h new file mode 100644 index 00000000..1fefa465 --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample/SceneDelegate.h @@ -0,0 +1,15 @@ +// +// SceneDelegate.h +// ObjCExample +// +// Created by Brandon Sneed on 8/13/21. +// + +#import + +@interface SceneDelegate : UIResponder + +@property (strong, nonatomic) UIWindow * window; + +@end + diff --git a/Examples/apps/ObjCExample/ObjCExample/SceneDelegate.m b/Examples/apps/ObjCExample/ObjCExample/SceneDelegate.m new file mode 100644 index 00000000..deeab08c --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample/SceneDelegate.m @@ -0,0 +1,57 @@ +// +// SceneDelegate.m +// ObjCExample +// +// Created by Brandon Sneed on 8/13/21. +// + +#import "SceneDelegate.h" + +@interface SceneDelegate () + +@end + +@implementation SceneDelegate + + +- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { + // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. + // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). +} + + +- (void)sceneDidDisconnect:(UIScene *)scene { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). +} + + +- (void)sceneDidBecomeActive:(UIScene *)scene { + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. +} + + +- (void)sceneWillResignActive:(UIScene *)scene { + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). +} + + +- (void)sceneWillEnterForeground:(UIScene *)scene { + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. +} + + +- (void)sceneDidEnterBackground:(UIScene *)scene { + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. +} + + +@end diff --git a/Examples/apps/ObjCExample/ObjCExample/ViewController.h b/Examples/apps/ObjCExample/ObjCExample/ViewController.h new file mode 100644 index 00000000..2551d85a --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample/ViewController.h @@ -0,0 +1,14 @@ +// +// ViewController.h +// ObjCExample +// +// Created by Brandon Sneed on 8/13/21. +// + +#import + +@interface ViewController : UIViewController + + +@end + diff --git a/Examples/apps/ObjCExample/ObjCExample/ViewController.m b/Examples/apps/ObjCExample/ObjCExample/ViewController.m new file mode 100644 index 00000000..f6ab4d1f --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample/ViewController.m @@ -0,0 +1,22 @@ +// +// ViewController.m +// ObjCExample +// +// Created by Brandon Sneed on 8/13/21. +// + +#import "ViewController.h" + +@interface ViewController () + +@end + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view. +} + + +@end diff --git a/Examples/apps/ObjCExample/ObjCExample/main.m b/Examples/apps/ObjCExample/ObjCExample/main.m new file mode 100644 index 00000000..d08e79bb --- /dev/null +++ b/Examples/apps/ObjCExample/ObjCExample/main.m @@ -0,0 +1,18 @@ +// +// main.m +// ObjCExample +// +// Created by Brandon Sneed on 8/13/21. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + NSString * appDelegateClassName; + @autoreleasepool { + // Setup code that might create autoreleased objects goes here. + appDelegateClassName = NSStringFromClass([AppDelegate class]); + } + return UIApplicationMain(argc, argv, nil, appDelegateClassName); +} diff --git a/Segment.xcodeproj/project.pbxproj b/Segment.xcodeproj/project.pbxproj index 30c218ce..53a19fc4 100644 --- a/Segment.xcodeproj/project.pbxproj +++ b/Segment.xcodeproj/project.pbxproj @@ -31,7 +31,6 @@ 46210811260538BE00EBC4A8 /* KeyPath_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46210810260538BE00EBC4A8 /* KeyPath_Tests.swift */; }; 46210836260BBEE400EBC4A8 /* DeviceToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46210835260BBEE400EBC4A8 /* DeviceToken.swift */; }; 4658175425BA4C20006B2809 /* HTTPClient_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4658175325BA4C20006B2809 /* HTTPClient_Tests.swift */; }; - 465879B72686554400180335 /* EventsObjC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 465879B62686554400180335 /* EventsObjC.swift */; }; 465879BA2686560C00180335 /* watchOSDelegation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 465879B82686560C00180335 /* watchOSDelegation.swift */; }; 465879BB2686560C00180335 /* watchOSLifecycleMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 465879B92686560C00180335 /* watchOSLifecycleMonitor.swift */; }; 4663C729267A799100ADDD1A /* QueueTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4663C728267A799100ADDD1A /* QueueTimer.swift */; }; @@ -40,6 +39,9 @@ 46A018DA25E97FDF00F9CCD8 /* AppleUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A018D925E97FDF00F9CCD8 /* AppleUtils.swift */; }; 46A018EE25E9A74F00F9CCD8 /* VendorSystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A018ED25E9A74F00F9CCD8 /* VendorSystem.swift */; }; 46E382E72654429A00BA2502 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46E382E62654429A00BA2502 /* Utils.swift */; }; + 46F7485D26C718710042798E /* ObjCAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F7485B26C718710042798E /* ObjCAnalytics.swift */; }; + 46F7485E26C718710042798E /* ObjCConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F7485C26C718710042798E /* ObjCConfiguration.swift */; }; + 46F7486026C720F60042798E /* ObjC_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46F7485F26C720F60042798E /* ObjC_Tests.swift */; }; 46FE4C9725A3F35E003A7362 /* macOSLifecycleMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46FE4C9625A3F35E003A7362 /* macOSLifecycleMonitor.swift */; }; 46FE4C9C25A3F41C003A7362 /* LinuxLifecycleMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46FE4C9B25A3F41C003A7362 /* LinuxLifecycleMonitor.swift */; }; 46FE4CE025A53FAD003A7362 /* Storage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46FE4CDF25A53FAD003A7362 /* Storage.swift */; }; @@ -112,7 +114,6 @@ 46210810260538BE00EBC4A8 /* KeyPath_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyPath_Tests.swift; sourceTree = ""; }; 46210835260BBEE400EBC4A8 /* DeviceToken.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceToken.swift; sourceTree = ""; }; 4658175325BA4C20006B2809 /* HTTPClient_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPClient_Tests.swift; sourceTree = ""; }; - 465879B62686554400180335 /* EventsObjC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventsObjC.swift; sourceTree = ""; }; 465879B82686560C00180335 /* watchOSDelegation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = watchOSDelegation.swift; sourceTree = ""; }; 465879B92686560C00180335 /* watchOSLifecycleMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = watchOSLifecycleMonitor.swift; sourceTree = ""; }; 4663C728267A799100ADDD1A /* QueueTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueueTimer.swift; sourceTree = ""; }; @@ -121,6 +122,9 @@ 46A018D925E97FDF00F9CCD8 /* AppleUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleUtils.swift; sourceTree = ""; }; 46A018ED25E9A74F00F9CCD8 /* VendorSystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VendorSystem.swift; sourceTree = ""; }; 46E382E62654429A00BA2502 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; + 46F7485B26C718710042798E /* ObjCAnalytics.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjCAnalytics.swift; sourceTree = ""; }; + 46F7485C26C718710042798E /* ObjCConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjCConfiguration.swift; sourceTree = ""; }; + 46F7485F26C720F60042798E /* ObjC_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjC_Tests.swift; sourceTree = ""; }; 46FE4C9625A3F35E003A7362 /* macOSLifecycleMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = macOSLifecycleMonitor.swift; sourceTree = ""; }; 46FE4C9B25A3F41C003A7362 /* LinuxLifecycleMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinuxLifecycleMonitor.swift; sourceTree = ""; }; 46FE4CDF25A53FAD003A7362 /* Storage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Storage.swift; sourceTree = ""; }; @@ -197,7 +201,8 @@ 465879B52686554400180335 /* ObjC */ = { isa = PBXGroup; children = ( - 465879B62686554400180335 /* EventsObjC.swift */, + 46F7485B26C718710042798E /* ObjCAnalytics.swift */, + 46F7485C26C718710042798E /* ObjCConfiguration.swift */, ); path = ObjC; sourceTree = ""; @@ -307,6 +312,7 @@ OBJ_12 /* Analytics_Tests.swift */, 4658175325BA4C20006B2809 /* HTTPClient_Tests.swift */, 46210810260538BE00EBC4A8 /* KeyPath_Tests.swift */, + 46F7485F26C720F60042798E /* ObjC_Tests.swift */, ); name = "Segment-Tests"; path = "Tests/Segment-Tests"; @@ -467,6 +473,7 @@ 46E382E72654429A00BA2502 /* Utils.swift in Sources */, A31A16B225781CB400C9CDDF /* JSON.swift in Sources */, 46022771261F7A4800A9E913 /* Atomic.swift in Sources */, + 46F7485D26C718710042798E /* ObjCAnalytics.swift in Sources */, A3471FBE256487F000965480 /* Configuration.swift in Sources */, OBJ_23 /* Analytics.swift in Sources */, A31A16342576B7AF00C9CDDF /* Types.swift in Sources */, @@ -474,10 +481,10 @@ A31A16E12579779600C9CDDF /* Version.swift in Sources */, 46210836260BBEE400EBC4A8 /* DeviceToken.swift in Sources */, 9692724E25A4E5B7009B5298 /* Startup.swift in Sources */, - 465879B72686554400180335 /* EventsObjC.swift in Sources */, 4663C729267A799100ADDD1A /* QueueTimer.swift in Sources */, 46FE4C9C25A3F41C003A7362 /* LinuxLifecycleMonitor.swift in Sources */, 460227422612987300A9E913 /* watchOSLifecycleEvents.swift in Sources */, + 46F7485E26C718710042798E /* ObjCConfiguration.swift in Sources */, A31A162F2576B73F00C9CDDF /* State.swift in Sources */, 9692726825A583A6009B5298 /* SegmentDestination.swift in Sources */, 4602276C261E7BF900A9E913 /* iOSDelegation.swift in Sources */, @@ -501,6 +508,7 @@ buildActionMask = 0; files = ( OBJ_30 /* Analytics_Tests.swift in Sources */, + 46F7486026C720F60042798E /* ObjC_Tests.swift in Sources */, OBJ_31 /* XCTestManifests.swift in Sources */, 4658175425BA4C20006B2809 /* HTTPClient_Tests.swift in Sources */, 46210811260538BE00EBC4A8 /* KeyPath_Tests.swift in Sources */, diff --git a/Sources/Segment/Configuration.swift b/Sources/Segment/Configuration.swift index 75a802b5..4af4ace4 100644 --- a/Sources/Segment/Configuration.swift +++ b/Sources/Segment/Configuration.swift @@ -22,7 +22,6 @@ public class Configuration { internal struct Values { var writeKey: String var application: Any? = nil - var trackInAppPurchases: Bool = false var trackApplicationLifecycleEvents: Bool = true var trackDeeplinks: Bool = true var flushAt: Int = 20 @@ -44,8 +43,8 @@ public class Configuration { public extension Configuration { @discardableResult - func trackInAppPurchases(_ enabled: Bool) -> Configuration { - values.trackInAppPurchases = enabled + func application(_ value: Any?) -> Configuration { + values.application = value return self } diff --git a/Sources/Segment/Events.swift b/Sources/Segment/Events.swift index a8163c48..dc9afb36 100644 --- a/Sources/Segment/Events.swift +++ b/Sources/Segment/Events.swift @@ -7,10 +7,9 @@ import Foundation +// MARK: - Typed Event Signatures + extension Analytics { - - // MARK: - Track - // make a note in the docs on this that we removed the old "options" property // and they need to write a middleware/enrichment now. // the objc version should accomodate them if it's really needed. @@ -35,13 +34,6 @@ extension Analytics { track(name: name, properties: nil as TrackEvent?) } - // MARK: - Identify - - // make a note in the docs on this that we removed the old "options" property - // and they need to write a middleware/enrichment now. - // the objc version should accomodate them if it's really needed. - - /// Associate a user with their unique ID and record traits about them. /// - Parameters: /// - userId: A database ID (or email address) for this user. If you don't have a userId @@ -56,6 +48,7 @@ extension Analytics { let event = IdentifyEvent(userId: userId, traits: jsonTraits) process(incomingEvent: event) } else { + store.dispatch(action: UserInfo.SetUserIdAndTraitsAction(userId: userId, traits: nil)) let event = IdentifyEvent(userId: userId, traits: nil) process(incomingEvent: event) } @@ -89,11 +82,6 @@ extension Analytics { process(incomingEvent: event) } - // MARK: - Screen - - // make a note in the docs on this that we removed the old "options" property - // and they need to write a middleware/enrichment now. - // the objc version should accomodate them if it's really needed. public func screen(screenTitle: String, category: String? = nil, properties: P?) { do { if let properties = properties { @@ -113,11 +101,6 @@ extension Analytics { screen(screenTitle: screenTitle, category: category, properties: nil as ScreenEvent?) } - // MARK: - Group - - // make a note in the docs on this that we removed the old "options" property - // and they need to write a middleware/enrichment now. - // the objc version should accomodate them if it's really needed. public func group(groupId: String, traits: T?) { do { if let traits = traits { @@ -137,12 +120,91 @@ extension Analytics { group(groupId: groupId, traits: nil as GroupEvent?) } - // MARK: - Alias public func alias(newId: String) { -// let userInfo: UserInfo? = store.currentState() - let event = AliasEvent(newId: newId) store.dispatch(action: UserInfo.SetUserIdAction(userId: newId)) process(incomingEvent: event) } } + +// MARK: - Untyped Event Signatures + +extension Analytics { + /// Associate a user with their unique ID and record traits about them. + /// - Parameters: + /// - userId: A database ID (or email address) for this user. If you don't have a userId + /// but want to record traits, you should pass nil. For more information on how we + /// generate the UUID and Apple's policies on IDs, see https://segment.io/libraries/ios#ids + /// - properties: A dictionary of traits you know about the user. Things like: email, name, plan, etc. + public func track(name: String, properties: [String: Any]? = nil) { + var props: JSON? = nil + if let properties = properties { + do { + props = try JSON(properties) + } catch { + exceptionFailure("\(error)") + } + } + let event = TrackEvent(event: name, properties: props) + process(incomingEvent: event) + } + + /// Associate a user with their unique ID and record traits about them. + /// - Parameters: + /// - userId: A database ID (or email address) for this user. If you don't have a userId + /// but want to record traits, you should pass nil. For more information on how we + /// generate the UUID and Apple's policies on IDs, see https://segment.io/libraries/ios#ids + /// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc. + public func identify(userId: String, traits: [String: AnyHashable]? = nil) { + do { + if let traits = traits { + let traits = try JSON(traits as Any) + store.dispatch(action: UserInfo.SetUserIdAndTraitsAction(userId: userId, traits: traits)) + let event = IdentifyEvent(userId: userId, traits: traits) + process(incomingEvent: event) + } else { + store.dispatch(action: UserInfo.SetUserIdAndTraitsAction(userId: userId, traits: nil)) + let event = IdentifyEvent(userId: userId, traits: nil) + process(incomingEvent: event) + } + + } catch { + exceptionFailure("Could not parse traits.") + } + } + + /// Track a screen change with a title, category and other properties. + /// - Parameters: + /// - screenTitle: The title of the screen being tracked. + /// - category: A category to the type of screen if it applies. + /// - properties: Any extra metadata associated with the screen. e.g. method of access, size, etc. + public func screen(screenTitle: String, category: String? = nil, properties: [String: AnyHashable]? = nil) { + var event = ScreenEvent(screenTitle: screenTitle, category: category, properties: nil) + if let properties = properties { + do { + let jsonProperties = try JSON(properties) + event = ScreenEvent(screenTitle: screenTitle, category: category, properties: jsonProperties) + } catch { + exceptionFailure("Could not parse properties.") + } + } + process(event: event) + } + + /// Associate a user with a group such as a company, organization, project, etc. + /// - Parameters: + /// - groupId: A unique identifier for the group identification in your system. + /// - traits: Traits of the group you may be interested in such as email, phone or name. + public func group(groupId: String, traits: [String: AnyHashable]?) { + var event = GroupEvent(groupId: groupId) + if let traits = traits { + do { + let jsonTraits = try JSON(traits) + event = GroupEvent(groupId: groupId, traits: jsonTraits) + } catch { + exceptionFailure("Could not parse traits.") + } + } + process(event: event) + } +} diff --git a/Sources/Segment/ObjC/EventsObjC.swift b/Sources/Segment/ObjC/EventsObjC.swift deleted file mode 100644 index 627912c1..00000000 --- a/Sources/Segment/ObjC/EventsObjC.swift +++ /dev/null @@ -1,122 +0,0 @@ -// -// File.swift -// -// -// Created by Cody Garvin on 6/10/21. -// - -#if !os(Linux) - -import Foundation - -// MARK: - Objective-C friendly methods -extension Analytics { - - // MARK: - Objective-C Track - - /// Associate a user with their unique ID and record traits about them. - /// - Parameters: - /// - userId: A database ID (or email address) for this user. If you don't have a userId - /// but want to record traits, you should pass nil. For more information on how we - /// generate the UUID and Apple's policies on IDs, see https://segment.io/libraries/ios#ids - /// - properties: A dictionary of traits you know about the user. Things like: email, name, plan, etc. - @objc - public func track(name: String, properties: [String: Any]?) { - var props: JSON? = nil - if let properties = properties { - do { - props = try JSON(properties) - } catch { - exceptionFailure("\(error)") - } - } - let event = TrackEvent(event: name, properties: props) - process(incomingEvent: event) - } - - - // MARK: - Objective-C Identify - - /// Associate a user with their unique ID and record traits about them. - /// - Parameters: - /// - userId: A database ID (or email address) for this user. If you don't have a userId - /// but want to record traits, you should pass nil. For more information on how we - /// generate the UUID and Apple's policies on IDs, see https://segment.io/libraries/ios#ids - /// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc. - @objc - public func identify(userId: String, traits: [String: AnyHashable]?) { - do { - if let traits = traits { - let traits = try JSON(traits as Any) - let event = IdentifyEvent(userId: userId, traits: traits) - process(incomingEvent: event) - } else { - let event = IdentifyEvent(userId: userId, traits: nil) - process(incomingEvent: event) - } - - } catch { - exceptionFailure("Could not parse traits.") - } - } - - /// Associate a user with traits about them. - /// - Parameters: - /// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc. - @objc - public func identify(traits: [String: AnyHashable]) { - do { - let traits = try JSON(traits as Any) - let event = IdentifyEvent(userId: nil, traits: traits) - process(event: event) - } catch { - exceptionFailure("Could not parse traits.") - } - } - - - // MARK: - Objective-C Screen - - /// Track a screen change with a title, category and other properties. - /// - Parameters: - /// - screenTitle: The title of the screen being tracked. - /// - category: A category to the type of screen if it applies. - /// - properties: Any extra metadata associated with the screen. e.g. method of access, size, etc. - @objc - public func screen(screenTitle: String, category: String? = nil, properties: [String: AnyHashable]?) { - var event = ScreenEvent(screenTitle: screenTitle, category: category, properties: nil) - if let properties = properties { - do { - let jsonProperties = try JSON(properties) - event = ScreenEvent(screenTitle: screenTitle, category: category, properties: jsonProperties) - } catch { - exceptionFailure("Could not parse properties.") - } - } - process(event: event) - } - - - // MARK: - Objective-C Group - - - /// Associate a user with a group such as a company, organization, project, etc. - /// - Parameters: - /// - groupId: A unique identifier for the group identification in your system. - /// - traits: Traits of the group you may be interested in such as email, phone or name. - @objc - public func group(groupId: String, traits: [String: AnyHashable]?) { - var event = GroupEvent(groupId: groupId) - if let traits = traits { - do { - let jsonTraits = try JSON(traits) - event = GroupEvent(groupId: groupId, traits: jsonTraits) - } catch { - exceptionFailure("Could not parse traits.") - } - } - process(event: event) - } -} - -#endif diff --git a/Sources/Segment/ObjC/ObjCAnalytics.swift b/Sources/Segment/ObjC/ObjCAnalytics.swift new file mode 100644 index 00000000..718650ef --- /dev/null +++ b/Sources/Segment/ObjC/ObjCAnalytics.swift @@ -0,0 +1,161 @@ +// +// File.swift +// +// +// Created by Cody Garvin on 6/10/21. +// + +#if !os(Linux) + +import Foundation + +// MARK: - ObjC Compatibility + +@objc(SEGAnalytics) +public class ObjCAnalytics: NSObject { + internal let analytics: Analytics + + @objc + public init(configuration: ObjCConfiguration) { + self.analytics = Analytics(configuration: configuration.configuration) + } +} + +// MARK: - ObjC Events + +@objc +extension ObjCAnalytics { + @objc(track:) + public func track(name: String) { + track(name: name, properties: nil) + } + + + @objc(track:properties:) + public func track(name: String, properties: [String: Any]?) { + analytics.track(name: name, properties: properties) + } + + /// Associate a user with their unique ID and record traits about them. + /// - Parameters: + /// - userId: A database ID (or email address) for this user. If you don't have a userId + /// but want to record traits, you should pass nil. For more information on how we + /// generate the UUID and Apple's policies on IDs, see https://segment.io/libraries/ios#ids + @objc(identify:) + public func identify(userId: String) { + identify(userId: userId, traits: nil) + } + + /// Associate a user with their unique ID and record traits about them. + /// - Parameters: + /// - userId: A database ID (or email address) for this user. If you don't have a userId + /// but want to record traits, you should pass nil. For more information on how we + /// generate the UUID and Apple's policies on IDs, see https://segment.io/libraries/ios#ids + /// - traits: A dictionary of traits you know about the user. Things like: email, name, plan, etc. + @objc(identify:traits:) + public func identify(userId: String, traits: [String: AnyHashable]?) { + analytics.identify(userId: userId, traits: traits) + } + + /// Track a screen change with a title, category and other properties. + /// - Parameters: + /// - screenTitle: The title of the screen being tracked. + @objc(screen:) + public func screen(screenTitle: String) { + screen(screenTitle: screenTitle, category: nil, properties: nil) + } + + /// Track a screen change with a title, category and other properties. + /// - Parameters: + /// - screenTitle: The title of the screen being tracked. + /// - category: A category to the type of screen if it applies. + @objc(screen:category:) + public func screen(screenTitle: String, category: String?) { + analytics.screen(screenTitle: screenTitle, category: category, properties: nil) + } + /// Track a screen change with a title, category and other properties. + /// - Parameters: + /// - screenTitle: The title of the screen being tracked. + /// - category: A category to the type of screen if it applies. + /// - properties: Any extra metadata associated with the screen. e.g. method of access, size, etc. + @objc(screen:category:properties:) + public func screen(screenTitle: String, category: String?, properties: [String: AnyHashable]?) { + analytics.screen(screenTitle: screenTitle, category: category, properties: properties) + } + + /// Associate a user with a group such as a company, organization, project, etc. + /// - Parameters: + /// - groupId: A unique identifier for the group identification in your system. + @objc(group:) + public func group(groupId: String) { + group(groupId: groupId, traits: nil) + } + + /// Associate a user with a group such as a company, organization, project, etc. + /// - Parameters: + /// - groupId: A unique identifier for the group identification in your system. + /// - traits: Traits of the group you may be interested in such as email, phone or name. + @objc(group:traits:) + public func group(groupId: String, traits: [String: AnyHashable]?) { + analytics.group(groupId: groupId, traits: traits) + } +} + +// MARK: - ObjC Peripheral Functionality + +@objc +extension ObjCAnalytics { + @objc + public var anonymousId: String { + return analytics.anonymousId + } + + @objc + public var userId: String? { + return analytics.userId + } + + @objc + public func traits() -> [String: Any]? { + var traits: [String: Any]? = nil + if let userInfo: UserInfo = analytics.store.currentState() { + traits = userInfo.traits?.dictionaryValue + } + return traits + } + + @objc + public func flush() { + analytics.flush() + } + + @objc + public func reset() { + analytics.reset() + } + + @objc + public func settings() -> [String: Any]? { + var result: [String: Any]? = nil + if let system: System = analytics.store.currentState() { + do { + let encoder = JSONEncoder() + let json = try encoder.encode(system.settings) + if let r = try JSONSerialization.jsonObject(with: json) as? [String: Any] { + result = r + } + } catch { + // not sure why this would fail, but report it. + exceptionFailure("Failed to convert Settings to ObjC dictionary: \(error)") + } + } + return result + } + + @objc + public func version() -> String { + return analytics.version() + } +} + +#endif diff --git a/Sources/Segment/ObjC/ObjCConfiguration.swift b/Sources/Segment/ObjC/ObjCConfiguration.swift new file mode 100644 index 00000000..14efc5b9 --- /dev/null +++ b/Sources/Segment/ObjC/ObjCConfiguration.swift @@ -0,0 +1,132 @@ +// +// File.swift +// +// +// Created by Brandon Sneed on 8/13/21. +// + +#if !os(Linux) + +import Foundation + +@objc(SEGConfiguration) +public class ObjCConfiguration: NSObject { + internal var configuration: Configuration + + @objc + public var application: Any? { + get { + return configuration.values.application + } + set(value) { + configuration.application(value) + } + } + + @objc + public var trackApplicationLifecycleEvents: Bool { + get { + return configuration.values.trackApplicationLifecycleEvents + } + set(value) { + configuration.trackApplicationLifecycleEvents(value) + } + } + + @objc + public var trackDeeplinks: Bool { + get { + return configuration.values.trackDeeplinks + } + set(value) { + configuration.trackDeeplinks(value) + } + } + + @objc + public var flushAt: Int { + get { + return configuration.values.flushAt + } + set(value) { + configuration.flushAt(value) + } + } + + @objc + public var flushInterval: TimeInterval { + get { + return configuration.values.flushInterval + } + set(value) { + configuration.flushInterval(value) + } + } + + @objc + public var defaultSettings: [String: Any] { + get { + var result = [String: Any]() + do { + let encoder = JSONEncoder() + let json = try encoder.encode(configuration.values.defaultSettings) + if let r = try JSONSerialization.jsonObject(with: json) as? [String: Any] { + result = r + } + } catch { + // not sure why this would fail, but report it. + exceptionFailure("Failed to convert Settings to ObjC dictionary: \(error)") + } + return result + } + set(value) { + do { + let json = try JSONSerialization.data(withJSONObject: value, options: .prettyPrinted) + let decoder = JSONDecoder() + let settings = try decoder.decode(Settings.self, from: json) + configuration.defaultSettings(settings) + } catch { + exceptionFailure("Failed to convert defaultSettings to Settings object: \(error)") + } + } + } + + @objc + public var autoAddSegmentDestination: Bool { + get { + return configuration.values.autoAddSegmentDestination + } + set(value) { + configuration.autoAddSegmentDestination(value) + } + } + + @objc + public var apiHost: String { + get { + return configuration.values.apiHost + } + set(value) { + configuration.apiHost(value) + } + } + + @objc + public var cdnHost: String { + get { + return configuration.values.cdnHost + } + set(value) { + configuration.cdnHost(value) + } + } + + + @objc + public init(writeKey: String) { + self.configuration = Configuration(writeKey: writeKey) + } +} + +#endif + diff --git a/Tests/Segment-Tests/ObjC_Tests.swift b/Tests/Segment-Tests/ObjC_Tests.swift new file mode 100644 index 00000000..a34147f2 --- /dev/null +++ b/Tests/Segment-Tests/ObjC_Tests.swift @@ -0,0 +1,63 @@ +// +// ObjC_Tests.swift +// Segment-Tests +// +// Created by Brandon Sneed on 8/13/21. +// + +#if !os(Linux) + +import XCTest +@testable import Segment + +class ObjC_Tests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + /* + + NOTE: These tests only cover non-trivial methods. Most ObjC methods pass straight through to their swift counterparts + however, there are some where some data conversion needs to happen in order to be made accessible. + + */ + + + func testNonTrivialConfiguration() { + let config = ObjCConfiguration(writeKey: "WRITE_KEY") + config.defaultSettings = ["integrations": ["Amplitude": true]] + + let defaults = config.defaultSettings + let integrations = defaults["integrations"] as? [String: Any] + + XCTAssertTrue(integrations != nil) + XCTAssertTrue(integrations?["Amplitude"] as? Bool == true) + } + + func testNonTrivialAnalytics() { + let config = ObjCConfiguration(writeKey: "WRITE_KEY") + config.defaultSettings = ["integrations": ["Amplitude": true]] + + let analytics = ObjCAnalytics(configuration: config) + analytics.identify(userId: "testPerson", traits: ["email" : "blah@blah.com"]) + + waitUntilStarted(analytics: analytics.analytics) + + let settings = analytics.settings() + let integrations = settings?["integrations"] as? [String: Any] + + XCTAssertTrue(integrations != nil) + XCTAssertTrue(integrations?["Amplitude"] as? Bool == true) + + let traits = analytics.traits() + XCTAssertTrue(traits != nil) + XCTAssertTrue(traits?["email"] as? String == "blah@blah.com") + } +} + +#endif