i know how to handle user response to notification in UIKit, but how to do it in swiftUI.
swiftUI view are all struct and can't conform to UNUserNotificationCenterDelegate, is there a work around?
Related
I am creating an alert using UIAlertController and I would like the alert to display on whichever view controller is currently being displayed. This application has about 30 different view controllers and I need the alert to display on whichever view is currently being displayed. Does anyone have a suggestion to do this in the easiest manner.
I am using NSTimer to call a function on one of the views every 30 seconds, looking for a response from a SOAP service. I would like to be able to know which view is currently in use and display the alert if there is a response from my SOAP service.
You probably want the code that is polling for the SOAP service to generate a broadcast notification, and each of your viewControllers would be observing for that notification. It's possible that all of the viewControllers would get the notification at the same time, but I suspect that only the foreground viewController could act on it (or, you need some way for the viewController to know that it is the active viewController and if not the active one, ignore the notification). Or, you could do the addObserver when the viewController appears, and remove the observer when the viewController disappears.
See this post:
Send and receive messages through NSNotificationCenter in Objective-C?
self.window?.rootViewController?.navigationController?.topViewController return top view controller on the stack
Is it possible in iOS to register on AppDelegate for notifications for all viewDidAppear which happen in this app? I want to have register for those to do some analytics processing for my app, without the need to explicitly trigger my class from every single viewDidAppear.
Any suggestions how this could be done?
Thanks!
You would have to subclass UIView and register the notification and post it from that subclass. All your views in your app would need to be instances of your subclass.
I have set up push notifications successfully on my app but I want the user to go to a certain view when the swipe the notification (iOS 5) opposed to just starting the app up.
The view controller is called statsViewController
Does anyone know how to do this? Thanks in advance
You can add a custom dictionary to your push notification payload. See Apple's push notification guide. When you receive the notification, grab the payload and load the view controller based on what's inside.
I receive my push notification successfully but when I tap on it, it simply takes me to first view when my app loads.
I want the user to go to specific views depending on the push notification because the user will be receiving many different push notifications (1 for each soccer team, hence possiblity of many different views).
So example: I have a view controller called manchesterUnitedView and somebody just scored so the user receives a push notification for that particular view. When they press it, I want it to take them to the manchesterUnitedView.
Does anyone know how to do this?
thanks
You can use the payload of the notification to pass the information you need to the app, then retrieve it and use it when the app is launched as a result of the user tapping on a notification.
To do this just add a custom dictionary to the JSON payload of the notification and add the information you need to pass to the app there.
See here for details on the payload format.
You can then retrieve your custom dictionary when the app is launched in the application:didFinishLaunchingWithOptions: method implementation of your UIApplicationDelegate and use it to initialize your application state.
See here for documentation of how to retrieve the payload in your UIApplicationDelegate.
I am also interested in this.
The following should work:
I receive the Push on my iPhone and after clicking the "View" Button the App should open, and then i can read the full message.
just like here on this site (bottom): http://www.myfitapp.de/fitnessstudio-app/push-nachrichten/
I´m building an app which simulates an Inputstream of information from a sensor. When information are detected and parsed I want to send Notifications, that will be observed
by the different views which update themselves to a given timeintervall.
Is its MVC compliant to use Notifications to get a connection from Model/Controller to the View?
I´m asking because I´m often reading about Views sending Notifications to the Controller when a User interacted with the UI.
Thanks
The view is supposed to be just a view and should not have to receive notifications to update itself. I am not saying I have not done this myself as it work having the view update itself. I would recommend that you design your application so that your view controllers receive the notifications and update the views appropriately. Use your views to display and interact with the user sending any interaction updates to your view controller and the view controller sending any display updates to the view.