Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by moghes · May 21, 2018 at 08:00 AM · iospluginobjective-cwebpage

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!!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image moghes · May 21, 2018 at 08:07 AM 0
Share

Note that I am testing on real device (iphone 6) and not a simulator

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

117 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

How to pass a Swift string into Unity iOS game? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges