Generating alert to User when didReceiveMemoryWarning is called

前端 未结 3 1793
长发绾君心
长发绾君心 2021-01-26 03:22

I\'ve seen some apps that generate a warning when low memory is detected. I tried to do this in my app but ran into a problem. Using the simulator to simulate a memory warning

3条回答
  •  长情又很酷
    2021-01-26 04:07

    As I understand it, you'll likely get this just before your app crashes (or is killed). If you manage to free up memory, the app may survive (but isn't guaranteed to).

    There might be a few legitimate use cases. Since it's usually a prelude to a crash, you might want to warn the user of this. This could take the form of a message like: "Your device is low on memory. As a result, this application may unexpectedly exit. If the problem persists, try powering the phone off and on again". Assuming all is well, this shouldn't appear - so you may want some warning if it does.

    This might be more common on jailbroken phones, where the popular 'backgrounder' app allows applications to be run in the background (often until this very condition occurs - at which point they're forcibly exited - see the comment here for example).

    To work around the problem of the event being triggered 11 times consecutively.. You could rate limit the popup. For example: when you display, store the seconds since the epoch. Then - check that a certain amount of time has passed before displaying it again.

提交回复
热议问题