Skip to content

Commit

Permalink
Internal fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JazysYu committed Nov 24, 2017
1 parent 43f4c6e commit cfc0ac4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
5 changes: 4 additions & 1 deletion JZNavigationExtension/Private/_JZ-objc-internal.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
}

- (UIView *)jz_backgroundView {
return [self valueForKeyPath:@"_backgroundView._backgroundEffectView"];
if (@available(iOS 10, *)) {
return [self valueForKeyPath:@"_backgroundView._backgroundEffectView"];
}
return [self valueForKeyPath:@"_backgroundView"];
}

@end
Expand Down
2 changes: 2 additions & 0 deletions JZNavigationExtension/Private/_JZNavigationDelegating.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

@interface _JZNavigationDelegating : NSObject <UINavigationControllerDelegate, UIGestureRecognizerDelegate>

- (instancetype)initWithActionsPerformInDealloc:(dispatch_block_t)actionsPerformInDealloc;

- (instancetype)initWithNavigationController:(UINavigationController *)navigationController;

@end
13 changes: 13 additions & 0 deletions JZNavigationExtension/Private/_JZNavigationDelegating.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,23 @@

@interface _JZNavigationDelegating()
@property (nonatomic, weak) UINavigationController *navigationController;
@property (nonatomic, copy) dispatch_block_t actionsPerformInDealloc;
@end

@implementation _JZNavigationDelegating

- (void)dealloc {
!self.actionsPerformInDealloc ?: self.actionsPerformInDealloc();
}

- (instancetype)initWithActionsPerformInDealloc:(dispatch_block_t)actionsPerformInDealloc {
self = [super init];
if (self) {
self.actionsPerformInDealloc = actionsPerformInDealloc;
}
return self;
}

- (instancetype)initWithNavigationController:(UINavigationController *)navigationController {
self = [super init];
if (self) {
Expand Down
14 changes: 12 additions & 2 deletions JZNavigationExtension/UINavigationController+JZExtension.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ - (void)jz_setDelegate:(NSObject <UINavigationControllerDelegate> *)delegate {
static NSString *_JZNavigationDelegatingTrigger = @"_JZNavigationDelegatingTrigger";

if (![self.delegate isEqual:self.jz_navigationDelegate]) {
[(NSObject *)self.delegate removeObserver:self forKeyPath:_JZNavigationDelegatingTrigger context:_cmd];
objc_setAssociatedObject(self.delegate, _cmd, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
@try { [(NSObject *)self.delegate removeObserver:self.delegate forKeyPath:_JZNavigationDelegatingTrigger context:_cmd]; }
@catch (NSException *exception) {
}
}

if (!delegate) {
Expand All @@ -78,7 +81,14 @@ - (void)jz_setDelegate:(NSObject <UINavigationControllerDelegate> *)delegate {

NSAssert([delegate isKindOfClass:[NSObject class]], @"Must inherit form NSObject!");

[delegate addObserver:self forKeyPath:_JZNavigationDelegatingTrigger options:NSKeyValueObservingOptionNew context:_cmd];
[delegate addObserver:delegate forKeyPath:_JZNavigationDelegatingTrigger options:NSKeyValueObservingOptionNew context:_cmd];

__unsafe_unretained typeof(delegate) unretained_delegate = delegate;
objc_setAssociatedObject(delegate, _cmd, [[_JZNavigationDelegating alloc] initWithActionsPerformInDealloc:^{
@try { [unretained_delegate removeObserver:unretained_delegate forKeyPath:_JZNavigationDelegatingTrigger context:_cmd]; }
@catch (NSException *exception) {
}
}], OBJC_ASSOCIATION_RETAIN_NONATOMIC);

void (^jz_add_replace_method)(id, SEL, IMP) = ^(id object, SEL sel, IMP imp) {

Expand Down

0 comments on commit cfc0ac4

Please sign in to comment.