Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migs647/macconversion #918

Merged
merged 17 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version: 2

version: 2.1
jobs:
build_and_test:
macos:
Expand Down
22 changes: 19 additions & 3 deletions Analytics.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
630FC8EA2107F2A500A759C5 /* SEGScreenReporting.h in Headers */ = {isa = PBXBuildFile; fileRef = 5AF0EDFEDC0EE79A0A0EB713 /* SEGScreenReporting.h */; settings = {ATTRIBUTES = (Public, ); }; };
6E265C791FB1178C0030E08E /* IntegrationsManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E265C781FB1178C0030E08E /* IntegrationsManagerTest.swift */; };
6EEC1C712017EA370089C478 /* EndToEndTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EEC1C702017EA370089C478 /* EndToEndTests.swift */; };
96A12C2824B680DB00949804 /* NSViewController+SEGScreen.h in Headers */ = {isa = PBXBuildFile; fileRef = 96A12C2624B680DB00949804 /* NSViewController+SEGScreen.h */; };
96A12C2924B680DB00949804 /* NSViewController+SEGScreen.m in Sources */ = {isa = PBXBuildFile; fileRef = 96A12C2724B680DB00949804 /* NSViewController+SEGScreen.m */; };
9D8CE59023EE014E00197D0C /* CryptoTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADEB8E91DECD335005322DA /* CryptoTest.swift */; };
9D8CE59123EE014E00197D0C /* UserDefaultsStorageTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = EADEB8E61DECD335005322DA /* UserDefaultsStorageTest.swift */; };
9D8CE59223EE014E00197D0C /* TrackingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA542761EB4035400945DA7 /* TrackingTests.swift */; };
Expand Down Expand Up @@ -130,6 +132,8 @@
66058A0DB75544E7C2766C31 /* Pods_AnalyticsTestsTVOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AnalyticsTestsTVOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6E265C781FB1178C0030E08E /* IntegrationsManagerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegrationsManagerTest.swift; sourceTree = "<group>"; };
6EEC1C702017EA370089C478 /* EndToEndTests.swift */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = EndToEndTests.swift; sourceTree = "<group>"; tabWidth = 4; };
96A12C2624B680DB00949804 /* NSViewController+SEGScreen.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSViewController+SEGScreen.h"; sourceTree = "<group>"; };
96A12C2724B680DB00949804 /* NSViewController+SEGScreen.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSViewController+SEGScreen.m"; sourceTree = "<group>"; };
9D8CE5A723EE014E00197D0C /* AnalyticsTestsTVOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AnalyticsTestsTVOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
A31958EE2385AC3A00A47EFA /* SerializationTests.m */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = SerializationTests.m; sourceTree = "<group>"; tabWidth = 4; };
A34CC6DB249AAEBA00C5E368 /* SEGState.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SEGState.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -390,6 +394,8 @@
EADEB8A11DECD12B005322DA /* SEGUtils.m */,
EADEB8A21DECD12B005322DA /* UIViewController+SEGScreen.h */,
EADEB8A31DECD12B005322DA /* UIViewController+SEGScreen.m */,
96A12C2624B680DB00949804 /* NSViewController+SEGScreen.h */,
96A12C2724B680DB00949804 /* NSViewController+SEGScreen.m */,
);
path = Internal;
sourceTree = "<group>";
Expand Down Expand Up @@ -423,6 +429,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
96A12C2824B680DB00949804 /* NSViewController+SEGScreen.h in Headers */,
A34CC6DE249AAEBB00C5E368 /* SEGState.h in Headers */,
EADEB8DC1DECD12B005322DA /* SEGAnalytics.h in Headers */,
EADEB8B81DECD12B005322DA /* SEGIntegrationFactory.h in Headers */,
Expand Down Expand Up @@ -534,7 +541,7 @@
};
EADEB85A1DECD080005322DA = {
CreatedOnToolsVersion = 8.1;
ProvisioningStyle = Automatic;
ProvisioningStyle = Manual;
};
EADEB8691DECD0EF005322DA = {
CreatedOnToolsVersion = 8.1;
Expand Down Expand Up @@ -703,6 +710,7 @@
EADEB8BE1DECD12B005322DA /* SEGScreenPayload.m in Sources */,
EADEB8B61DECD12B005322DA /* SEGIdentifyPayload.m in Sources */,
EADEB8CE1DECD12B005322DA /* SEGSegmentIntegrationFactory.m in Sources */,
96A12C2924B680DB00949804 /* NSViewController+SEGScreen.m in Sources */,
EADEB8C01DECD12B005322DA /* SEGTrackPayload.m in Sources */,
EADEB8AF1DECD12B005322DA /* SEGAES256Crypto.m in Sources */,
EADEB8C81DECD12B005322DA /* SEGHTTPClient.m in Sources */,
Expand Down Expand Up @@ -922,7 +930,9 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Manual;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -931,9 +941,11 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.segment.Analytics;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos appletvsimulator";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos appletvsimulator macosx";
TARGETED_DEVICE_FAMILY = "1,2,3";
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -945,7 +957,9 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Manual;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -954,9 +968,11 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.segment.Analytics;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos appletvsimulator";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos appletvos appletvsimulator macosx";
TARGETED_DEVICE_FAMILY = "1,2,3";
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand Down
2 changes: 1 addition & 1 deletion Analytics/Classes/Analytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2016 Segment. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

//! Project version number for Analytics.
FOUNDATION_EXPORT double AnalyticsVersionNumber;
Expand Down
56 changes: 52 additions & 4 deletions Analytics/Classes/SEGAnalytics.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#import <objc/runtime.h>
#import <UIKit/UIKit.h>
#import "SEGAnalyticsUtils.h"
#import "SEGAnalytics.h"
#import "SEGIntegrationFactory.h"
#import "SEGIntegration.h"
#import "SEGSegmentIntegrationFactory.h"
#import "UIViewController+SEGScreen.h"
#import "NSViewController+SEGScreen.h"
#import "SEGStoreKitTracker.h"
#import "SEGHTTPClient.h"
#import "SEGStorage.h"
Expand Down Expand Up @@ -56,12 +56,12 @@ - (instancetype)initWithConfiguration:(SEGAnalyticsConfiguration *)configuration
self.runner = [[SEGMiddlewareRunner alloc] initWithMiddleware:
[configuration.sourceMiddleware ?: @[] arrayByAddingObject:self.integrationsManager]];

// Attach to application state change hooks
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

// Pass through for application state change events
id<SEGApplicationProtocol> application = configuration.application;
if (application) {
#if TARGET_OS_IPHONE
// Attach to application state change hooks
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
for (NSString *name in @[ UIApplicationDidEnterBackgroundNotification,
UIApplicationDidFinishLaunchingNotification,
UIApplicationWillEnterForegroundNotification,
Expand All @@ -70,18 +70,40 @@ - (instancetype)initWithConfiguration:(SEGAnalyticsConfiguration *)configuration
UIApplicationDidBecomeActiveNotification ]) {
[nc addObserver:self selector:@selector(handleAppStateNotification:) name:name object:application];
}
#elif TARGET_OS_OSX
// Attach to application state change hooks
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
for (NSString *name in @[ NSApplicationWillUnhideNotification,
NSApplicationDidFinishLaunchingNotification,
NSApplicationWillResignActiveNotification,
NSApplicationDidHideNotification,
NSApplicationDidBecomeActiveNotification,
NSApplicationWillTerminateNotification]) {
[nc addObserver:self selector:@selector(handleAppStateNotification:) name:name object:application];
}
#endif
}

#if TARGET_OS_IPHONE
if (configuration.recordScreenViews) {
[UIViewController seg_swizzleViewDidAppear];
}
#elif TARGET_OS_OSX
if (configuration.recordScreenViews) {
[NSViewController seg_swizzleViewDidAppear];
}
#endif
if (configuration.trackInAppPurchases) {
_storeKitTracker = [SEGStoreKitTracker trackTransactionsForAnalytics:self];
}

#if !TARGET_OS_TV
if (configuration.trackPushNotifications && configuration.launchOptions) {
#if TARGET_OS_IOS
NSDictionary *remoteNotification = configuration.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
#else
NSDictionary *remoteNotification = configuration.launchOptions[NSApplicationLaunchUserNotificationKey];
#endif
if (remoteNotification) {
[self trackPushNotification:remoteNotification fromLaunch:YES];
}
Expand All @@ -105,6 +127,7 @@ - (void)dealloc
NSString *const SEGBuildKeyV1 = @"SEGBuildKey";
NSString *const SEGBuildKeyV2 = @"SEGBuildKeyV2";

#if TARGET_OS_IPHONE
- (void)handleAppStateNotification:(NSNotification *)note
{
SEGApplicationLifecyclePayload *payload = [[SEGApplicationLifecyclePayload alloc] init];
Expand All @@ -119,6 +142,22 @@ - (void)handleAppStateNotification:(NSNotification *)note
[self _applicationDidEnterBackground];
}
}
#elif TARGET_OS_OSX
- (void)handleAppStateNotification:(NSNotification *)note
{
SEGApplicationLifecyclePayload *payload = [[SEGApplicationLifecyclePayload alloc] init];
payload.notificationName = note.name;
[self run:SEGEventTypeApplicationLifecycle payload:payload];

if ([note.name isEqualToString:NSApplicationDidFinishLaunchingNotification]) {
[self _applicationDidFinishLaunchingWithOptions:note.userInfo];
} else if ([note.name isEqualToString:NSApplicationWillUnhideNotification]) {
[self _applicationWillEnterForeground];
} else if ([note.name isEqualToString: NSApplicationDidHideNotification]) {
[self _applicationDidEnterBackground];
}
}
#endif

- (void)_applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Expand Down Expand Up @@ -153,13 +192,22 @@ - (void)_applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
}];
}

