Is there a way to determine whether a Windows Store app is suspended? - windows-8

I'm building a Windows Store app and it pops up toast notifications from time to time. I also have an animation that plays to show when something has updated. Both of these happen at the same time.
What I would like is to not show the toast when the app is running.
So, is there a nice easy way to determine this or do I have to manually track the state via the suspending/resuming events?
Edited info:
The solution has a background task project which goes off, gets the data, then decides if anything has changed that the user needs to know about.
If so, it creates a toast, updates the tile badge, and plays an animation to fade in the new data.
The issue is that I don't want to show the toast and update the tile badge if the user has the app full screen. Similarly, playing the animation isn't needed until the app is resumed (that's the easy part though).
I realize I could solve it by having one timer that works when the app is running, and a separate background task for when it's suspended but that seems like overkill in this case.

The simple answer here is that if your app is suspended, your code won't be running.
If you want to pop up toasts when your app is suspended, you'll either need to use the WPNS or a background task to track changes.

Related

React Native lifecycle and restarts

Firstly, apologies for the slightly open ended questions but I can't find the info I'm looking for in other questions.
I'm trying to understand the lifecycle of a RN app on both iOS and Android. I understand the app bootstraps when you first start it and stays running while the phone is alive, but what happens when the user switches to a different app and comes back, or their screen times out then they switch it back on? It would be really annoying if the app restarted just because they briefly switched to check their email.
My specific use case (not particularly important to this generic question but included for context) is that I'm trying to build a game with socket.io connections and I'm wondering if I can hook into events to see if the app has been in the background or if I even need to. I have found a way of forcing a restart which may be necessary at some points, but I'd rather just try to reconnect things that have disconnected if I can find out when that happens.
Any push in the right direction would be appreciated.
The app doesn't restart when it goes in the background as you describe. The app keeps its state and the user sees the last screen they visited.
You should have a look at react native's AppState
https://facebook.github.io/react-native/docs/appstate
Using AppState you can addEventListeners that capture the change of the app's state like when going to background.
Of course there are also some problems here...
You can't capture the "kill "event. You can only detect if the app is sent to the background but unfortunately you can't detect when the user chooses to "kill" the app
You can't run any code while your app is in the background. This might be serious in your case but you should evaluate it. For example if you have a timer and you sent the app to the background then the timer stops.

iBeacon entry.exit callback when app is force killed by swipe up iOS

I read in many places that if user swipes up and kills an app, that app will not be able to receive location updates. I get didEnterRegion and didExitRegion callbacks are received when my app is not killed and is in background. But if I swipe kill app, app doesn't get those callbacks. My question here is,
Is it that app will stop getting callbacks ever? i.e., even if the app is launched again and is in background it does not get the callbacks
I read about startMonitoringSignificantLocationChanges and background app refresh when used together, I can get callback even when app is killed by swipe. I tried this and could not get it working. Is this the expected behavior?
Will startMonitoringSignificantLocationChanges and background app refresh together when used, I get region entry/exit callbacks after rebooting device?
This is not expected behavior. You are supposed to get didEnterRegion and didExitRegion callbacks even after killing an app in the task switcher. If you are not seeing this, something may be wrong with your app or testing methodology. Posting code may be helpful.
A few caveats and tips:
Make sure your app has obtained backround permission with locationManager.requestAlwaysAuthorization(). Without it, it cannot detect at all in the background.
Detection in the killed state did not work on iOS 7.0.x. It started working as of 7.1+.
Make sure you wait long enough to get detections. In some app states, it can take up to 15 minutes.
Before killing your app in testing, check logs to ensure you know what CoreLocation thinks is your current region state. If you turn off a beacon then kill your app, CoreLocation may not have had time to realize the beacon disappeared, thinking it is still inside the region. If you then turn on the beacon, you will not get a new entry event because it thinks you are already inside.

How can I detect/observe when third party app launches a full screen process?

I would like to build a helper app for gamers, and to build some extra functionality I would like to observe/time certain third party games behaviors, more specifically when the game actually launches the full screen process.
For example: my app is a system tray app, the game has a "launcher" app with lobby and menu screens. Once the game launches the extra process, usually OS X will switch resolutions (optionally) and my App would be notified somehow. Then I can start a timer. Once game match finishes, either the process is closed, or the game is not full screen anymore, my app gets a second notification and I can stop the timer.
Are there official Apple APIs that provide any way to observe/poll for the app going full screen and/or launch additional windows that I can reliably assume it's the actual game screen?
I doubt you're going to find a completely comprehensive solution. There are many ways for apps to achieve a full-screen experience and most don't provide a notification about that fact.
A full-screen app can modify the presentationOptions of NSApplication to hide the Dock and menu bar. Another app can use key-value observing to monitor its application object's currentSystemPresentationOptions property, which will reflect the current system status.
A full-screen app can capture the displays (although Apple discourages this technique). You can try to detect this by calling CGDisplayIsCaptured(), although it's been deprecated since 10.9 with no replacement. It may be possible that, if you register a callback with CGDisplayRegisterReconfigurationCallback(), you'll get called when something captures the display. However, capturing the display is sort of about preventing other processes from noticing such changes, so maybe not. In that case, you'd have to poll. You might also poll for the current display mode; changing the mode is the primary reason why a game would capture the display in the first place.
A full-screen game could also just create a borderless window the size of the screen and set its window level to be in front of the Dock and menu bar (and other apps' windows). There's not really a notification about this. You could detect it using the CGWindowList API, but you would have to poll. For example, you could call CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID) and iterate through the dictionaries looking for one the size of the screen and at a window level above kCGStatusWindowLevel.
(You might be able to use the Accessibility API to get a notification when the frontmost window changes, so you'd only have to poll when that happens.)
You cannot observe a notification if there is none. So firstly you need to know if the app you want to observe is actually sending a notification that is observable. You cannot 'hook' into other apps without their planned consent.

iOS: Update UI while in Running in Location Services Background

I have a simple app that uses location services, and registers to run in the background. I update a simple tableView with location data. This data is still being received when the user leaves the app and does something else.
Currently I am calling a method in my - (void)applicationWillEnterForeground:(UIApplication *)application to update the UI, but there is still a split second when the app opens, and the UI gets updated.
I have also tried to do periodic UI updates when in the background, but not surprisingly this doesn't seem to work.
Are there any solutions out there so that I can have the UI fully updated when the user brings the app back into the foreground?
The best solution would probably be to profile and see why you have any delay at all before displaying new data. It's quite possible you could do some things to get ready for the display to arrive, like doing Core Data queries ahead of time (they can take a significant amount of time).
An alternative would be to dump a blank UI bitmap from the screen as you were being suspended, and write to it directly based on activity - then when the application resumes, briefly show that bitmap as a screen overlay before showing the real complete UI.

Save Button Pushes and Location

I am making an app where I need to know
every button that was ever pushed by the user in the app, and when it was pushed, and
where the iPhone has gone (using gps), but there are no cell towers in the area so I can't use that significant location changes method everyone uses.
It seems to me like the Plist method for data saving won't work because I don't want the app to start where it left off, I want it to start at the beginning every time.
Also, if any of you have any idea how I can make my app wake up at certain specific times, and/or how I can make it impossible to exit, that would be awesome. This is for an experiment with the University of Queensland St. Lucio Psych Department and the Grute Eylandt Aborigines.
You can know everything the user does in your app if you want. You could use your own solution with an SQLite database for example, and dispatch the data to a server every once in a while.
The GPS is also easy, you could just track the user with the Core Location framework.
You can't make the app wake at specific times, the best you can do is implement push notifications but it's up to the user to open the app via the notification or by themselves by tapping the app icon on the iPhone home screen.
Otherwise you could set up a local notification just before exiting the application, this is faster and easier to implement then setting up push notifications.
There is also no way to stop the app being closed, that is until iOS 6 comes along with it's accessibility features, you can disable the home button then. But not now.