Skip to content

Commit

Permalink
fix: UICollectionView/UITableView swizzle bug (#316)
Browse files Browse the repository at this point in the history
* fix: UICollectionView/UITableView didSelect swizzle

* ci: update ci

* fix: some warnings raise when building

* fix: upgrade codes about key chain access

* style: code format

* fix: some warnings raise when building

---------

Co-authored-by: GIOSDK <[email protected]>
  • Loading branch information
YoloMao and GIOSDK authored May 7, 2024
1 parent af66457 commit 0ec1ab0
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 41 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
build:
runs-on: macos-12
env:
DERIVED_DATA: $HOME/.DerivedData
DERIVED_DATA: ${{ github.workspace }}/.DerivedData

steps:
- name: Checkout Repo
Expand Down Expand Up @@ -62,14 +62,16 @@ jobs:
run: |
xcresultparser -o cobertura ${{ env.DERIVED_DATA }}/Logs/Test/*.xcresult/ \
> ${{ env.DERIVED_DATA }}/cobertura-coverage.xml
pwd
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: /Users/runner/.DerivedData/cobertura-coverage.xml
fail_ci_if_error: true
files: ./.DerivedData/cobertura-coverage.xml
directory: ${{ github.workspace }}
verbose: true

- name: Parse xcresult to Sonarqube xml
run: |
Expand Down
6 changes: 2 additions & 4 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
0465314824DD4272002D254C /* GIOPageEventViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530F724DD4271002D254C /* GIOPageEventViewController.m */; };
0465314924DD4272002D254C /* GIOFirstViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530F924DD4271002D254C /* GIOFirstViewController.m */; };
0465314A24DD4272002D254C /* GIOSecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530FA24DD4271002D254C /* GIOSecondViewController.m */; };
0465314B24DD4272002D254C /* GrowingIO-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 046530FD24DD4271002D254C /* GrowingIO-Info.plist */; };
0465314C24DD4272002D254C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530FE24DD4271002D254C /* main.m */; };
0465314D24DD4272002D254C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 046530FF24DD4271002D254C /* AppDelegate.m */; };
0465314E24DD4272002D254C /* GIOLabelAttributeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0465310124DD4271002D254C /* GIOLabelAttributeViewController.m */; };
Expand Down Expand Up @@ -2241,7 +2240,6 @@
0465315F24DD4272002D254C /* GIOListTableViewCell.xib in Resources */,
0465315D24DD4272002D254C /* GIOFoodTableViewCell.xib in Resources */,
34B932352767661600025C94 /* MeasurementProtocol.storyboard in Resources */,
0465314B24DD4272002D254C /* GrowingIO-Info.plist in Resources */,
0465315924DD4272002D254C /* GIOPageStructure.storyboard in Resources */,
34BDC35A277088D40030B3CE /* UICatalogTests.storyboard in Resources */,
0465313B24DD4272002D254C /* LaunchScreen.storyboard in Resources */,
Expand Down Expand Up @@ -3563,7 +3561,7 @@
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
Expand Down Expand Up @@ -3620,7 +3618,7 @@
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.0;
MTL_ENABLE_DEBUG_INFO = NO;
Expand Down
2 changes: 1 addition & 1 deletion Example/ShareExtension/ShareViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ - (void)viewDidLoad {
GrowingAutotrackConfiguration *configuration = [GrowingAutotrackConfiguration configurationWithAccountId:@"0a1b4118dd954ec3bcc69da5138bdb96"];
configuration.dataSourceId = @"ab555003531e0fd1";
configuration.debugEnabled = YES;
[GrowingAutotracker startWithConfiguration:configuration launchOptions:nil];
[GrowingAutotracker startWithConfiguration:configuration launchOptions:@{}];
}