#if TARGET_OS_IPHONE
[self track:@"Application Opened" properties:@{
@"from_background" : @NO,
@"version" : currentVersion ?: @"",
@"build" : currentBuild ?: @"",
@"referring_application" : launchOptions[UIApplicationLaunchOptionsSourceApplicationKey] ?: @"",
@"url" : launchOptions[UIApplicationLaunchOptionsURLKey] ?: @"",
}];
#elif TARGET_OS_OSX
[self track:@"Application Opened" properties:@{
@"from_background" : @NO,
@"version" : currentVersion ?: @"",
@"build" : currentBuild ?: @"",
@"default_launch" : launchOptions[NSApplicationLaunchIsDefaultLaunchKey] ?: @(YES),
}];
#endif


[[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:SEGVersionKey];
Expand Down
17 changes: 16 additions & 1 deletion Analytics/Classes/SEGAnalyticsConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,33 @@
//

#import <Foundation/Foundation.h>

#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <Cocoa/Cocoa.h>
#endif

NS_SWIFT_NAME(ApplicationProtocol)
@protocol SEGApplicationProtocol <NSObject>

#if TARGET_OS_IPHONE
@property (nullable, nonatomic, assign) id<UIApplicationDelegate> delegate;
- (NSUInteger)seg_beginBackgroundTaskWithName:(nullable NSString *)taskName expirationHandler:(void (^__nullable)(void))handler;
- (void)seg_endBackgroundTask:(NSUInteger)identifier;
#elif TARGET_OS_OSX
@property (nullable, nonatomic, assign) id<NSApplicationDelegate> delegate;
#endif
@end


#if TARGET_OS_IOS
@interface UIApplication (SEGApplicationProtocol) <SEGApplicationProtocol>
@end
#elif TARGET_OS_OSX
@interface NSApplication (SEGApplicationProtocol) <SEGApplicationProtocol>
@end
#endif


typedef NSMutableURLRequest *_Nonnull (^SEGRequestFactory)(NSURL *_Nonnull);
typedef NSString *_Nonnull (^SEGAdSupportBlock)(void);
Expand Down
13 changes: 12 additions & 1 deletion Analytics/Classes/SEGAnalyticsConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
#import "SEGAnalyticsConfiguration.h"
#import "SEGAnalytics.h"
#import "SEGCrypto.h"
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <Cocoa/Cocoa.h>
#endif


#if TARGET_OS_IPHONE
@implementation UIApplication (SEGApplicationProtocol)

- (UIBackgroundTaskIdentifier)seg_beginBackgroundTaskWithName:(nullable NSString *)taskName expirationHandler:(void (^__nullable)(void))handler
Expand All @@ -25,6 +29,7 @@ - (void)seg_endBackgroundTask:(UIBackgroundTaskIdentifier)identifier
}

