Hello!
I am trying to create a plugin for showing video ads.
I have created a view controller so that,i can use it for presenting the video ads .
Everything is working like i expected,but when i try to hide the my view controller it shows black screen.
My code looks somewhat like this…
myclass.h
#pragma once
#include "myclass.generated.h"
UCLASS(NotBlueprintable)
class Umyclass : public UObject
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable,Category = "MyClass")
static void ShowView();
UFUNCTION(BlueprintCallable,Category = "MyClass")
static void CloseView();
//If true will close myviewcontroller which was presented.
static bool ShouldClose;
};
#if PLATFORM_IOS
@interface myViewController:UIViewController
+ (myViewController*) GetSingleton;
@end
#endif
myClass.cpp
#include "myClass.h"
bool Umyclass::ShouldClose;
#if PLATFORM_IOS
@interface myViewController()<someDelegate>
@end
@implementation myViewController
+ (myViewController*) GetSingleton
{
static myViewController* Singleton = [[myViewController alloc] init];
return Singleton;
}
-(void) showTheController:(UIViewController*) controller
{
[[IOSAppDelegate GetDelegate].IOSController presentViewController : controller animated : NO completion : nil];
}
-(void) hideTheController:(UIViewController*) controller
{
[controller dismissViewControllerAnimated : NO completion : nil];
}
//protocol method which alerts when the view controller is closed.
-(void) viewClosed()
{
Umyclass::ShouldClose = true;
}
@end
myViewController* viewController = [[myViewController alloc] init];
#endif
void Umyclass::ShowView()
{
ShouldClose = false;
#if PLATFORM_IOS
dispatch_async(dispatch_get_main_queue(), ^{
[[myViewController GetSingleton] showTheController:viewController];
});
#endif
}
void Umyclass::CloseView()
{
if(ShouldClose == true)
{
#if PLATFORM_IOS
dispatch_async(dispatch_get_main_queue(), ^{
[[myViewController GetSingleton] hideTheController:viewController];
});
#endif
}
}
ShowView method is called when a button is clicked in the game.
It shows the controller and then after completing it’s work there is a close button available which when clicked, sends a message to the viewClosed protocol method which sets the ShouldClose variable to true.
I then call CloseView() method which then gets rid of myViewController.
But after this step the screen stays black.
Please Help!
Thank you!