- Home /
Can I update PlayerPrefs when iOS app triggers a memory warning
I would like to be able to check at the time when I'm about to load a level if the app has received a memory warning; is that doable?
To save you looking through the forum, look in AppController.mm for:
- (void) applicationDidReceive$$anonymous$$emoryWarning:(UIApplication*)application { }
and add the following into the method:
UnitySend$$anonymous$$essage("$$anonymous$$emoryController", "Received$$anonymous$$emoryWarning","$$anonymous$$emory warning, yo!");
Drag Ben BearFish's script onto a game object in your scene and name the game object $$anonymous$$emoryController.
Answer by Ben-BearFish · Oct 24, 2012 at 12:41 AM
You have to modify the AppController.mm file to get a message. Check here for an explanation:
Here's my C# code:
using UnityEngine;
using System.Collections;
public class LowMemoryManager : MonoBehaviour
{
//Function is called when a lowMemoryWarning is received
public void ReceivedMemoryWarning(string message)
{
Debug.Log("Low Memory Manager RECEIVED LOW MEMORY WARNING!");
Resources.UnloadUnusedAssets();
Prefs.Save();
}
}
Answer by Paulius-Liekis · Dec 16, 2014 at 04:19 PM
You don't have to modify AppController.mm anymore. See the last answer here: http://answers.unity3d.com/questions/291788/is-there-a-way-to-tell-in-unity-ios-when-ondidrece.html
#import "UnityAppController.h"
@interface MyOwnAppController : UnityAppController {}
@end
@implementation MyOwnAppController
- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application {
printf_console("WARNING MY OWN APP CONTROLLER -> applicationDidReceiveMemoryWarning()\n");
}
@end
IMPL_APP_CONTROLLER_SUBCLASS(MyOwnAppController)