データを渡すために、unity 3d と iOS の間にブリッジがあります。extern "C" を使用して unity 3d から iOS にデータを正常に送信できます。その後、extern "c" のメソッドから目的の c メソッドを呼び出すことができます。しかし、目的のCメソッドから、別のビューコントローラーをプッシュしたい場合、クラッシュして次の問題が表示されます。
A view can only be associated with at most one view controller at a time! View is associated with Clear this association before associating this view with...
この問題を解決するにはどうすればよいですか?
これが私のView Controllerクラスです:
@implementation ARViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Just setting Unity delegates and view to add it as subview for my main view.
// This allow me to add a UIButton above the UnityView to popViewController or anything i want to make native in iOS.
unityViewController = [[UnityDefaultViewController alloc] init];
unityController = (UnityAppController*)[[UIApplication sharedApplication] delegate];
unityViewController.view = (UIView*)unityController.unityView;
[viewToUnity addSubview:unityViewController.view];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)gotoAnotherViewController
{
ViewController *arVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ClickVC"];
[self presentViewController:arVC animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
});
}
@end
extern "C" {
void _NativeMethodName(const char* stringValue)
{
[[ARViewController new] gotoAnotherViewController];
NSLog(@"Passed string value: %s", stringValue);
}
}