- Home /
Open Web page embedded in unity app using native UIVIEW
Hello everyone,
The question is more to the experts who are familiar with Xcode, Objective C and plugins.
So I need to open a web page embedded in the unity app, at first searched for some plugins, but they provide limit control for example the web dialog opens in the middle of the screen .. etc
I wrote my own small plugin, here's the code:
#import <Foundation/Foundation.h>
@interface MyPlugin : UIViewController <UIWebViewDelegate>
{
UIWebView *webView;
}
@end
@implementation MyPlugin
static MyPlugin *_sharedInstance;
+(MyPlugin*) _sharedInstance
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedInstance = [[MyPlugin alloc] init];
});
return _sharedInstance;
}
-(id)init
{
NSLog(@"Init called");
self = [super init];
if(self)
[self initHelper];
return self;
}
-(void) initHelper
{
NSLog(@"InitHelper called");
}
- (void)viewDidLoad
{
NSLog(@"viewDidLoad");
[super viewDidLoad];
NSString *urlString = @"https://www.google.com";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView setScalesPageToFit:YES];
[webView loadRequest:urlRequest];
}
-(void) OpenWebView
{
NSLog(@"OpenWebView 1");
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[webView setDelegate:self];
[self.view addSubview:webView];
}
@end
extern "C"
{
void IOSOpenViewController()
{
NSLog(@"IOSOpenViewController");
[[MyPlugin _sharedInstance] OpenWebView];
}
//void IOSOpenWebView()
//{
// return [[MyPlugin _sharedInstance] OpenWebView];
//}
}
and the Unity c# code here:
public class WebViewUsingMyPlugin : MonoBehaviour
{
[DllImport("__Internal")]
private static extern void IOSOpenViewController ();
void Start()
{
OpenViewController ();
}
void OpenViewController()
{
if (Application.platform == RuntimePlatform.IPhonePlayer)
IOSOpenViewController ();
else
Debug.LogWarning ("Wrong platform");
}
}
And I have the following log:
2018-05-21 11:47:19.986689+0400 popupwebview[2117:182663] IOSOpenViewController
2018-05-21 11:47:19.986907+0400 popupwebview[2117:182663] Init called
2018-05-21 11:47:19.987115+0400 popupwebview[2117:182663] InitHelper called
2018-05-21 11:47:19.987143+0400 popupwebview[2117:182663] OpenWebView 1
2018-05-21 11:47:20.070216+0400 popupwebview[2117:182663] viewDidLoad
2018-05-21 11:47:22.085602+0400 popupwebview[2117:182819] WF: === Starting WebFilter logging for process popupwebview
2018-05-21 11:47:22.086258+0400 popupwebview[2117:182819] WF: _userSettingsForUser mobile: {
filterBlacklist = (
);
filterWhitelist = (
);
restrictWeb = 1;
useContentFilter = 0;
useContentFilterOverrides = 0;
whitelistEnabled = 0;
}
2018-05-21 11:47:22.086986+0400 popupwebview[2117:182819] WF: _WebFilterIsActive returning: NO
so far, the log show that native functions being called in the right order, or at least in the right order according to my knowledge :)
but I do not see anything on the screen, I added [webView setScalesPageToFit:YES];
later on, but didn't effect the result.
Since I am sure viewDidLoad is being called, I don't know why or for what reason or anything missing, the web page dialog doesn't show up and nthg happens.
Any hints? even if a working plugin free or paid available out there?
Thanks!!
Note that I am testing on real device (iphone 6) and not a simulator
Your answer
Follow this Question
Related Questions
Problem with ios plugin to show web view 1 Answer
Making a plugin from objective C code 1 Answer
Passing NSDictionary from obj-C to C# 3 Answers
Writing unity ios plugin in Swift 1 Answer