Last active
April 8, 2019 13:10
-
-
Save soxjke/4c79e923ec549e8d7e4e0ef219f12bd5 to your computer and use it in GitHub Desktop.
AWSAuthCore crash workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <AWSAuthCore/AWSAuthCore.h> | |
@interface AWSIdentityManager (Fixtures) | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AWSIdentityManager+Fixtures.h" | |
#import "AWSSignInManager+Fixtures.h" | |
#import "RuntimeHelper.h" | |
@implementation AWSIdentityManager (Fixtures) | |
+ (void)load { | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
swizzleInstanceMethod(self, | |
@selector(logins), | |
@selector(fixed_logins)); | |
}); | |
} | |
- (AWSTask<NSDictionary<NSString *, NSString *> *> *)fixed_logins { | |
if (![AWSSignInManager sharedInstance].currentSignInProvider) { | |
return [AWSTask taskWithResult:nil]; | |
} | |
return [[[AWSSignInManager sharedInstance].currentSignInProvider token] continueWithSuccessBlock:^id _Nullable(AWSTask<NSString *> * _Nonnull task) { | |
NSString *token = task.result; | |
if (token) { | |
return [AWSTask taskWithResult:@{[AWSSignInManager sharedInstance].currentSignInProvider.identityProviderName : token}]; | |
} else { | |
return [AWSTask taskWithResult:nil]; | |
} | |
}]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <AWSAuthCore/AWSAuthCore.h> | |
@interface AWSSignInManager (Fixtures) | |
@property (nonatomic, strong) NSObject<AWSSignInProvider> *currentSignInProvider; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void swizzleInstanceMethod(Class class, SEL original, SEL custom); | |
void swizzleClassMethod(Class class, SEL original, SEL custom); | |
id getIvarNamed(id object, const char *name); | |
void setIvarNamed(id object, const char *name, id value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "RuntimeHelper.h" | |
#import <objc/runtime.h> | |
void swizzleInstanceMethod(Class class, SEL original, SEL custom) { | |
Method originalMethod = class_getInstanceMethod(class, original); | |
Method swizzledMethod = class_getInstanceMethod(class, custom); | |
BOOL didAddMethod = | |
class_addMethod(class, | |
original, | |
method_getImplementation(swizzledMethod), | |
method_getTypeEncoding(swizzledMethod)); | |
if (didAddMethod) { | |
class_replaceMethod(class, | |
custom, | |
method_getImplementation(originalMethod), | |
method_getTypeEncoding(originalMethod)); | |
} else { | |
method_exchangeImplementations(originalMethod, swizzledMethod); | |
} | |
} | |
void swizzleClassMethod(Class class, SEL original, SEL custom) { | |
Method originalMethod = class_getClassMethod(class, original); | |
Method swizzledMethod = class_getClassMethod(class, custom); | |
BOOL didAddMethod = | |
class_addMethod(class, | |
original, | |
method_getImplementation(swizzledMethod), | |
method_getTypeEncoding(swizzledMethod)); | |
if (didAddMethod) { | |
class_replaceMethod(class, | |
custom, | |
method_getImplementation(originalMethod), | |
method_getTypeEncoding(originalMethod)); | |
} else { | |
method_exchangeImplementations(originalMethod, swizzledMethod); | |
} | |
} | |
id getIvarNamed(id object, const char *name) { | |
Ivar ivar = class_getInstanceVariable(object_getClass(object), name); | |
return object_getIvar(object, ivar); | |
} | |
void setIvarNamed(id object, const char *name, id value) { | |
Ivar ivar = class_getInstanceVariable(object_getClass(object), name); | |
return object_setIvar(object, ivar, value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment