- Home /
Embedded Unity Application not displaying in iOS app
I currently have an iOS app and want to embed a Unity application as a subview within my application. I'v been struggling with this over the last couple months on and off.
I was getting issues with building my application for some time, but now it is building and running properly (almost). The view I would like the Unity application to display within isn't displaying anything.
For reference I am using Unity 2019.1.12f1 and XCode 10.3
I am NOT using Vuforia, its just a very basic Unity app with a model and basic animation.
My AppDelegate file is:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var application: UIApplication?
@objc var currentUnityController: UnityAppController!
var isUnityRunning = false
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.application = application
unity_init(CommandLine.argc, CommandLine.unsafeArgv)
currentUnityController = UnityAppController()
currentUnityController.application(application, didFinishLaunchingWithOptions: launchOptions)
// first call to startUnity will do some init stuff, so just call it here and directly stop it again
startUnity()
stopUnity()
return true
}
func applicationWillResignActive(_ application: UIApplication) {f isUnityRunning {
currentUnityController.applicationWillResignActive(application)
}
}
func applicationDidEnterBackground(_ application: UIApplication) {
if isUnityRunning {
currentUnityController.applicationDidEnterBackground(application)
}
}
func applicationWillEnterForeground(_ application: UIApplication) {
if isUnityRunning {
currentUnityController.applicationWillEnterForeground(application)
}
}
func applicationDidBecomeActive(_ application: UIApplication) {
if isUnityRunning {
currentUnityController.applicationDidBecomeActive(application)
}
}
func applicationWillTerminate(_ application: UIApplication) {
if isUnityRunning {
currentUnityController.applicationWillTerminate(application)
}
}
func startUnity() {
if !isUnityRunning {
isUnityRunning = true
currentUnityController.applicationDidBecomeActive(application!)
}
}
func stopUnity() {
if isUnityRunning {
currentUnityController.applicationWillResignActive(application!)
isUnityRunning = false
}
}
I am then using this snippet of code to display the code Unity in the subview
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.startUnity()
self.unityView = UnityGetGLView()
I am absolutely baffled as to why this is not working. Any help would be much appreciated.
Hope this is enough information. Please let me know if there is anything else you need to know.
Your answer
Follow this Question
Related Questions
How to quit unity alone from the iOS embedding app 0 Answers
ReplayKit can not include user commentary and camera footage while broadcasting 0 Answers
Embedded app in unity 0 Answers
Access photos, videos & music from iOS and Android library? 0 Answers
IL2CPP does not support marshaling delegates that point to instance methods to native code. 1 Answer