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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM