I found an issue, I have a project which has both Swift and objective - C files. I have added NSnotificationcenter addobserver, which works fine in debug mode, but when I generate IPA (release mode) then it does not work. I have added observer in Objective-C class and posting it from Swift class.
Swift Class: On a button click
@IBAction func btnBackTapped(_ sender: Any) {
let testManager = TestManager.init(window: appdel?.window, andApplicationViewController: splitViewController!)
NotificationCenter.default.post(name: NSNotification.Name(rawValue:"test"), object: nil)}
> Objectice - Class:
-(id)initWithWindow:(UIWindow *)w andApplicationViewController:(UIViewController *)avc {
self = [super init];
if (self)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(testMethod:) name:@"test" object:nil];
}
return self;
}
-(void)testMethod:(NSNotification *)notification {
NSLog(@"testMethod called ");
}
Notes: I have noticed one more thing once I work with Xcode 11 version then it works in both cases. (Release and debug mode works fine). The issue only I faced in Xcode 12 versions, debug mode only. I found the issue and fixed now working fine even in debug mode. Issue: I have created an object of class TestManager in the local method. So class destroys at the time notification fire. That's why the other class notification method does not call. Fixes: I have created the object of class TestManager as Global instead of local method. And now working fine.
I have posted this question for two reasons: First one: if someone facing the same issue then can try, as I searched a couple of hours then I was not able to find the issue, because as this issue was only in debug mode, So I was not aware of how to run release mode in Xcode and set breakpoint. I found a way by which you can run from Xcode in release mode as well, no need to create IPA and install it every time. Go to edit scheme > Select run and info tab > Build confirmation > change it debug mode.
Second: May please someone tell me why it works in debug mode and why does not work in release mode when I created another class object in the local method instead of global. Any suggestion will be great, Thanks in advance. Happy coding.