My project is Unity in Native integration, had problem with clang error: Build failed refer image. I had gone through other sources in stack overflow to clear with clang error. I tried to remove my main.mm file, then build get succeeded but app will crash when calling unity screen. So I have to keep both files AppDelgate and main.mm file. Couldn't fix this....issue. if anyone could please..
Based on your question, hope that it's unity in swift native integration.
NOTE: This solution is only for case: Unity in Native iOS
From your screen shot it show that you are using 2 main files in Xcode. There are 2 options to fix this out.
Option 1) you may keep both files in Build Phases --> Compile sources , but in your AppDelegate, command @UIApplicationMain
import UIKit
//@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
.......................................}
This will build succeeded and unity view appears at initial stage.
Option 2) If you want to show unity view with button, Remove your main.mm file from Build Phases --> Compile sources , so app won't crash in unity view by using 'shared window appDelegate' and try this code in your AppDelegate (uncommand @UIApplicationMain)
func unityWindow() -> UIWindow? {
return UnityGetMainWindow()
}
func showUnityWindow() {
unityWindow()?.makeKeyAndVisible()
}
func hideUnityWindow() {
window!.makeKeyAndVisible()
}
then, in your View Controller
private var isShowUnityWindow = false
override func viewDidLoad()
{
super.viewDidLoad()
isShowUnityWindow = false
}
@IBAction func startUnityandHide(_ sender: UIButton)
{
isShowUnityWindow = !isShowUnityWindow
var appDelegate = UIApplication.shared.delegate as? AppDelegate
if isShowUnityWindow {
appDelegate?.unityWindow()!.frame = CGRect(x: 40, y: 200, width: 300, height: 300)
appDelegate?.showUnityWindow()
} else {
appDelegate?.hideUnityWindow()
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.