@end
#endif

@implementation SEGAnalyticsExperimental
@end
Expand Down Expand Up @@ -67,9 +72,15 @@ - (instancetype)init
@"(fb\\d+://authorize#access_token=)([^ ]+)": @"$1((redacted/fb-auth-token))"
};
_factories = [NSMutableArray array];
#if TARGET_OS_IPHONE
if ([UIApplication respondsToSelector:@selector(sharedApplication)]) {
_application = [UIApplication performSelector:@selector(sharedApplication)];
}
#elif TARGET_OS_OSX
if ([NSApplication respondsToSelector:@selector(sharedApplication)]) {
_application = [NSApplication performSelector:@selector(sharedApplication)];
}
#endif
}
return self;
}
Expand Down
12 changes: 11 additions & 1 deletion Analytics/Classes/SEGScreenReporting.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#if TARGET_OS_IPHONE
#import <UIKit/UIKit.h>
#elif TARGET_OS_OSX
#import <Cocoa/Cocoa.h>
#endif

#import "SEGSerializableValue.h"

/** Implement this protocol to override automatic screen reporting
Expand All @@ -8,8 +13,13 @@ NS_ASSUME_NONNULL_BEGIN

@protocol SEGScreenReporting
@optional
-(void) seg_trackScreen:(UIViewController*)screen name:(NSString*)name;
#if TARGET_OS_IPHONE
- (void)seg_trackScreen:(UIViewController*)screen name:(NSString*)name;
@property (readonly, nullable) UIViewController *seg_mainViewController;
#elif TARGET_OS_OSX
- (void)seg_trackScreen:(NSViewController*)screen name:(NSString*)name;
@property (readonly, nullable) NSViewController *seg_mainViewController;
#endif
@end

NS_ASSUME_NONNULL_END
Expand Down
Loading