Is there any way to manage callback when user go through web view and click button - back to app?
Asked
Active
Viewed 919 times
2

halileohalilei
- 2,220
- 2
- 25
- 52

Evgeniy Kleban
- 6,794
- 13
- 54
- 107
-
You can have a look at UIApplicationDidBecomeActiveNotification. I believe this notification will be thrown when you come back to your application from Safari or any other application. – halileohalilei Mar 02 '17 at 14:58
-
@halileohalilei ok i will try, have you test it? – Evgeniy Kleban Mar 02 '17 at 14:59
-
Nope, but it works with any other event that makes your application gain focus, so it should also work in this scenario. – halileohalilei Mar 02 '17 at 15:00
-
Possible duplicate of [Deselect table view row when returning to app](http://stackoverflow.com/questions/42473220/deselect-table-view-row-when-returning-to-app) – Mar 02 '17 at 15:03
-
@EvgeinyKleban check the duplicate link for the solution http://stackoverflow.com/questions/3639859/handling-applicationdidbecomeactive-how-can-a-view-controller-respond-to-the for Obj-C version if you don't know how to add notifications. – Mar 02 '17 at 15:05
-
1@Sneak thanks i know it :) – Evgeniy Kleban Mar 02 '17 at 15:06
-
@halileohalilei your solution work, you can answer so i can mark it as correct. – Evgeniy Kleban Mar 02 '17 at 15:07
1 Answers
4
You can bind the UIApplicationDidBecomeActiveNotification
to an action do whatever you wish when you come back to your application. It should be thrown whenever your application gains back focus for any reason.
Note that this notification will be thrown every time you app becomes active, so make sure to unbind the action after it is called once. Also it will be thrown even if the user does not tap the back button, but goes back to home screen and reopens your app.
You can also use the delegate methods in your AppDelegate
class and store the status of the app with some variables to determine when the user comes back to your app.

halileohalilei
- 2,220
- 2
- 25
- 52
-
1This will get thrown even if the app comes from background to foreground as well... so I think the best idea would be to have a boolean variable on **applicationDidEnterBackground** of **appdelegate** to determine if the has become **active** from **inactive** or become **active** from **background** or **suspended** or **notrunning** state – Durai Amuthan.H Mar 02 '17 at 15:13
-
But one more thing even if we do like this also , we'll know never its come back from other app or Did it get interrupt by a phone call ? unless apple provides a way to do it – Durai Amuthan.H Mar 02 '17 at 20:46
-
1@DuraiAmuthan.H I think that can be managed fairly easily. If the action is only bound before redirecting to another app, and unbound after the user comes back, then we need not worry about the app being interrupted by a phone call since there won't be any action bound to the notification. However, you're right, there can easily be some scenario where this approach would also fail. Best way would be to have a dedicated API by Apple, as you said. – halileohalilei Mar 02 '17 at 20:54
-
Anyhow its the nearest thing as of now one could do due to lack of API from Apple for this – Durai Amuthan.H Mar 02 '17 at 21:11