Personalized actions on local notifications - ios

Ive been searching for this information for a day now.
I made a custom notification with some interactive buttons and 2 action buttons (send and cancel).
When I press an action button Im able to get an event on the app side, but i dont have any way to send the information fetch from the notification actions. The userInfo i receive here is the same i gave the notification.
Lets say I can selectable 5 options in the custom view.
What I'm attempting is to return to the app which buttons were selected on the custom notification when the action is pressed.
How can I give the information to the app of the button that was press on the custom view (view controller)?
the response on "func didReceive" its a read only variable
Thank you

You could create a IBAction attached to your specific button, then the next step would be placing your logic inside of said IBAction. Hope that documentation can help!

So I ended up by sharing some code from the main app with the custom notification. Now the notification has direct access to the service, which is something I don't really like but with the lack of time it was the solution I choose.
To do this choose the file from the project you want the notification to have access to, and on right side in the File Inspector -> Target Membership -> Select your notification
Be aware that all the functions used in this code need to be available from the notification project

Related

IOS notification content extension: add buttons in storyboard and handle the click action

IOS notification content extension: add buttons in MainInterface.storyboard and handle the click action without dismissing the notification
after making some research I discover that:
can not handle buttons clicks in the IOS notification content extension, only the type of button can be used is the media button, see the IOS documentation:
https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextension
The up answer is not correct, you can just add UNNotificationExtensionUserInteractionEnabled YES to the info.plist, then you can do every thing just like a common viewController
As Abdullah S. Al-Hallak said, it is not possible to perform actions that will lunch a certain screen. In Apple documentation, it is mentioned that "Do not install gesture recognizers or rely on touch events in your interface."
The only possible way is to add actions that will do some things in the presented notification only (like animation, as presented in this cool post: Adding a Custom UI and Interactivity in Local and Push Notifications)

What architecture can I use to change screens in Swift when there's an event outside of the current view?

For example, I have a Notification that occurs when there is an "unauthorized" error returned from the api server that should bring the user back to the login screen. This event could appear anywhere in the program.
Do I create a new viewless controller to manage states and have it monitor for this notification and then present the login view controller?
I'm thinking about push notifications too, received by the app delegate. Some of these may cause the data model to get updated and then the screen to change. Who should make the screen change? In the past I put all this in the AppDelegate. But there must be a more elegant way!
I also found out about FlowControllers. But they don't play nicely with Interface Builder, at least according to this solution.
Please let me know if you need more specific information about my project.

Remote Notification 'application:didFinishLaunchingWithOptions:' method not called

Target: 7.0 and UP
Testing on: iPhone6 Device
I have been testing Regular Push Notifications (Remote).
I have discovered that if a user clicks on the app icon -- the "applicationDidFinishLaunching:" method is never called.
I have been reading and re-reading the guide on "Handling Local and Remote Notifications" and to confirm that I understood everything referred to: Handling Remote Notifications
It says If a user taps the default button in the alert or taps (or clicks) the app icon, then the app should call its delegate "application:didFinishLaunchingWithOptions" method. And if its a remote notification, it should call "application:didReceiveRemoteNotification:fetchCompletionHandler:".
Neither one of these methods get called if I click on the app icon.
The only method that does get called is applicationWillEnterForeground.
I do have a storyboard file. So the way it loads:
--> navigation controller --> table view controller --> so on
Am I supposed to somehow set the appDelegate in the storyboard file?
I have done a lot of research and so far I have had no luck.
My push alerts do come through so I know that it works. I just haven't been able to determine why these other methods are not being called when the user clicks on the app icon.
Any suggestions or help is appreciated.
The only solution if you want to handle when a user clicks on the app icon is to either A.) set up silent notifications or B.) Set up something on your server so that you can make a request to it to find out if there was a new update.

Global app remote notification response ios

I would like to implement a similar response system for push notifications throughout my app. When a remote notification appears and the application is in the active state I would like to place a button temporarily on the screen that performs the same action regardless of where it is in the app.
The only way I can think to do this is to create the same response to notification method in each of the app's many view controller.
Is there any way to do this in the app delegate, tab bar, or navigation bar so that the same response would apply to multiple views rather than placing the same function in each view controller separately?
Please advise and thanks
If I understood your question correctly: your problem is not related to notifications at all, but rather how to place a button on top of all views. A common way would be to add it as a subView to the window.
As a starting point: AwesomeMenu on GitHub

IOS Is there a way to send user to particular view after tapping "view" on notification?

I am using push notifications in my app and I would like to send user to particular view, not the view he last saw. Is it possible?
You need to implement the appropriate AppDelegate messages.
Specifically, you will receive the APNS payload on the application:didFinishLaunchingWithOptions:
You might also receive the payload in a different message, application:didReceiveRemoteNotification: if the application is active.
Then when you know that your app was launched because the user touched a notification, you can direct him to a specific view accordingly.
I don't think that you have control over what the user sees while app is starting app (opening animation). After the app is fully active, you can send him wherever you want to by opening proper view controllers, setting proper tab, etc...

Resources