diff --git a/.travis.yml b/.travis.yml index fcbbf2f69..a58c21b4c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ language: objective-c before_install: - - gem install cocoapods -v 1.3.1 -osx_image: xcode9.3 + - gem uninstall cocoapods --force -a -q -I -x + - gem install cocoapods -v 1.4.0 +osx_image: xcode10 branches: only: - master @@ -10,8 +11,8 @@ env: - WORKSPACE="HelloMixpanel/HelloMixpanel.xcworkspace" - SCHEME="[iOS] HelloMixpanel" matrix: - - DESTINATION="OS=10.0,name=iPhone 7" RUN_TESTS="YES" POD_LINT="YES" - - DESTINATION="OS=11.1,name=iPhone X" RUN_TESTS="YES" POD_LINT="NO" + - DESTINATION="OS=10.0,name=iPhone 5s" RUN_TESTS="YES" POD_LINT="YES" + - DESTINATION="OS=12.0,name=iPhone X" RUN_TESTS="YES" POD_LINT="YES" podfile: HelloMixpanel/podfile script: - set -o pipefail @@ -25,5 +26,5 @@ script: # Run `pod lib lint` if specified # allow warnings while surveys are deprecated but not yet removed. disallow them again later - if [ $POD_LINT == "YES" ]; then - pod lib lint --allow-warnings; + pod lib lint --allow-warnings --no-clean; fi diff --git a/HelloMixpanel/HelloMixpanel.xcodeproj/project.pbxproj b/HelloMixpanel/HelloMixpanel.xcodeproj/project.pbxproj index 425774fc8..5d0ec856a 100644 --- a/HelloMixpanel/HelloMixpanel.xcodeproj/project.pbxproj +++ b/HelloMixpanel/HelloMixpanel.xcodeproj/project.pbxproj @@ -1068,9 +1068,14 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-HelloMixpanelTests/Pods-HelloMixpanelTests-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Nocilla-iOS/Nocilla.framework", + "${BUILT_PRODUCTS_DIR}/OCMock-iOS/OCMock.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nocilla.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OCMock.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -1083,13 +1088,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-HelloMixpanel_tvOSTests-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; 6EDEBFE516C45FD65271D88E /* [CP] Copy Pods Resources */ = { @@ -1113,9 +1121,14 @@ files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-HelloMixpanel_tvOSTests/Pods-HelloMixpanel_tvOSTests-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Nocilla-tvOS/Nocilla.framework", + "${BUILT_PRODUCTS_DIR}/OCMock-tvOS/OCMock.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nocilla.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OCMock.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -1143,13 +1156,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-HelloMixpanelTests-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -1513,7 +1529,7 @@ GCC_WARN_STRICT_SELECTOR_MATCH = YES; GCC_WARN_UNDECLARED_SELECTOR = NO; INFOPLIST_FILE = "HelloMixpanel/HelloMixpanel-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_CFLAGS = ( "$(inherited)", @@ -1551,7 +1567,7 @@ GCC_WARN_STRICT_SELECTOR_MATCH = YES; GCC_WARN_UNDECLARED_SELECTOR = NO; INFOPLIST_FILE = "HelloMixpanel/HelloMixpanel-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_CFLAGS = ( "$(inherited)", @@ -1598,7 +1614,7 @@ "\"$(SRCROOT)/../Mixpanel\"/**", ); INFOPLIST_FILE = "HelloMixpanelTests/HelloMixpanelTests-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", @@ -1640,7 +1656,7 @@ "\"$(SRCROOT)/../Mixpanel\"/**", ); INFOPLIST_FILE = "HelloMixpanelTests/HelloMixpanelTests-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", @@ -1747,7 +1763,7 @@ GCC_WARN_STRICT_SELECTOR_MATCH = YES; GCC_WARN_UNDECLARED_SELECTOR = NO; INFOPLIST_FILE = "HelloMixpanel/HelloMixpanel-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; OTHER_CFLAGS = ( "$(inherited)", @@ -1789,7 +1805,7 @@ "\"$(SRCROOT)/../Mixpanel\"/**", ); INFOPLIST_FILE = "HelloMixpanelTests/HelloMixpanelTests-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @loader_path/Frameworks"; LIBRARY_SEARCH_PATHS = ( "$(inherited)", @@ -1836,7 +1852,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; - TVOS_DEPLOYMENT_TARGET = 9.0; + TVOS_DEPLOYMENT_TARGET = 10.0; }; name = Debug; }; @@ -1870,7 +1886,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; - TVOS_DEPLOYMENT_TARGET = 9.0; + TVOS_DEPLOYMENT_TARGET = 10.0; VALIDATE_PRODUCT = YES; }; name = Release; @@ -1904,7 +1920,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; TARGETED_DEVICE_FAMILY = 3; - TVOS_DEPLOYMENT_TARGET = 9.0; + TVOS_DEPLOYMENT_TARGET = 10.0; VALIDATE_PRODUCT = YES; }; name = AppStore; @@ -1946,7 +1962,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HelloMixpanel_tvOS.app/HelloMixpanel_tvOS"; - TVOS_DEPLOYMENT_TARGET = 9.2; + TVOS_DEPLOYMENT_TARGET = 10.0; TV_OS_TEST = 1; }; name = Debug; @@ -1985,7 +2001,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HelloMixpanel_tvOS.app/HelloMixpanel_tvOS"; - TVOS_DEPLOYMENT_TARGET = 9.2; + TVOS_DEPLOYMENT_TARGET = 10.0; TV_OS_TEST = 1; VALIDATE_PRODUCT = YES; }; @@ -2024,7 +2040,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/HelloMixpanel_tvOS.app/HelloMixpanel_tvOS"; - TVOS_DEPLOYMENT_TARGET = 9.2; + TVOS_DEPLOYMENT_TARGET = 10.0; TV_OS_TEST = 1; VALIDATE_PRODUCT = YES; }; diff --git a/HelloMixpanel/HelloMixpanel.xcodeproj/xcshareddata/xcschemes/[iOS] HelloMixpanel.xcscheme b/HelloMixpanel/HelloMixpanel.xcodeproj/xcshareddata/xcschemes/[iOS] HelloMixpanel.xcscheme index 8aede4e41..367f60d4f 100644 --- a/HelloMixpanel/HelloMixpanel.xcodeproj/xcshareddata/xcschemes/[iOS] HelloMixpanel.xcscheme +++ b/HelloMixpanel/HelloMixpanel.xcodeproj/xcshareddata/xcschemes/[iOS] HelloMixpanel.xcscheme @@ -40,8 +40,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES" - codeCoverageEnabled = "YES"> + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -104,7 +104,7 @@ + isEnabled = "NO"> diff --git a/HelloMixpanel/HelloMixpanel/AppDelegate.m b/HelloMixpanel/HelloMixpanel/AppDelegate.m index 03ecf2a25..30039befe 100644 --- a/HelloMixpanel/HelloMixpanel/AppDelegate.m +++ b/HelloMixpanel/HelloMixpanel/AppDelegate.m @@ -32,7 +32,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( self.mixpanel.checkForNotificationsOnActive = YES; self.mixpanel.showNotificationOnActive = YES; //Change this to NO to show your notifs manually. - + self.mixpanel.enableLogging = YES; + // Set the upload interval to 20 seconds for demonstration purposes. This would be overkill for most applications. self.mixpanel.flushInterval = 20; // defaults to 60 seconds @@ -50,10 +51,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( }); } }]; - } else { - UIUserNotificationSettings *userNotificationSettings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil]; - [[UIApplication sharedApplication] registerUserNotificationSettings:userNotificationSettings]; - [[UIApplication sharedApplication] registerForRemoteNotifications]; } return YES; @@ -61,19 +58,22 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( #pragma mark - Push notifications -- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings -{ - [[UIApplication sharedApplication] registerForRemoteNotifications]; -} - -- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)(void))completionHandler +- (void)userNotificationCenter:(UNUserNotificationCenter *)center +didReceiveNotificationResponse:(UNNotificationResponse *)response + withCompletionHandler:(void (^)(void))completionHandler { - if ([identifier isEqualToString:@"declineAction"]) { + if ([response.actionIdentifier isEqualToString:@"declineAction"]) { NSLog(@"%@ user declined push notification action", self); - - } else if ([identifier isEqualToString:@"answerAction"]) { + + } else if ([response.actionIdentifier isEqualToString:@"answerAction"]) { NSLog(@"%@ user answered push notification action", self); } + + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:response.notification.request.content.userInfo[@"aps"][@"alert"] preferredStyle:UIAlertControllerStyleAlert]; + [alert addAction:[UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleDefault handler:nil]]; + [self.window.rootViewController presentViewController:alert animated:YES completion:nil]; + + completionHandler(); } - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken { @@ -88,22 +88,10 @@ - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotifications #endif } -- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo -{ - // Show alert for push notifications recevied while the app is running - UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:userInfo[@"aps"][@"alert"] preferredStyle:UIAlertControllerStyleAlert]; - [alert addAction:[UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleDefault handler:nil]]; - [self.window.rootViewController presentViewController:alert animated:YES completion:nil]; -} - --(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{ +- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{ completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge); } --(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{ - completionHandler(); -} - #pragma mark - Session timing example diff --git a/HelloMixpanel/HelloMixpanel/HelloMixpanel.storyboard b/HelloMixpanel/HelloMixpanel/HelloMixpanel.storyboard index e227a7acc..44d979e72 100644 --- a/HelloMixpanel/HelloMixpanel/HelloMixpanel.storyboard +++ b/HelloMixpanel/HelloMixpanel/HelloMixpanel.storyboard @@ -1,11 +1,11 @@ - + - + @@ -27,101 +27,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -136,7 +42,7 @@ - + @@ -176,7 +82,7 @@ - + @@ -196,7 +102,7 @@ - + @@ -270,7 +176,7 @@ - + @@ -455,7 +361,7 @@ - + @@ -503,138 +409,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -682,7 +457,7 @@ - + @@ -794,7 +569,7 @@ - + @@ -821,7 +596,7 @@ @@ -1165,7 +940,7 @@ Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostr - + @@ -1188,7 +963,7 @@ Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostr - + @@ -1249,7 +1024,7 @@ Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostr - + @@ -1313,7 +1088,7 @@ Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostr - + @@ -1407,7 +1182,7 @@ Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostr - + @@ -1451,7 +1226,7 @@ Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostr - + @@ -1499,13 +1274,11 @@ Incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostr - + - - diff --git a/HelloMixpanel/HelloMixpanelTests/Info.plist b/HelloMixpanel/HelloMixpanelTests/Info.plist new file mode 100644 index 000000000..6c40a6cd0 --- /dev/null +++ b/HelloMixpanel/HelloMixpanelTests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/HelloMixpanel/HelloMixpanelTests/MixpanelBaseTests.h b/HelloMixpanel/HelloMixpanelTests/MixpanelBaseTests.h index b79be5f07..7e1b7c77f 100644 --- a/HelloMixpanel/HelloMixpanelTests/MixpanelBaseTests.h +++ b/HelloMixpanel/HelloMixpanelTests/MixpanelBaseTests.h @@ -9,15 +9,7 @@ #import #import "Mixpanel.h" -#if !defined(MIXPANEL_TVOS_EXTENSION) -#import -#endif - -#if !defined(MIXPANEL_TVOS_EXTENSION) -@interface MixpanelBaseTests : FBSnapshotTestCase -#else @interface MixpanelBaseTests : XCTestCase -#endif @property (nonatomic, strong) Mixpanel *mixpanel; @property (atomic) BOOL mixpanelWillFlush; diff --git a/HelloMixpanel/Podfile b/HelloMixpanel/Podfile index e7f858efd..71f5c4b87 100644 --- a/HelloMixpanel/Podfile +++ b/HelloMixpanel/Podfile @@ -8,7 +8,6 @@ end target :HelloMixpanelTests do platform :ios, '8.0' shared_pods - pod 'FBSnapshotTestCase' end target :HelloMixpanel_tvOSTests do diff --git a/Mixpanel/MPLogger.h b/Mixpanel/MPLogger.h index 3262155cb..a5a2e81e7 100644 --- a/Mixpanel/MPLogger.h +++ b/Mixpanel/MPLogger.h @@ -9,6 +9,7 @@ #import #import #import +#import static BOOL gLoggingEnabled = NO; static NSObject *loggingLockObject; @@ -26,16 +27,81 @@ static inline void NAME(NSString *format, ...) { \ } \ } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" // Something has failed. -__MP_MAKE_LOG_FUNCTION(ASL_LEVEL_ERR, MPLogError) +__MP_MAKE_LOG_FUNCTION(ASL_LEVEL_ERR, MPLogError_legacy) // Something is amiss and might fail if not corrected. -__MP_MAKE_LOG_FUNCTION(ASL_LEVEL_WARNING, MPLogWarning) +__MP_MAKE_LOG_FUNCTION(ASL_LEVEL_WARNING, MPLogWarning_legacy) // The lowest priority that you would normally log, and purely informational in nature. -__MP_MAKE_LOG_FUNCTION(ASL_LEVEL_INFO, MPLogInfo) +__MP_MAKE_LOG_FUNCTION(ASL_LEVEL_INFO, MPLogInfo_legacy) // The lowest priority, and normally not logged except for code based messages. -__MP_MAKE_LOG_FUNCTION(ASL_LEVEL_DEBUG, MPLogDebug) +__MP_MAKE_LOG_FUNCTION(ASL_LEVEL_DEBUG, MPLogDebug_legacy) #undef __MP_MAKE_LOG_FUNCTION +#pragma clang diagnostic pop + +static inline os_log_t mixpanelLog() { + static os_log_t logger = nil; + if (!logger) { + if (@available(iOS 10.0, macOS 10.12, *)) { + logger = os_log_create("com.mixpanel.sdk.objc", "Mixpanel"); + } + } + return logger; +} + +static inline void MPLogDebug(NSString *format, ...) { + if (!gLoggingEnabled) return; + va_list arg_list; + va_start(arg_list, format); + NSString *formattedString = [[NSString alloc] initWithFormat:format arguments:arg_list]; + if (@available(iOS 10.0, macOS 10.12, *)) { + os_log_with_type(mixpanelLog(), OS_LOG_TYPE_DEBUG, ": %s", [formattedString UTF8String]); + } + else { + MPLogDebug_legacy(@"%s", [formattedString UTF8String]); + } +} + +static inline void MPLogInfo(NSString *format, ...) { + if (!gLoggingEnabled) return; + va_list arg_list; + va_start(arg_list, format); + NSString *formattedString = [[NSString alloc] initWithFormat:format arguments:arg_list]; + if (@available(iOS 10.0, macOS 10.12, *)) { + os_log_with_type(mixpanelLog(), OS_LOG_TYPE_INFO, ": %s", [formattedString UTF8String]); + } + else { + MPLogInfo_legacy(@"%s", [formattedString UTF8String]); + } +} + +static inline void MPLogWarning(NSString *format, ...) { + if (!gLoggingEnabled) return; + va_list arg_list; + va_start(arg_list, format); + NSString *formattedString = [[NSString alloc] initWithFormat:format arguments:arg_list]; + if (@available(iOS 10.0, macOS 10.12, *)) { + os_log_with_type(mixpanelLog(), OS_LOG_TYPE_ERROR, ": %s", [formattedString UTF8String]); + } + else { + MPLogWarning_legacy(@"%s", [formattedString UTF8String]); + } +} + +static inline void MPLogError(NSString *format, ...) { + if (!gLoggingEnabled) return; + va_list arg_list; + va_start(arg_list, format); + NSString *formattedString = [[NSString alloc] initWithFormat:format arguments:arg_list]; + if (@available(iOS 10.0, macOS 10.12, *)) { + os_log_with_type(mixpanelLog(), OS_LOG_TYPE_ERROR, ": %s", [formattedString UTF8String]); + } + else { + MPLogError_legacy(@"%s", [formattedString UTF8String]); + } +} diff --git a/Mixpanel/MPSequenceGenerator.m b/Mixpanel/MPSequenceGenerator.m index c7ae87035..1c6c79b5d 100644 --- a/Mixpanel/MPSequenceGenerator.m +++ b/Mixpanel/MPSequenceGenerator.m @@ -3,11 +3,12 @@ #import #import "MPSequenceGenerator.h" +#include @implementation MPSequenceGenerator { - int32_t _value; + atomic_int_fast32_t _value; } - (instancetype)init @@ -27,7 +28,7 @@ - (instancetype)initWithInitialValue:(int32_t)initialValue - (int32_t)nextValue { - return OSAtomicAdd32(1, &_value); + return atomic_fetch_add_explicit(&_value, 1, memory_order_relaxed); } @end diff --git a/Mixpanel/MPSwizzler.h b/Mixpanel/MPSwizzler.h index a0ea5fa48..3ac2a666c 100644 --- a/Mixpanel/MPSwizzler.h +++ b/Mixpanel/MPSwizzler.h @@ -11,7 +11,11 @@ // Cast to turn things that are not ids into NSMapTable keys #define MAPTABLE_ID(x) (__bridge id)((void *)x) +// Ignore the warning cause we need the paramters to be dynamic and it's only being used internally +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wstrict-prototypes" typedef void (^swizzleBlock)(); +#pragma clang diagnostic pop @interface MPSwizzler : NSObject diff --git a/Mixpanel/MPSwizzler.m b/Mixpanel/MPSwizzler.m index cb66d1e86..d8838faca 100644 --- a/Mixpanel/MPSwizzler.m +++ b/Mixpanel/MPSwizzler.m @@ -92,7 +92,11 @@ static void mp_swizzledMethod_5(id self, SEL _cmd, id arg, id arg2, id arg3) } } +// Ignore the warning cause we need the paramters to be dynamic and it's only being used internally +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wstrict-prototypes" static void (*mp_swizzledMethods[MAX_ARGS - MIN_ARGS + 1])() = {mp_swizzledMethod_2, mp_swizzledMethod_3, mp_swizzledMethod_4, mp_swizzledMethod_5}; +#pragma clang diagnostic pop @implementation MPSwizzler diff --git a/Mixpanel/MPTweakInline.m b/Mixpanel/MPTweakInline.m index dface470c..7478ba2ff 100644 --- a/Mixpanel/MPTweakInline.m +++ b/Mixpanel/MPTweakInline.m @@ -14,6 +14,7 @@ #import "MPTweak.h" #import "MPTweakInline.h" #import "MPTweakStore.h" +#include static MPTweak *_MPTweakCreateWithEntry(NSString *name, mp_tweak_entry *entry) { @@ -102,8 +103,9 @@ @interface _MPTweakInlineLoader : NSObject @implementation _MPTweakInlineLoader + (void)load { - static uint32_t _tweaksLoaded = 0; - if (OSAtomicTestAndSetBarrier(1, &_tweaksLoaded)) { + static atomic_uint_fast32_t _tweaksLoaded = 0; + + if (atomic_fetch_or(&_tweaksLoaded, 1)) { return; } diff --git a/Mixpanel/MPUIControlBinding.m b/Mixpanel/MPUIControlBinding.m index d36eea058..35b6aa2f7 100644 --- a/Mixpanel/MPUIControlBinding.m +++ b/Mixpanel/MPUIControlBinding.m @@ -74,9 +74,15 @@ - (instancetype)initWithEventName:(NSString *)eventName andVerifyEvent:(UIControlEvents)verifyEvent { if (self = [super initWithEventName:eventName onPath:path]) { - [self setSwizzleClass:[UIControl class]]; + // iOS 12: UITextField now implements -didMoveToWindow, without calling the parent implementation. so Swizzle UIControl won't work + if (@available(iOS 12, *)) { + [self setSwizzleClass:[path containsString:@"UITextField"] ? [UITextField class] : [UIControl class]]; + } + else { + [self setSwizzleClass:[UIControl class]]; + } _controlEvent = controlEvent; - + if (verifyEvent == 0) { if (controlEvent & UIControlEventAllTouchEvents) { verifyEvent = UIControlEventTouchDown; diff --git a/Mixpanel/Mixpanel.m b/Mixpanel/Mixpanel.m index d40b4b26b..107b240c1 100755 --- a/Mixpanel/Mixpanel.m +++ b/Mixpanel/Mixpanel.m @@ -1624,13 +1624,19 @@ - (void)setEnableLogging:(BOOL)enableLogging { @synchronized (loggingLockObject) { gLoggingEnabled = enableLogging; - + if (@available(iOS 10.0, macOS 10.12, *)) { + return; + } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + // Legacy logging, will be removed in future as long as we only support iOS 10+ if (gLoggingEnabled) { asl_add_log_file(NULL, STDERR_FILENO); asl_set_filter(NULL, ASL_FILTER_MASK_UPTO(ASL_LEVEL_DEBUG)); } else { asl_remove_log_file(NULL, STDERR_FILENO); } +#pragma clang diagnostic pop } } diff --git a/Mixpanel/MixpanelExceptionHandler.m b/Mixpanel/MixpanelExceptionHandler.m index f1170944d..f431cda45 100644 --- a/Mixpanel/MixpanelExceptionHandler.m +++ b/Mixpanel/MixpanelExceptionHandler.m @@ -11,12 +11,13 @@ #import "MixpanelPrivate.h" #import "MPLogger.h" #include +#include static NSString * const UncaughtExceptionHandlerSignalExceptionName = @"UncaughtExceptionHandlerSignalExceptionName"; static NSString * const UncaughtExceptionHandlerSignalKey = @"UncaughtExceptionHandlerSignalKey"; -static volatile int32_t UncaughtExceptionCount = 0; -static const int32_t UncaughtExceptionMaximum = 10; +static volatile atomic_int_fast32_t UncaughtExceptionCount = 0; +static const atomic_int_fast32_t UncaughtExceptionMaximum = 10; @interface MixpanelExceptionHandler () @@ -83,7 +84,8 @@ - (void)addMixpanelInstance:(Mixpanel *)instance { void MPSignalHandler(int signalNumber, struct __siginfo *info, void *context) { MixpanelExceptionHandler *handler = [MixpanelExceptionHandler sharedHandler]; - int32_t exceptionCount = OSAtomicIncrement32(&UncaughtExceptionCount); + atomic_int_fast32_t exceptionCount = atomic_fetch_add_explicit(&UncaughtExceptionCount, 1, memory_order_relaxed); + if (exceptionCount <= UncaughtExceptionMaximum) { NSDictionary *userInfo = @{UncaughtExceptionHandlerSignalKey: @(signalNumber)}; NSException *exception = [NSException exceptionWithName:UncaughtExceptionHandlerSignalExceptionName @@ -112,7 +114,7 @@ void MPSignalHandler(int signalNumber, struct __siginfo *info, void *context) { void MPHandleException(NSException *exception) { MixpanelExceptionHandler *handler = [MixpanelExceptionHandler sharedHandler]; - int32_t exceptionCount = OSAtomicIncrement32(&UncaughtExceptionCount); + atomic_int_fast32_t exceptionCount = atomic_fetch_add_explicit(&UncaughtExceptionCount, 1, memory_order_relaxed); if (exceptionCount <= UncaughtExceptionMaximum) { [handler mp_handleUncaughtException:exception]; }