Git Product home page Git Product logo

neteasebaymaxdemo's Introduction

TODO

  • Unit Test
  • Bad Access 防护
  • UI Not On Main Thread 防护
  • Refactor Code

扯扯闲话

网易移动端团队前阵子在他们Blog发布了一篇文章,是关于他们自主研发的Crash自防护机制——大白健康系统--iOS APP运行时Crash自动修复系统”。看过原文后,觉得挺有意思的,是一个不错的Runtime实践用例。这个Repo是根据原文提供方案仿写的小Demo,仅做讨论研究讨论使用,期待官方早日完成测试开源SDK,学习下源码。这里不讨论这种防护是否有必要,仅当学习练手之用。 最后感谢网易TZY的交流解惑,通过交流技术认识到新朋友是很快乐的。

更多说明,请参考这篇博文--一个很好的OCRuntime用例-仿网易Baymax防护机制

neteasebaymaxdemo's People

Contributors

parsifalc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

neteasebaymaxdemo's Issues

Cannot form weak reference to instance (0x7f81547ccfc0) of class UIInputSetHostView.

在本地工程中测试KVO防护功能的时候,发现与 YYTextKeyboardManager.h 有所冲突,会报错
Cannot form weak reference to instance (0x7f81547ccfc0) of class UIInputSetHostView. It is possible that this object was over-released, or is in the process of deallocation.

代码如下:
`

  • (void)addToKeyboardView:(UIView *)keyboardView {
    if (_keyboardView == keyboardView) return;
    if (_keyboardView) {
    [self removeFrameObserver];
    objc_setAssociatedObject(_keyboardView, &_YYTextKeyboardViewFrameObserverKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }
    _keyboardView = keyboardView;
    if (keyboardView) {
    [self addFrameObserver];
    }
    objc_setAssociatedObject(keyboardView, &_YYTextKeyboardViewFrameObserverKey, self, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    }

  • (void)removeFrameObserver {
    [_keyboardView removeObserver:self forKeyPath:@"frame"];
    [_keyboardView removeObserver:self forKeyPath:@"center"];
    [_keyboardView removeObserver:self forKeyPath:@"bounds"];
    [_keyboardView removeObserver:self forKeyPath:@"transform"];
    _keyboardView = nil;
    }

  • (void)addFrameObserver {
    if (!_keyboardView) return;
    [_keyboardView addObserver:self forKeyPath:@"frame" options:kNilOptions context:NULL];
    [_keyboardView addObserver:self forKeyPath:@"center" options:kNilOptions context:NULL];
    [_keyboardView addObserver:self forKeyPath:@"bounds" options:kNilOptions context:NULL];
    [_keyboardView addObserver:self forKeyPath:@"transform" options:kNilOptions context:NULL];
    }

  • (void)dealloc {
    [self removeFrameObserver];
    }
    `
    keyboardView的声明是这样的 __unsafe_unretained UIView *_keyboardView;
    是不是因为 _unsafe_unretained 的原因导致的问题?
    如果是的话 要怎么做才能避免呢?

关于bad access的疑问

image

为何这个分类要设置为MRC呢,可以考虑到的是因为源码是MRC的,所以freeZombie调用会更加安全吗

关于array或disctionary中NSNull 类型value的问题

NSArray等容器类中不允许插入nil对象 ,所以在接收到后台数据解析时,比如,有时空NSString会被解析成NSNull类型插入到容器类对象中,正常通过objectAtIndex获取是没有问题的,但当我们仍然把NSNull当做NSString来调用一些方法时(比如 [object length]),就会报unrecognized selector crash

关于Unrecognized Selector防护的疑问

Hello, 我在阅读代码的时候发现防护之后都调用的 baymaxProtected 方法,这个方法的返回值为空,那如果我需要防护的是有返回值(如CGFloat)这样的,这个方法会不会有问题呢?

关于dealloc swizzleInstanceMethod处理优化建议

因KVO防护需求,需要在dealloc中做一些处理,所以重定向了dealloc。但会引发原有dealloc方法的未处理,所以[self swizzleInstanceMethodWithOriginSel:NSSelectorFromString(@"dealloc") swizzledSel:@selector(baymax_dealloc)];应改为替换并添加原有dealloc消息转发。

EXC_BAD_ACCESS相关疑问

阅读源码的时候看到关于 野指针crash防护 这块, 主要的策略是建立队列存放zombie对象,用来替代已被释放的对象来处理方法来避免崩溃。 这里有些疑问:如果队列开的小了,那么页面复杂的时候,实际上能起到保护作用的比较少,队列开的大了,又会比较消耗内存,不知可有什么好的方案或者策略呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.