Hi,
in my Unity iOS app I want to catch the memory lack to avoid the "Message from debugger: Terminated due to memory issue" and consequent crash.
I followed this thread:
http://answers.unity3d.com/questions/291788/is-there-a-way-to-tell-in-unity-ios-when-ondidrece.html
In Unity I added a GameObject called "MemoryManagerObj"; on it I attached the following cs script:
using UnityEngine;
public class MemoryManager : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void LackOfMemory(string MemMsg) {
Debug.Log ("LACK OF MEMORY!!!");
}
}
In folder Plugins/iOS I added the following iOSMemoryController.mm:
#import "UnityAppController.h"
@interface iOSMemoryManager : UnityAppController {}
@end
@implementation iOSMemoryManager
- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application {
printf_console("WARNING MY OWN APP CONTROLLER -> applicationDidReceiveMemoryWarning()\n");
UnityPlayer.UnitySendMessage("MemoryManagerObj", "LackOfMemory", "Message");
}
@end
IMPL_APP_CONTROLLER_SUBCLASS(iOSMemoryManager)
I builded the Unity project and open in Xcode. Now when there is a memory issue I've this message:
WARNING MY OWN APP CONTROLLER -> applicationDidReceiveMemoryWarning()
SendMessage: object MemoryManagerObj not found!
Message from debugger: Terminated due to memory issue
though the GameObject named MemoryManagerObj exists.
Where I'm wrong?
Thank you!
↧