2014-12-29 4 views
1

이것은 내 코드입니다. UniWebView를 사용하여 UIView에서 웹 페이지를 열려고합니다. 웹 페이지가 열리지 만 단 한 번입니다. 다시 열 수 없습니다. 페이지를 여는 데 버튼을 사용하고 있습니다. 버튼에는이 스크립트와 UniWebView가 첨부되어 있습니다.웹 페이지는 UniWebView를 사용하여 한 번만 액세스 할 수 있습니다.

using UnityEngine; 
using System.Collections; 
using System.Net; 
using System.IO; 
public class InternetCheck : MonoBehaviour 
{ 
    UniWebView _webView; 

void Awake() 
{ 
    _webView = GetComponent<UniWebView>(); 
} 

void Start() 
{ 

    _webView.OnLoadComplete += OnLoadComplete; 
    _webView.OnWebViewShouldClose += OnWebViewShouldClose; 
} 

void OnLoadComplete(UniWebView webView, bool success,string errorMessage) 
{ 
    if(success) 
    { 
     webView.Show(); 
    } 
    else 
    { 
     Debug.LogError("Unable to load"); 
    } 
    webView.ShowToolBar (true); 
} 


void BtnClicked() 
{ 
    if (_webView == null) 
    { 
     _webView = GetComponent<UniWebView>();  
    } 

    if(isInternetAvailable()) 
    { 

     _webView.insets = new UniWebViewEdgeInsets(0,0,0,0); 
     _webView.url = "http://google.com"; 
     _webView.Load(); 
    } 
    else 
     if(!isInternetAvailable()) 
    { 
     _webView.insets = new UniWebViewEdgeInsets(0,0,0,0); 
     _webView.url = Application.streamingAssetsPath + "/Privacy Policy _ Terms of Use _ Cartoon Network.html"; 
     _webView.Load(); 
    } 
} 



bool OnWebViewShouldClose(UniWebView webView) { 
    if (webView == _webView) { 
     _webView = null; 

     return true; 
    } 
    return false; 
} 

public static bool isInternetAvailable() 
{ 
    string HtmlText = GetHtmlFromUri("http://google.com"); 
    if(HtmlText == "") 
    { 
     //MNAndroidMessage.Create(Const.NO_NETWORK_ALERT_TITLE, Const.NO_NETWORK_ALERT_MESSAGE); 
     //   Debug.Log (" Please check your internet conection "); 
     return false; 
    } 
    else if(!HtmlText.Contains("schema.org/WebPage")) 
    { 
     //MNAndroidMessage.Create(Const.NETWORK_LOGIN_ALERT_TITLE, Const.NETWORK_LOGIN_ALERT_MESSAGE); 
     //   Debug.Log (" Please check your internet conection might be you need to password to connect"); 
     return false; 
    } 
    else 
    { 
     //   Debug.Log("Network available "); 
     return true; 
    } 
} 

public static string GetHtmlFromUri(string resource) 
{ 
    string html = string.Empty; 
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(resource); 
    try 
    { 
     using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse()) 
     { 
      bool isSuccess = (int)resp.StatusCode < 299 && (int)resp.StatusCode >= 200; 
      if (isSuccess) 
      { 
       using (StreamReader reader = new StreamReader(resp.GetResponseStream())) 
       { 
        //We are limiting the array to 80 so we don't have 
        //to parse the entire html document feel free to 
        //adjust (probably stay under 300) 
        char[] cs = new char[80]; 
        reader.Read(cs, 0, cs.Length); 
        foreach(char ch in cs) 
        { 
         html +=ch; 
        } 
       } 
      } 
     } 
    } 
    catch 
    { 
     return ""; 
    } 
    return html; 
} 
} 
+1

사이드 노트 : "UniWebView"클래스에 대한 링크가 있고 "유니티"(DI 프레임 워크)가 올바른 태그 (어쩌면 "unity3d")인지 다시 확인하는 것이 좋습니다. –

+0

그래, 바뀔거야. 그. 나는 그것을 알아 냈다. 단추를 클릭 할 때 UniWebView 구성 요소를 다시 할당하면됩니다. – generic2709

답변

1

문제점을 파악했습니다. 제거 될 때 UniWebView 구성 요소를 다시 추가하기 만하면됩니다.

관련 문제