Last active
May 28, 2019 19:37
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if UNITY_TVOS | |
namespace UnityEngine | |
{ | |
namespace tvOS | |
{ | |
public class Application | |
{ | |
[System.Runtime.InteropServices.DllImport("__Internal")] | |
extern static public void ExitToHomeScreen(); | |
} | |
} | |
} | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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