注意
Web画面上からタイムアウトをイベントとして受信する方法は、AndroidとiOSに対応しています。以下サーバアプリケーションのコンテンツの配置例です。
Timeout
+-- timeout.jsp
+-- js
+-- android
+-- cordova.js
+-- ios
+-- cordova.js
cordova.jsは以下に保管されているものをコピーしてサーバアプリケーションに含めます。
また、cordova.jsの配置先には認証が有効にならないようにimadmin auth importコマンドで設定します。
<製品インストールフォルダー>\development\android\cordovajs\cordova.js
/opt/FJSVimsrv/development/android/cordovajs/cordova.js
<製品インストールフォルダー>\development\ios\cordovajs\cordova.js
/opt/FJSVimsrv/development/ios/cordovajs/cordova.js
上記ディレクトリからcordova.jsをコピーします。
<%@ page contentType="text/html;charset=UTF-8" isErrorPage="true" %>
<%
response.setHeader("X-IMAPS-TIMEOUT", "true");
response.setStatus(200);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>401 Unauthorized</title>
<script type="text/javascript">
var require;
if(/Android/i.test(navigator.userAgent)){
require = "<%=request.getContextPath()%>\/timeout\/js\/android\/cordova.js";
} else {
require = "<%=request.getContextPath()%>\/timeout\/js\/ios\/cordova.js";
}
document.write('<scr'+'ipt type="text/javascript" src="'+require+'" onload="onLoad()"><\/scr'+'ipt>');
function onLoad() {
document.addEventListener("deviceready",
function () {
cordova.exec(false, false, "AuthPlugin", "unauthorized", []);
}, false);
}
</script>
</head>
<body>
<b>401 Unauthorized</b><br>
</body>
</html>
public class WebViewActivity extends CordovaActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Config.init(this);
init();
super.loadUrl(Config.getStartUrl());
}
@Override
public Object onMessage(String id, Object data) {
if(id.equals("IMAPS_EVENT_AUTH_TIMEOUT_ERROR")) {
new AlertDialog.Builder(this)
.setTitle("Timeout")
.setMessage("タイムアウトが発生しました")
.setPositiveButton("OK", null)
.create()
.show();
}
return super.onMessage(id, data);
}
}
#pragma mark IMAAuthViewControllerDelegate implementation
- (void) didFailLoadWithError:(NSError *)anError
{
NSString *message = [self getErrorMsg:anError];
NSLog(@"didFailLoadWithError %@", message);
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Timeout"
message:@"タイムアウトが発生しました"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}