Closed RichDaddyCashMany closed 3 months ago
#import "OneSignalHook.h"
#import <objc/runtime.h>
@implementation OneSignalHook
+ (void)load {
[OneSignalHook swizzleOneSignalLifecycleObserverMethod];
}
+ (void)swizzleOneSignalLifecycleObserverMethod {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = NSClassFromString(@"OneSignalLifecycleObserver");
if (class) {
SEL originalSelector = NSSelectorFromString(@"didBecomeActive");
SEL swizzledSelector = @selector(swizzled_didBecomeActive);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod([self class], swizzledSelector);
BOOL didAddMethod = class_addMethod(class,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
} else {
NSLog(@"OneSignalLifecycleObserver class not found");
}
});
}
- (void)swizzled_didBecomeActive {
NSLog(@"-[OneSignalLifecycleObserver didBecomeActive] deny");
SEL originalSelector = NSSelectorFromString(@"swizzled_didBecomeActive");
if ([self respondsToSelector:originalSelector]) {
((void (*)(id, SEL))[self methodForSelector:originalSelector])(self, originalSelector);
}
}
@end
Hi @RichDaddyCashMany thank you for reaching out about this behavior.
I see you are asking about badge count being cleared and reset to zero when the app is foregrounded.
Actually, this is the default behavior. Please see our docs on iOS Badge Behavior.
If you want to prevent our SDK from automatically clearing badges set OneSignal_disable_badge_clearing
to YES
as a Boolean type in your .plist
in Xcode.
How can we help?
iOS app后台进入前台的这个库居然会自动清除角标,真是无语,还好我是老iOS
Code of Conduct