Subclassing AppController.mm and call to applicationDidReceiveMemoryWarning not working

I have the following mm file in Assets/Plugins/iOS

#import "UnityAppController.h"


@interface MemoryAppController : UnityAppController

- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application;

@end


@implementation MemoryAppController

- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application {

    printf_console("Chicken nuggets ON A STICK \n");

    UnitySendMessage("MemoryHandlerIOS", "OnReceivedMemoryWarning","");

}

@end


IMPL_APP_CONTROLLER_SUBCLASS(MemoryAppController)

I have the following Script:

using UnityEngine;
using System.Collections;
using VascoGames;

public class ReceiveMemoryWarningHandler : Singleton<ReceiveMemoryWarningHandler> {

 #if UNITY_IOS

 public void OnReceivedMemoryWarning(string msg){
 
 Debug.Log("Memory warning received from iOS");
 Resources.UnloadUnusedAssets();

 }

 #endif
}

In my scene I have a GameObject named “MemoryHandlerIOS”. According to the manual the first parameter in UnitySendMessage should be name of the game object.

printf_console doesn’t output the message in the mm file and the Debug.Log from the class isn’t called either. However I’m not entirely sure if that’s due to the fact I have Debug Scripting off ( can’t compile if I turn that on ).

The mm file is build into the Xcode project.

Anything I’m doing wrong?

Bump…

Bump…

Remove line 7 from your .mm and make sure your GameObject and unity C# class names are both MemoryHandlerIOS. If that doesn’t work, try changing your derived class to MonoBehaviour instead of the Singleton.

Jim,

Originally line 7 wasn’t there either, but that didn’t work.

Singleton is derived from monoheviour. If I change the unity AppController.mm in xcode directly all calls are made fine.
It just seems like my custom mm controller doesn’t have any effect.

Any other ideas?

What is the full name of your mm file in Assets/Plugins/iOS?

MemoryAppController.mm

I don’t see any other issues… You tried changing your C# class name to match the GameObject name right?

Try adding this above the printf_console line.

[super applicationDidReceiveMemoryWarning:application];

yes

Ill try your suggestion and let you know.

Did you ever get this working? I’m having the same issue, where it seems the methods in the subclass of the app controller are never called.

1 Like

Hey @SimteractiveDev I pretty much dropped it. But I do remember a few of those debug lines popping up but not sure how or what I did. I moved on from that project. Sorry.

No worries, thanks anyway :slight_smile:

If anyone wants to know why this happens. You can’t sub class app controller in more than one place.

https://stackoverflow.com/questions/42508476/can-you-have-more-than-one-subclass-of-unityappcontroller

If I find a better solution, I’ll write.