Suppose App is in foreground and user does not interact with app for 5 min, App should give alert.
Suppose App is in background and it remain in background for more than 5 min App should give alert as soon as app comes in foreground.
Is there any standard way to do that?
For the background part, basically you want to have a Counter. This Counter should do
Observe UIApplicationWillResignActiveNotification notification. And record the time when the selector is called. Let's say it's lastActiveTime.
Observe UIApplicationDidBecomeActiveNotification notification. And inside the selector, compare the current time with lastActiveTime. If it's more than 5 minutes, you'll pop up the alert.
For foreground, you could use some assumptions such as if the top most view controller is the same, assume the user hasn't interacted with the app. You can have a timer that keep checking the top most view controller.
Related
In my app at the time app the launches first time there is an animation on first UIViewController for only 5 seconds. The problem is when app launches first time animation starts and Notification enable alert pop's up, so animation is hidden behind the notification enable alert and as soon as user tap ok on notification alert; animation ended. Because of this notification enable alert user can't see full animation. Please provide suggestion how to fix this ? Is there any way to delay notification enable alert to show after some delay ?
I'm guessing your requesting authorization for notifications in your didFinishLaunching (or perhaps somewhere else). Where ever you're doing it just move it to the completionHandler of the animation and from there add a 5 second delay using asyncAfter.
When I open the app it fires the events viewDidLoad and viewDidAppear form my View Controller but when I close it and run it again it does not call any of them.
Any idea?
You need to read up on application states. Here is a link I found online outlining the different states:
http://www.techrepublic.com/blog/software-engineer/understand-the-states-and-transitions-of-an-ios-app/
What you really want is to be notified when your app becomes active.
Probably the easiest way is to implement the function applicationDidBecomeActive() in your app delegate. That will be called when your app becomes active as the foreground app either on launch, or when it returns to the foreground as the active app.
Note that if you want that notification sent to some object other than the app delegate you can listen for the UIApplicationDidBecomeActive notification.
I am making an app with multiple schedule alarms in the future. The design is that a Local Notification will fire, then when the user opens the app any time after this notification (either through Notification Action or just by tapping the icon on the home screen), the app will automatically show an Alarm view controller, which the user interacts with.
I know I can just call on a function with performSegueWithIdentifier with the Notification Action feature, but I would really like a comprehensive method that covers the case when the user ignores the notification, then launches the app with other methods.
Thank you for your help!
I'm confused about UIApplicationDidBecomeActiveNotification. I can register an observer for this notification, and receive signals when the app becomes active from the background or when being launched. However, when I pull down the hidden top popup view (for general information: notifications, weather, stock market) then pull up to hide it, the signal is also generated.
I use a callback method hooked with this signal to refresh my app, so this can be annoying for users of my app.
Can anybody help me differentiate these cases?
Maybe you should try UIApplicationWillEnterForegroundNotification, the apple doc has said:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html
UIApplicationDidBecomeActiveNotification: Posted when the application becomes active.
An application is active when it is receiving events. An active application can be said to have focus. It gains focus after being launched, loses focus when an overlay window pops up or when the device is locked, and gains focus when the device is unlocked.
I found lots of "reloadData" for TableView questions here, but my case is different.
I have a notification App, that uses UILocalNotification to fire reminders.
I need to refresh my tableview in real time after an alert fires, without the need of closing and opening the app to do so...
Example:
User is viewing the scheduled reminders (tableView), when suddenly one of the reminders fires. At this moment, the tableView will reload, but only if the user quits application or go back to another view and open the tableView again. That can't happen cause the application breaks if the user press the row in the tableView witch showed the current reminder (that's already completed and doesn't exists anymore).
I need to reload tableView in real time, without leaving the tableView Controller view. any idea on how to do that?
When a local notification for your app fires while the app is in the foreground, the system sends the application:didReceiveLocalNotification: message to your app delegate. From there, you should notify the view controller (via a direct reference and message send or possibly with a custom NSNotification) to do whatever it needs to do in this case.