userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: is not fired - objective-c-runtime

Able to receive the notification but delegate method is not fired after clicking on the notification.
Note :
UNUserNotificationCenter delegate received call to -userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: but the completion handler was never called.

Related

Function after presenting Alert Swift

TLDR
Is there a way to be notified before a UIAlert is going to be presented. Is there a viewDidLoad/viewWillLoad type function that can be called in a ViewController either before or after an alert pops up?
My Problem
My View Controller is receiving an alert from a method in my app delegate. My View Controller calls a method in the app delegate which can then send a UIAlert if there was a problem. While this seems like bad design, I can't change it. I need some type of way of knowing that an alert showed up.
You can try
// do before
self.present(alert,animated:true) {
// do after
}
Sol1:
Add a completion block when you call the Appdelegate func and inside app delegate return that completion like code above in // do after
Sol2:
set a delegate between app delegate and the VC that calls it
Sol3:
use
NotificationCenter.default.addObserver(
self,
selector: #selector(listenForNotification),
name: Notification.Name(rawValue: "AlertShowed"),
object: nil)
inside the VC
and this in Appdelagete alert completion
NotificationCenter.default.post(name: Notification.Name("AlertShowed"), object:"")
The function present(_:animated:completion:) takes an Optional completion handler, completion. If you provide a completion handler it gets called once the modal is displayed. You display UIAlertControllers using present(_:animated:completion:), so just pass in a completion handler.
If you are opening the alert from within a method in appdelegate, then you should some how keep a reference on your view controller and call a specific method on it before showing the alert.
Or even, you can implement a pub sub design where you’d have your controller register for a custom notification name on the Notification Center and call/post that notification from the appdelegate just before showing the alert, don’t forget about removing the observer once the controller gets closed.
The choice is yours

How to make custom notification so that whenever event occurs it will handle in iOS

Hi I want to make custom local notification so that whenever popover is visible it will handle by that notification.
so that as multiple time the popover is visible it will handle by that notification
Currently i have partially done this but problem is that if i want to run notification's selector method multiple times i have to post that notification wherever i want.
used this link to implement it
i want to send some notifications to observers when some event occurs. and i also want to know how observer catch/handle/receive that notification?
Can i make notification like, once i postNotification in viewDidLoad it will handle as many times that event occurs?
Note-See the answer posted by me
Use this
line before presenting popover
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dissmissPop:) name:#"popOver" object:popOver.contentViewController];//popOver is your name of popover
-(void)dissmissPop:(id)sender{
//method to be called
}
To call notification from popover use this
[[NSNotificationCenter defaultCenter] postNotificationName:#"popOver" object:self];
Notifications are same as broadcast receivers. If we register as broadcast receiver whenever new email arrives. But do you actually post the event notification? No. Someone else does. Similarly when keyboard is shown the notification is posted by the system. Send you only get notified.
The system posts whenever the keyboard is gonna appear. This should make it clear that if you want to post custom notifications you have to post it every time there's need for it to.
So if you make custom notification you have to postNotification when ever you want to post it.

What should I do when i cancel a NSOperation? It did not remove from queue when I cancel it

As I know, a NSOperation will remove from its NSOperationQueue when I send isFinished KVO notification and isFinished=YES, and will not remove from its NSOperationQueue when I send isCancelled KVO notification. so in my cancel function:
When the operation has cancelled before, just return.
When the operation is finished, just just return.
When a NSOperation isExecuting, its queue has send isExecuting KVO notification before, so I just send isCancelled and isFinished KVO notification, then its queue will remove it.
When a NSOperation isReady, its queue has not send isExecuting KVO notification yet, so I send isExecuting KVO notification, but I got some errors in console: went isFinished=YES without being started by the queue it is in.
My question is: What should I do when I cancel an operation which state is just ready? I want it to be removed by queue.
By the way, I have a member variable to save the sate of operation, I want the cancel function do not influence its value, so When cancel an operation which state is ready, I just send isExecuting KVO notification but isExecuting=NO, because the state value is ready. Finally, my code is:

how can we run GUI code when app is firing applicationWillResignActive:

i want to execute some GUI code ,let suppose I want to make the LED on when app fires
applicationWillResignActive: event ,
how can I do this ?
Can I delay the firing of this event until code executes or there is any other method available for doing this?
No you cannot delay this event being fired
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
You can respond by putting your code in the application delegate method
- (void)applicationWillResignActive:(UIApplication *)application;
or by observing for the UIApplicationWillResignActiveNotification notification

Responding to EKEventStoreChangedNotification

I'm trying to listen for EKEventStoreChangedNotification to check if the calendar is changed while my app is in background.
I register the observer in a view controller's initWithNibMethod like this:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(calendarChanged:) name:EKEventStoreChangedNotification object:nil];
The calendarChanged method just logs a message on the console to check if it's called.
Problem is my observer method never gets called (the observer object is still valid). From what I understand, unless an app is registered to do background execution (my app is not set up for this) the notifications of that type should be coalesced and delivered on entering foreground.
I think the "object:" needs to set with the EventStore object you're using.
Yes, you won't get called whilst you're in the background but your "calendarChanged:" selector will be called when your app' comes in to foreground.