Jump to specific UITableView on application:didReceiveRemoteNotification: - iphone

When my app receives a Push Notification, application:didReceiveRemoteNotification: receives the data. When the user open the app from a notification, I want to jump to the last UITableView in the stack, to display the 'details' related to the Push Notification.
I am able to jump to the correct tab in the UITabBar.
Is there a way to Push views in that Tab from the App Delegate, or am I going about this the wrong way?

If you're already able to jump to the correct tab, you're almost there.
One way to do it would be to save off the push alert information into nsuserdefault... maybe in a form of a dictionary object in the "didReceiveRemoteNotification". It's like of like save off a cookie web development for later use.
Then for the viewcontroller you're displaying in the tab that you jump to, you could do a check in viewWillAppear and see if you have anything stored in your nsuserdefault and grab the saved off notification data there and you can look up the corresponding data in your UITableViewDataSource.
Once you have that, you can call or do what ever you'd normally do had you selected the same data/object represented by a table cell and push the desired view (controller) into view.
Make sure to remove the object saved in NSUserDefault once you're attempted to push the view.

Related

Go back to view controller with cached data

I'm building an app which has 4 screens, on the second screen the user will set time by date-picker on tableview.
There are few times to be set (depending on array.count).
On the third screen the user will set the location, and on the 4th screen user will see info from API and the time has been set by the user, also on tableview cells.
In case the user wants to change or update the time he set in one of the cells to different time, I need to be able to go back to the second view with all the input user added already remain, and the user can change only the cells they want to change, without adding all the time all over again.
When I'm using segue it creates a new 2nd vc and all the previous info erased.
I thing you have to use delegate to propagate this information from whichever screen to which ever screen you want. In Order to achieve that you have to loose the segue.
https://medium.com/#nimjea/delegation-pattern-in-swift-4-2-f6aca61f4bf5
In this link Delegation pattern is explained very well. Please refer that.

iOS 5.x - Detect when a view appears on screen

How do I detect when a certain view appears while the app is running? e.g. in a tab bar app let's say we have 2 bars "Results" and "Edit" - the app loads with results and there is nothing. Now, users goes to edit and makes some magic. Then, he presses the results bar again, and he will see the results. In other words, I need to pass the information from "edit" view controller to "results" view controller when the results bar is pressed. I hope I made this clear. Thanks in advance!
There's a few ways to approach this problem.
1) you could keep a handle (or pointer, or property) to the "Results" view controller from your "Edit" view controller and when you want to send data to "Results", that'll be easy to do (via a method or a delegate protocol).
2) you could register the "Results" view controller for notifications and then when you want to update it with any new data, populate your fields when the proper notification comes in. And over in your "Edit" view controller, post a notification with a dictionary and/or object that encapsulates the results you want to display.
And there's more!

Reset the whole view

I have a UITabBarController, each tabs governs it's own UITableViewController. I have a singleton User object in my app and I also have a logout button in which logs out the user and presents a modalViewController of the login page. When I logout I also have the User object to send a postNotification to the three UITableViewController in order to reset the view and stuff. The question is how do I reset the view so it's fresh like when someone starts with the app again, clearing previous data? What's the best way to do this? Thanks
When each tableview controller receives the notification, it can just empty the data array and reload the table.

Reload View only when application is opened Again

My application has tab bar with one of the tabs having a segmented control on navigation bar.
Based on segment clicked different view is displayed using a url.
I am calling the url in viewdidload method.I do not want to use viewwillAppear to call the url as it will be called each time the view is displayed.
I only want to call the url again whenever user closes the application and comes back.
Whats the best way to do this.Should I remove the view controller from and reload it again once the application is opened.
Please use a more descriptive title for your question next time!
There are notifications for this that you can observe in your application:
UIApplicationDidBecomeActiveNotification and UIApplicationWillEnterForegroundNotification come to mind.

Push Notification Alert Handling

I have a doubt. I am building an application wherein if there is a new request is submitted I am getting a push notification in my application and on tap of "View" button in the push notification alert I need to show the request detail page. Now, normally this request detail page is 5th view in the stack. How should I handle this? Should I initialize first 4 views and put them on the stack before going to the detail page?
Also, there is a scenario where if someone is working on some part of the app and notification comes up. In that should I loose the changes on the currently opened page and show the request details if "View" was tapped on?
How should I handle this?
You can just push that view (the usual 5th view). The only thing is that when you pop that view, it will now act as the 2nd view, so theres no need to go through 4 additional views.
You can initialize and push the 5 views to your navigation controller (with animate:NO) to start the app up in the right place.
As for if you get a notification while running, that's really up to you and what is best for the app. You can always prompt the user before deleting any data. Note that if you get a push notification, your application:didReceiveRemoteNotification: instead of the alert showing.
This is commonly achieved by displaying the controller modally.
This way you don't have to recreate your view-controllers hierarchy and you don't lose the current context of your app if it was running. The user taps some "OK" button and returns to the previous screen.
For the first part of your question: if you have created your view in a decoupled way, that is, if it is not dependent on the 4 other views - i suppose then you can show this view without problems. Obviously the answer really depends whether your business rules allow this.
As for the second part of your question: you always can show an UIAlertView to your users asking whether they want to take action on the received push notification.
However - i think these problems really do not have anything to do with the nature of the push notifications, and you really should loose the "I have a doubt on push notification" part of your question :) ....
Hope this helps :)