<!DOCTYPE html>
<!--
Copyright (c) 2012-2016 Adobe Systems Incorporated. All rights reserved.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
<!-- This is a wide open CSP declaration. To lock this down for production, see below. -->
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *" />
<!-- Good default declaration:
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
* Enable eval(): add 'unsafe-eval' to default-src
* Create your own at http://cspisawesome.com
-->
<!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: 'unsafe-inline' https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *" /> -->
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>PhoneGap</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="js/PushNotification.js"></script>
<script type="text/javascript">
// 디바이스에서 deviceready event 를 캐치하여 알림서비스권한을 등록한다.
document.addEventListener("deviceready", function(){
window.plugins.pushNotification.register(tokenHandler, errorHandler, {
"badge":"true", // 뱃지기능사용
"sound":"true", // 사운드기능사용
"alert":"true", // alert기능사용
"ecb": "onNotificationAPN"
// 알림이 오면 onNotificationAPN 함수를 실행할 수 있도록 ecb에 등록한다.
});
});
// Push 서비스가 활성화 되었을때 디바이스 토큰을 수신해 출력해준다.
// 서버와 Push서비스를 연동할시에 tokenHandler() 안에서 서버로 토큰을 전송해준다.
function tokenHandler(result){
console.log('deviceToken:' + result);
}
// 에러처리 핸들러
function errorHandler(err){
console.log('error:' + err);
}
// 알림처리 완료 후에 실행될 콜백 핸들러
function successHandler(result){
console.log('result:'+result);
}
// IOS 버전 Push 수신 함수
function onNotificationAPN(push_noti){
// 알림메세지에 title,body가 없을때
// if (push_noti.alert){
// navigator.notification.alert(push_noti.alert);
// }
// 알림메세지에 title,body가 있을때
if (push_noti.body){
navigator.notification.alert(
push_noti.body, // message
complete, // callback
push_noti.title, // title
'확인' // buttonName
);
}
// alert 확인버튼 클릭후 콜백 함수 (선언은 필수, 필요하지않은경우 빈값으로)
function complete() {
// do something
}
// 알림메세지에 sound 값이 있을 경우
if (push_noti.sound){
var snd = new Media(push_noti.sound);
snd.play();
}
// 알림메세지에 badge 값이 있을 경우
if (push_noti.badge){
window.plugins.pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, push_noti.badge);
}
}
</script>
</body>
</html>