Skip to content

Instantly share code, notes, and snippets.

@zaikman
Last active May 28, 2019 19:37
Show Gist options
  • Save zaikman/229e74411a26073bd367e2c1acd33678 to your computer and use it in GitHub Desktop.
Save zaikman/229e74411a26073bd367e2c1acd33678 to your computer and use it in GitHub Desktop.
A sub-classed UnityAppController that allows a tvOS application to be manually suspended, to circumvent Unity issue #1134856. To use, place both files in a Plugin/tvOS folder in your Unity project and call UnityEngine.tvOS.Application.ExitToHomeScreen to suspend the application.
#if UNITY_TVOS
namespace UnityEngine
{
namespace tvOS
{
public class Application
{
[System.Runtime.InteropServices.DllImport("__Internal")]
extern static public void ExitToHomeScreen();
}
}
}
#endif
#import "UnityAppController.h"
@interface SuspendableAppController : UnityAppController
-(void) exitToHomeScreen;
@end
static SuspendableAppController* delegateObject;
@implementation SuspendableAppController
-(void) startUnity: (UIApplication*) application {
[super startUnity: application];
delegateObject = self;
}
-(void) exitToHomeScreen {
UIApplication *app = [UIApplication sharedApplication];
[app performSelector:@selector(suspend)];
}
extern "C" {
void ExitToHomeScreen() {
[delegateObject exitToHomeScreen];
}
}
@end
IMPL_APP_CONTROLLER_SUBCLASS( SuspendableAppController )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment