0

현재 BlackBerry WebWorks SDK를 사용하여 phonegap 응용 프로그램을 개발 중이며 현재 WebView와 해당 URL에 액세스하거나 제어 할 수 없습니다.BlackBerry 10 WebWorks BlackBerry 10 PhoneGap WebView URL

기본적으로 원하지 않는 Index.html 페이지가로드 중입니다. 나는 일단 외부 URL을 서버에로드하려고합니다. 그러면 일단 인증되면 www 폴더의 index.html이로드됩니다. 이것은 작동하지 않습니다. 어떤 아이디어 WebView URL을 제어하는 ​​방법?

감사합니다, ANKIT 타나

답변

0

난 그냥 WebWorks 2.1/코르도바와 응용 프로그램을 개발하고 같은 문제가 발생했습니다.

우선, 크로스 플랫폼으로가는 것이 목표 였기 때문에 InAppBrowser 플러그인을 사용하고 있습니다. (솔직히 말해서 수동으로 포함해야하는지는 확실하지 않습니다.)

BlackBerry 10 WebView는 loadstart 및 exit 이벤트를 지원하지 않는 것 같으므로 타이머를 사용하여 수동으로 WebView의 상태를 확인해야합니다. 이런 식으로 뭔가 :

var VIEWER = window.open('http://myauthenticationpage/login.html', '_blank', 'location=no,menubar=no,titlebar=no,toolbar=no,status=no'); 

//Start a timer to check for a URL change in the WebView 
var AuthTimer = setInterval(function() { 

    //Handle your failure case your own way, but stopping this loop is a good idea if the WebView isn't open 
    if ((typeof VIEWER === 'undefined') || (typeof VIEWER.document === 'undefined')) { 
     clearInterval(AuthTimer); 
     return; 
    } 

    //Get the current URL of the WebView 
    var url = VIEWER.document.URL; 

    //Process the URL in some way, like to extract a token 
    //You can also access the DOM of the loaded page, as another option 
    if (url.indexOf('authorizedUser=') > 0) { 
     //Extract the username, which my server appends in the query string 
     var user = url.substring(url.indexOf('authorizedUser=') + 15); 

     //I store the user token in localStorage 
     localStorage.setItem('user', user); 

     //Close the viewer and stope this timer 
     clearInterval(AuthTimer); 
     VIEWER.close(); 
    } 
}, 20); 

이 일을하면 ... 토큰 또는 다른 정보 사용자를 얻기 위해 서버에 Ajax 호출을 할 구현에 달려있을 수 있습니다.

앱이 시작될 때 첫 페이지에 즉석에서 '저장된 사용자 토큰이 있습니까?'라는 확인을해야합니다. 그렇지 않은 경우 위의 프로세스를 시작하십시오. 저장된 사용자 토큰이있을 때까지 계속 킥오프하십시오. 토큰이 있으면 서버에서 사용자 데이터를로드하거나 www/등에서 index.html을로드하십시오.

이것은 잘 작동하며 장치가이를 잘 처리합니다.

안드로이드/아이폰 OS가

당신이 안드로이드 또는 iOS에 그것을 크로스 플랫폼을하기로 결정하면, 당신은 대신 사용하여 이벤트를 할 수있는 참고 :

var VIEWER = window.open('http://myauthenticationpage/login.html', '_blank', 'location=no,menubar=no,titlebar=no,toolbar=no,status=no'); 

VIEWER.addEventListener('exit', function(e) { 
    //The webview closed! 
    if (user == null) { 
     //We still don't have a username 
     setTimeout(function() { 
      //Kick open the webview again, to try again for a username for example 
      //(Might want to wrap all this in a function) 
      VIEWER = window.open('http://myauthenticationpage/login.html', '_blank', 'location=no,menubar=no,titlebar=no,toolbar=no,status=no'); 
     }, 50); 
    } 
}); 

VIEWER.addEventListener('loadstart', function(e) { 
    //The webview has started loading a new page 
    var url = e.url; 
    var user = null; 

    if (url.indexOf('authorizedUser=') > 0) { 
     user = url.substring(url.indexOf('authorizedUser=') + 15); 

     localStorage.setItem('user', user); 

     VIEWER.close(); 
    } 
}); 

이 기술을 사용하여 웹 페이지를 성공적인 로그인이 발생하면 검색어 문자열이나 응답 DOM에 일부 데이터를 '반향'해야합니다. 대부분의 인증 구현에 대해 생각해 보면 요청에 더미 콜백 URL을 설정 한 다음 WebView URL의 콜백 URL을 확인하면됩니다.

이 정보가 도움이되기를 바랍니다.