Skip to content

Instantly share code, notes, and snippets.

@soxjke
Last active April 8, 2019 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soxjke/4c79e923ec549e8d7e4e0ef219f12bd5 to your computer and use it in GitHub Desktop.
Save soxjke/4c79e923ec549e8d7e4e0ef219f12bd5 to your computer and use it in GitHub Desktop.
AWSAuthCore crash workaround
#import <AWSAuthCore/AWSAuthCore.h>
@interface AWSIdentityManager (Fixtures)
@end
#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
#import <AWSAuthCore/AWSAuthCore.h>
@interface AWSSignInManager (Fixtures)
@property (nonatomic, strong) NSObject<AWSSignInProvider> *currentSignInProvider;
@end
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);
#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