• AppDelegate 中调用UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCente一定几率下出现 #28502 NSInternalInconsistencyException Invalid parameter not satisfying: bundleProxy != nil


    2019年2月27日:

    修复bug:

    查找资料:

     

     

     

    解决方式:添加分类,对系统方法替换,做非空校验

     #import "UNUserNotificationCenter+Hack.h"

    #import <objc/runtime.h>

    @implementation UNUserNotificationCenter (Hack)
    + (void)load {
    static dispatch_once_t _onceToken;
    dispatch_once(&_onceToken, ^{
    [self safeHook];
    });
    }

    + (void)safeHook {

    /*hook UNUserNotificationCenter's systemMethod - (id)initWithBundleProxy:(id)arg1;*/
    NSString * orig_initWithBundleProxyName = @"initWithBundleProxy:";

    SEL orig_initWithBundleSelector = NSSelectorFromString(orig_initWithBundleProxyName);

    if (![self instancesRespondToSelector:orig_initWithBundleSelector]) {
    return;
    }

    SEL alt_initWithBundleSelector = @selector(hk_initWithBundleProxy:);
    Method origMethod = class_getInstanceMethod(self, orig_initWithBundleSelector);
    Method altMethod = class_getInstanceMethod(self, @selector(hk_initWithBundleProxy:));

    class_addMethod(self,
    orig_initWithBundleSelector,
    class_getMethodImplementation(self, orig_initWithBundleSelector),
    method_getTypeEncoding(origMethod));
    class_addMethod(self,
    alt_initWithBundleSelector,
    class_getMethodImplementation(self, alt_initWithBundleSelector),
    method_getTypeEncoding(altMethod));

    method_exchangeImplementations(origMethod, altMethod);
    }

    - (instancetype)hk_initWithBundleProxy:(id)arg1 {

    if (nil==arg1||NSNull.null==arg1) return nil;
    // return [self hk_initWithBundleProxy:nil]; //crash
    return [self hk_initWithBundleProxy:arg1];
    }

    @end

  • 相关阅读:
    100 余个网页设计优化案例(用户体验、交互优化等方面)
    Tinyhttpd 源代码初步解读
    emlog pro 文章编辑器(editor.md)的快捷键
    什么是 CSS 设计模式
    原生 JS 实现 HTML 转 Markdown,以及其实现逻辑(html2md.js 或 html2markdown.js)
    【Example】C++ 回调函数及 std::function 与 std::bind
    【Example】C++运算符重载
    【小记】Linux find 配合 rm 命令安全批量删除文件
    【小记】Linux 快速查找并结束僵尸进程
    【Example】C++ 标准库多线程同步及数据共享 (std::future 与 std::promise)
  • 原文地址:https://www.cnblogs.com/coolcold/p/10454867.html
Copyright © 2020-2023  润新知