- (BOOL)isContentValid {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ - (void)growing_setDelegate:(id<UICollectionViewDelegate>)delegate {
GUSWReturnType(void),
GUSWArguments(UICollectionView * collectionView, NSIndexPath * indexPath),
GUSWReplacement({
GUSWCallOriginal(collectionView, indexPath);
if (collectionView && indexPath) {
UICollectionViewCell *cell =
[collectionView cellForItemAtIndexPath:indexPath];
if (cell) {
[GrowingViewClickProvider viewOnClick:cell];
}
}
GUSWCallOriginal(collectionView, indexPath);
}),
GrowingULSwizzleModeOncePerClassAndSuperclasses,
key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ - (void)growing_setDelegate:(id<UITableViewDelegate>)delegate {
GUSWReturnType(void),
GUSWArguments(UITableView * tableView, NSIndexPath * indexPath),
GUSWReplacement({
GUSWCallOriginal(tableView, indexPath);
if (tableView && indexPath) {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell) {
[GrowingViewClickProvider viewOnClick:cell];
}
}
GUSWCallOriginal(tableView, indexPath);
}),
GrowingULSwizzleModeOncePerClassAndSuperclasses,
key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ @implementation GrowingSceneDelegateAutotracker
+ (void)track:(Class)delegateClass {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (@available(iOS 13.0, *)) {
if (@available(iOS 13.0, tvOS 13.0, *)) {
// URL Scheme
SEL sel = @selector(scene:openURLContexts:);
Method method = class_getInstanceMethod(delegateClass, sel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#if Growing_OS_IOS
#import "GrowingTrackerCore/GrowingWindow.h"
#import "GrowingTrackerCore/Helpers/UIKit/UIApplication+GrowingHelper.h"
#import "GrowingULApplication.h"

@implementation UIApplication (GrowingHelper)

Expand All @@ -30,7 +31,7 @@ @implementation UIApplication (GrowingHelper)
/// 我们需要将其加入数组中
- (NSArray<UIWindow *> *)growingHelper_allWindows {
NSArray *array = [self windows];
UIWindow *keyWindow = [self keyWindow];
UIWindow *keyWindow = [self growingul_keyWindow];

if (!keyWindow) {
return array;
Expand Down
3 changes: 3 additions & 0 deletions GrowingTrackerCore/Network/GrowingNetworkInterfaceManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ - (NSString *)networkType {
}
}
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
accessString = self.teleInfo.currentRadioAccessTechnology;
#pragma clang diagnostic pop
}

if ([typeStrings4G containsObject:accessString]) {
Expand Down
34 changes: 11 additions & 23 deletions GrowingTrackerCore/Thirdparty/Logger/GrowingLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,12 @@
// prior written permission of Deusty, LLC.

#import <Foundation/Foundation.h>

// The Swift Package integration has no support for the legacy macros.
#if __has_include(<CocoaLumberjack/GrowingLegacyMacros.h>)
// Enable 1.9.x legacy macros if imported directly and it's not a swift package build.
#ifndef Growing_LEGACY_MACROS
#define Growing_LEGACY_MACROS 1
#endif
// Growing_LEGACY_MACROS is checked in the file itself
#import "GrowingLegacyMacros.h"
#endif

// Names of loggers.
#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLoggerNames.h"

#if OS_OBJECT_USE_OBJC
#define DISPATCH_QUEUE_REFERENCE_TYPE strong
#define GIO_DISPATCH_QUEUE_REFERENCE_TYPE strong
#else
#define DISPATCH_QUEUE_REFERENCE_TYPE assign
#define GIO_DISPATCH_QUEUE_REFERENCE_TYPE assign
#endif

@class GrowingLogMessage;
Expand Down Expand Up @@ -224,7 +212,7 @@ FOUNDATION_EXTERN NSString * __nullable GrowingExtractFileNameWithoutExtension(c
* Provides access to the underlying logging queue.
* This may be helpful to Logger classes for things like thread synchronization.
**/
@property (class, nonatomic, DISPATCH_QUEUE_REFERENCE_TYPE, readonly) dispatch_queue_t loggingQueue;
@property (class, nonatomic, GIO_DISPATCH_QUEUE_REFERENCE_TYPE, readonly) dispatch_queue_t loggingQueue;

/**
* Logging Primitive.
Expand Down Expand Up @@ -304,7 +292,7 @@ FOUNDATION_EXTERN NSString * __nullable GrowingExtractFileNameWithoutExtension(c
line:(NSUInteger)line
tag:(nullable id)tag
format:(NSString *)format
args:(va_list)argList NS_SWIFT_NAME(log(asynchronous:level:flag:context:file:function:line:tag:format:arguments:));
args:(va_list)argList;

/**
* Logging Primitive.
Expand Down Expand Up @@ -332,7 +320,7 @@ FOUNDATION_EXTERN NSString * __nullable GrowingExtractFileNameWithoutExtension(c
line:(NSUInteger)line
tag:(nullable id)tag
format:(NSString *)format
args:(va_list)argList NS_SWIFT_NAME(log(asynchronous:level:flag:context:file:function:line:tag:format:arguments:));
args:(va_list)argList;

/**
* Logging Primitive.
Expand All @@ -343,7 +331,7 @@ FOUNDATION_EXTERN NSString * __nullable GrowingExtractFileNameWithoutExtension(c
* @param logMessage the log message stored in a `GrowingLogMessage` model object
*/
+ (void)log:(BOOL)asynchronous
message:(GrowingLogMessage *)logMessage NS_SWIFT_NAME(log(asynchronous:message:));
message:(GrowingLogMessage *)logMessage;

/**
* Logging Primitive.
Expand All @@ -354,7 +342,7 @@ FOUNDATION_EXTERN NSString * __nullable GrowingExtractFileNameWithoutExtension(c
* @param logMessage the log message stored in a `GrowingLogMessage` model object
*/
- (void)log:(BOOL)asynchronous
message:(GrowingLogMessage *)logMessage NS_SWIFT_NAME(log(asynchronous:message:));
message:(GrowingLogMessage *)logMessage;

/**
* Since logging can be asynchronous, there may be times when you want to flush the logs.
Expand Down Expand Up @@ -573,7 +561,7 @@ FOUNDATION_EXTERN NSString * __nullable GrowingExtractFileNameWithoutExtension(c
*
* @param logMessage the message (model)
*/
- (void)logMessage:(GrowingLogMessage *)logMessage NS_SWIFT_NAME(log(message:));
- (void)logMessage:(GrowingLogMessage *)logMessage;

/**
* Formatters may optionally be added to any logger.
Expand Down Expand Up @@ -633,7 +621,7 @@ FOUNDATION_EXTERN NSString * __nullable GrowingExtractFileNameWithoutExtension(c
* Thus, a dedicated dispatch queue is used for each logger.
* Logger implementations may optionally choose to provide their own dispatch queue.
**/
@property (nonatomic, DISPATCH_QUEUE_REFERENCE_TYPE, readonly) dispatch_queue_t loggerQueue;
@property (nonatomic, GIO_DISPATCH_QUEUE_REFERENCE_TYPE, readonly) dispatch_queue_t loggerQueue;

/**
* If the logger implementation does not choose to provide its own queue,
Expand Down Expand Up @@ -666,7 +654,7 @@ FOUNDATION_EXTERN NSString * __nullable GrowingExtractFileNameWithoutExtension(c
* The formatter may also optionally filter the log message by returning nil,
* in which case the logger will not log the message.
**/
- (nullable NSString *)formatLogMessage:(GrowingLogMessage *)logMessage NS_SWIFT_NAME(format(message:));
- (nullable NSString *)formatLogMessage:(GrowingLogMessage *)logMessage;

@optional

Expand Down Expand Up @@ -884,7 +872,7 @@ typedef NS_OPTIONS(NSInteger, GrowingLogMessageOptions){
}

@property (nonatomic, strong, nullable) id <GrowingLogFormatter> logFormatter;
@property (nonatomic, DISPATCH_QUEUE_REFERENCE_TYPE) dispatch_queue_t loggerQueue;
@property (nonatomic, GIO_DISPATCH_QUEUE_REFERENCE_TYPE) dispatch_queue_t loggerQueue;

// For thread-safety assertions

Expand Down
4 changes: 4 additions & 0 deletions GrowingTrackerCore/Utils/GrowingArgumentChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface GrowingArgumentChecker : NSObject

+ (BOOL)isIllegalEventName:(NSString *)eventName;
Expand All @@ -27,3 +29,5 @@
+ (NSDictionary<NSString *, NSString *> *_Nullable)serializableAttributes:(NSDictionary *)properties;

@end

NS_ASSUME_NONNULL_END
37 changes: 32 additions & 5 deletions GrowingTrackerCore/Utils/GrowingKeyChainWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// limitations under the License.

#import "GrowingTrackerCore/Utils/GrowingKeyChainWrapper.h"
#import "GrowingTargetConditionals.h"
#import "GrowingTrackerCore/Thirdparty/Logger/GrowingLogger.h"

@implementation GrowingKeyChainWrapper
Expand All @@ -30,7 +31,23 @@ + (void)setKeychainObject:(id)value forKey:(NSString *)service {
SecItemDelete((CFDictionaryRef)keychainQuery);

// Add new object to search dictionary(Attention:the data format)
[keychainQuery setObject:[NSKeyedArchiver archivedDataWithRootObject:value] forKey:(id)kSecValueData];
#if Growing_OS_VISION
if (1) { // if (@available(visionOS 1.0, *)) {
#else
if (@available(iOS 11.0, macCatalyst 13.1, macOS 10.13, tvOS 11.0, watchOS 4.0, *)) {
#endif
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:value requiringSecureCoding:YES error:nil];
[keychainQuery setObject:data forKey:(id)kSecValueData];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:value];
[keychainQuery setObject:data forKey:(id)kSecValueData];
#pragma clang diagnostic pop
}

// Configure accessible attribute
[keychainQuery setObject:(id)kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly forKey:(id)kSecAttrAccessible];

// Add item to keychain with the search dictionary
SecItemAdd((CFDictionaryRef)keychainQuery, NULL);
Expand All @@ -48,7 +65,20 @@ + (id)keyChainObjectForKey:(NSString *)key {
CFDataRef keyData = NULL;
if (SecItemCopyMatching((CFDictionaryRef)keychainQuery, (CFTypeRef *)&keyData) == noErr) {
@try {
ret = [NSKeyedUnarchiver unarchiveObjectWithData:(__bridge NSData *)keyData];
#if Growing_OS_VISION
if (1) { // if (@available(visionOS 1.0, *)) {
#else
if (@available(iOS 11.0, macCatalyst 13.1, macOS 10.13, tvOS 11.0, watchOS 4.0, *)) {
#endif
ret = [NSKeyedUnarchiver unarchivedObjectOfClass:[NSString class]
fromData:(__bridge NSData *)keyData
error:nil];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
ret = [NSKeyedUnarchiver unarchiveObjectWithData:(__bridge NSData *)keyData];
#pragma clang diagnostic pop
}
} @catch (NSException *e) {
GIOLogError(@"GrowingIO Unarchive of %@ failed: %@", key, e);
} @finally {
Expand All @@ -58,16 +88,13 @@ + (id)keyChainObjectForKey:(NSString *)key {
return ret;
}

// keychain
+ (NSMutableDictionary *)getKeychainQuery:(NSString *)key {
return [NSMutableDictionary dictionaryWithObjectsAndKeys:(id)kSecClassGenericPassword,
(id)kSecClass,
key,
(id)kSecAttrService,
key,
(id)kSecAttrAccount,
(id)kSecAttrAccessibleAlwaysThisDeviceOnly,
(id)kSecAttrAccessible,
nil];
}

Expand Down

0 comments on commit 0ec1ab0

Please sign in to comment.