PushNotifications API 기능은 애플의 푸시 알람 서비스(APNS)을 이용하여 모바일 앱 사용자에게 다양한 푸시 메세지를 전달할 수 있는 기능을 제공함
본 가이드 프로그램 에서는 Push알림 기능의 활용을 가이드 할 수 있도록 기기등록, 기기목록보기,
송신내역보기 를 제공하고 있다.
| 구분 | 내용 |
|---|---|
| Local 디바이스 개발 환경 | Xcode 8.0 (8A218a), Cordova 6.4.0 |
| 서버 사이드 개발 환경 | 전자정부표준프레임워크 개발환경3.6 |
| Mash up Open API 연계 | N/A |
| 테스트 디바이스 | iPhone 6 , iPad Air |
| 테스트 플랫폼 | iOS 9.3, iOS 10.0 |
| 추가 라이브러리 적용 | N/A |
| 구분 | 내용 |
|---|---|
| 지원 디바이스 및 플랫폼 | N/A |
| 크로스 도메인 사용 | 폰갭에서 특정 외부 도메인이나 외부 도메인의 하위 도메인을 사용해야할 경우,[Project_Name]/Supproting Files/config.xml에서 <access origin=“ExternalHosts”/> 항목에 외부 도메인 주소를 추가 설정해야 외부 도메인에 접속할 수 있다. |
| 라이선스 | N/A |
PushNotifications API 가이드 프로그램은 크게 기기등록, 기기목록보기, 송신내역보기
기능으로 구성되어 있다.(관련기능 부분참조)
| 유형 | 대상소스명 | 비고 |
|---|---|---|
| CSS | assets/www/css/egovframwork/mbl/hyb/PushNotificationsAPI.css | PushNotificationsAPI 가이드 프로그램 주요 Cascading Style Sheets |
| IMAGE | assets/www/images/egovframwork/mbl/hyb/ | PushNotificationsAPI 가이드 프로그램 주요 Image 폴더 |
| JS | assets/www/js/egovframwork/mbl/hyb/PushNotificationsAPI.js | PushNotificationsAPI 가이드 프로그램 주요 JavaScript |
| HTML | assets/www/PushNotifications.html | PushNotificationsAPI 메인 페이지 |
| HTML | assets/www/intro.html | PushNotificationsAPI Intro 페이지 |
| HTML | assets/www/license.html | PushNotificationsAPI 라이센스 페이지 |
| HTML | assets/www/overview.html | PushNotificationsAPI 기능설명 페이지 |
| RES | [Project_Name]/Resources/ | PushNotificationsAPI 가이드 프로그램 주요 Resource 폴더 |
| PLIST | [Project_Name]/Resources/[Project_Name]-Info.plist | iOS 어플리케이션 설정 파일 |
var uuid;
var osVer;
var token_id;
var osType;
| 변수 | 설명 | 비고 |
|---|---|---|
| uuid | 디바이스 고유의 UUID를 반환한다. | |
| version | 디바이스의 플랫폼 버전을 반환한다. | |
| token_id | 앱에 고유의 token_id를 반환한다. | |
| osType | 디바이스 OS타입을 반환한다. |
window.addEventListener("batterycritical", yourCallbackFunction, false);
window.addEventListener("batterylow", yourCallbackFunction, false);
window.addEventListener("batterystatus", yourCallbackFunction, false);
| 유형 | 대상소스명 | 비고 |
|---|---|---|
| Controller | egovframework.hyb.add.dvc.web.EgovPushDeviceAPIController.java | PushnotificationsAPI 가이드 프로그램 Controller Class |
| Service | egovframework.hyb.add.dvc.service.EgovPushDeviceAPIService.java | PushnotificationsAPI 가이드 프로그램 Service Class |
| ServiceImpl | egovframework.hyb.add.dvc.service.impl.EgovPushDeviceAPIServiceImpl.java | PushnotificationsAPI 가이드 프로그램 ServiceImpl Class |
| VO | egovframework.hyb.add.dvc.service.PushDeviceAPIVO.java | PushnotificationsAPI 가이드 프로그램 VO Class |
| DAO | egovframework.hyb.add.dvc.service.impl.PushDeviceAPIDAO.java | PushnotificationsAPI 가이드 프로그램 Dao Class |
| QUERY XML | resources/egovframework/sqlmap/hyb/mbl/pus/EgovPushDeviceAPIGuide_SQL_xxx.xml | PushnotificationsAPI 가이드 프로그램 QUERY XML |
| 테이블명 | 테이블명(영문) | 비고 |
|---|---|---|
| Push디바이스 | push_device | Push디바이스 정보 관리 |
| Push메세지 | push_message | Push 메세지 정보 관리 |
* push_device
| No | 컬럼ID | 컬럼명 | 타입 | 길이 | NULL |
|---|---|---|---|---|---|
| 1 | SN | 일련번호 | NUMERIC | 6 | NotNull |
| 2 | UUID | UUID | VARCHAR | 50 | NotNull |
| 3 | OS_VER | 디바이스 버전 | VARCHAR | 2000 | Null |
| 4 | DEVICE_NM | 디바이스 코도바 버전 | VARCHAR | 20 | Null |
| 5 | TOKEN_ID | 앱 고유 번호 | VARCHAR | 250 | NotNull |
| 6 | osType | 디바이스 OS타입 | VARCHAR | 20 | Null |
| 7 | USEYN | 활성화여부 | CHAR | 1 | Null |
* push_message
| No | 컬럼ID | 컬럼명 | 타입 | 길이 | NULL |
|---|---|---|---|---|---|
| 1 | SN | 일련번호 | NUMERIC | 6 | NotNull |
| 2 | UUID | UUID | VARCHAR | 50 | NotNull |
| 3 | MESSAGE | 메세지 | VARCHAR | 2000 | Null |
| 4 | SND_DT | 메세지 발송 시간 | VARCHAR | 20 | Null |
| 5 | TOKEN_ID | 앱 고유 번호 | VARCHAR | 250 | NotNull |
| 6 | osType | 디바이스 OS타입 | VARCHAR | 20 | Null |
| 7 | PG_VER | 폰갭버전 | VARCHAR | 40 | Null |
| 8 | DEVICE_NM | 디바이스명 | VARCHAR | 200 | Null |
| 9 | USEYN | 활성화여부 | CHAR | 1 | Null |
PushNotifications API 가이드 프로그램에서 제공하는 모바일 디바이스의 메타 정보 조회 기능을 활용하기 위하여 필요한 항목 및 그 환경 설정은 다음과 같다.
<feature name="Battery"> <param name="ios-package" value="CDVBattery"/> </feature> <feature name="InterfaceAPI"> <param name="ios-package" value="EgovInterface"/> </feature> <feature name="Notification"> <param name="ios-package" value="CDVNotification"/> </feature>
<access origin="ExternalHosts"/>
#define kSERVER_URL @"Server_URL"
<sqlMap resource="egovframework/sqlmap/hyb/add/dvc/EgovDeviceAndroidAPIGuide_SQL_[DB명].xml"/>
* src/main/java/egovframework/com/push/GCMPush.java
public class GCMPush { public static void main(String[] args) { // TODO Auto-generated method stub Sender sender = new Sender("발급 API Key 입력"); // 서버 API Key 입력 String regId = "단말기 RegID 입력"; // 단말기 RegID 입력 Message message = new Message.Builder().addData("msg", "push notify!!! syh").build(); List<String> list = new ArrayList<String>(); list.add(regId); MulticastResult multiResult; try { multiResult = sender.send(message, list, 5); if (multiResult != null) { List<Result> resultList = multiResult.getResults(); for (Result result : resultList) { System.out.println(result.getMessageId()); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
PushnotificationsAPI 가이드 프로그램은 크게 디바이스 내 메타 정보 조회 기능과 조회된 메타 정보를 서버에 전송하고 조회할수 있는 기능으로 구성되어 있다.
/** 디바이스 정보 VO */
sn : "",
uuid : "",
deviceNm : "",
osVer : "",
useYn : "",
osType : "",
tokenId : "",
message : "",
sndDt : ""
function fn_egov_deviceInfo(){
$('.PushInfo:eq(0)').html(device.platform + " " + device.version);
$('.PushInfo:eq(1)').html(device.uuid);
$('.PushInfo:eq(2)').html(token_id);
$.mobile.changePage("#deviceInfo", "slide", false, false);
detailScroll.refresh();
}
function fn_egov_save_push_deviceInfo() {
useYn = "Y";
var url = "/pus/addPushDeviceInfo.do";
var accept_type = "json";
var params = {
uuid : device.uuid ,
osVer : String(device.version) ,
osType : device.platform ,
ntwrkDeviceInfo : deviceInfoVO.ntwrkDeviceInfo ,
deviceNm : device.cordova ,
useYn : "Y" ,
tokenId : token_id};
window.plugins.EgovInterface.request(url, params, function(jsondata) {
//var data = JSON.parse(jsondata);
//alert("jsondata : "+jsondata);
if(jsondata.resultState == "OK"){
//fn_goDeviceInfoListXml();
$.mobile.changePage("#main", "slide", false, false);
}else{
$("#alert_dialog").click( function() {
jAlert('데이터 전송 중 오류가 발생 했습니다.', '전송 오류', 'c');
});
}
}, function(result){
console.log("error > "+result);
});
console.log("DeviceAPIGuide fn_egov_regist_deviceInfo request Completed");
}
| Action | URL | Controller method | QueryID |
|---|---|---|---|
| 디바이스 정보 등록 | /pus/addPushDeviceInfo.do | insertDeviceInfo | “pushDeviceAPIDAO.insertPushDevice” |
기기 등록: 디바이스 정보를 서버로 업로드 한다. 메인화면 이동 : 첫 화면으로 이동한다.
function fn_egov_push_deviceInfoList() {
var url = "/pus/pushDeviceInfoList.do";
var accept_type = "json";
var params = {uuid : device.uuid};
// get the data from server
window.plugins.EgovInterface.request(url, params, function(jsonData) {
var list_html = "";
console.log(">>> resultData = "+jsonData);
$(jsonData["pushDeviceInfoList"]).each(function(idx,obj){
/* console.log("\n\n\n\n\n#>>>>>obj = "+idx + "/" + obj);
console.log("#>>>>>obj = "+obj.uuid+"\n\n\n\n");*/
var sn = obj.sn;
var uuid = obj.uuid;
var osType = obj.osType;
var tokenId = obj.tokenId;
list_html += "<li><a href='javascript:fn_egov_request_push_deviceInfoDetail(" + sn + ")'><h3>UUID : " +uuid + "</h3>";
list_html += "<p><strong>Token ID" + tokenId + "</strong></p>";
list_html += "<p>OS : " + osType + "</p></a></li>";
});
console.log("DeviceAPIGuide fn_egov_move_deviceInfoList request Completed");
var theList = $('#theList');
theList.html(list_html);
$.mobile.changePage("#deviceInfoList", "slide", false, false);
theList.listview("refresh");
listScroll.refresh();
});
}
function fn_egov_send_devicePushInfo() {
var url = "/pus/requestPushInfo.do";
var p_message = $("#message").val();
var p_osType = $(".pusdeviceInfoVO:eq(0)").text();
var p_uuid = $(".pusdeviceInfoVO:eq(1)").text();
var p_tokenid = $(".pusdeviceInfoVO:eq(2)").text();
nowdate = new Date();
date_str = nowdate.getFullYear() + "-" + (nowdate.getMonth()+1) + "-" + nowdate.getDate();
var params = {
uuid : p_uuid ,
message : p_message,
osType : p_osType,
sndDt : date_str ,
tokenId : p_tokenid};
window.plugins.EgovInterface.request(url, params, function(jsondata) {
//var data = JSON.parse(jsondata);
//alert("jsondata : "+jsondata);
console.log("jsondata > "+jsondata);
if(jsondata.resultState == "OK"){
//fn_goDeviceInfoListXml();
//alert("OK!");
console.log("send push ok");
}else{
$("#alert_dialog").click( function() {
jAlert('데이터 전송 중 오류가 발생 했습니다.', '전송 오류', 'c');
});
}
}, function(result){
console.log("error > "+result);
});
console.log("DeviceAPIGuide fn_egov_regist_deviceInfo request Completed");
$("#message").val("내용을 입력하세요.");
$.mobile.changePage("#main", "slide", false, false);
detailScroll.refresh();
}
// 서버에서 반환한 디바이스 정보 및 메세지 리스트를 화면에 출력한다.
function fn_egov_push_selectPushMessageList() {
var url = "/pus/PushMessageList.do";
var accept_type = "json";
var params = {uuid : device.uuid};
// get the data from server
window.plugins.EgovInterface.request(url, params, function(jsonData) {
var list_html = "";
//console.log(">>> resultData = "+jsonData);
$(jsonData["PushMessageList"]).each(function(idx,obj){
//console.log("\n\n\n\n\n#>>>>>obj = "+idx + "/" + obj);
var sn = obj.sn;
var uuid = obj.uuid;
var message = obj.message;
var tokenId = obj.tokenId;
var sndDt = obj.sndDt;
list_html += "<li><h3>UUID : " +uuid + "</h3>";
list_html += "<p><strong>Token ID : " + tokenId + "</strong></p>";
list_html += "<p><strong>송신 날짜 : " + sndDt + "</strong></p>";
list_html += "<p>message : " + message + "</p></li>";
});
console.log("DeviceAPIGuide fn_egov_push_selectPushMessageList request Completed");
var theList = $('#MessageList');
theList.html(list_html);
$.mobile.changePage("#PushMessageList", "slide", false, false);
theList.listview("refresh");
detailScroll.refresh();
});
}
| Action | URL | Controller method | QueryID |
|---|---|---|---|
| 디바이스 정보 목록 조회 | /pus/pushDeviceInfoList.do | selectVibratorInfoList | “pushDeviceAPIDAO.selectPushDeviceList” |
| 디바이스 정보 상세 조회 | /dvc/deviceInfo.do | selectDeviceInfo | “deviceaddAPIDAO.selectDeviceInfo” |
| 메세지 발송 | /pus/requestPushInfo.do | insertVibratorInfo | “pushDeviceAPIDAO.insertVibratorInfo” |
| 메세지 정보 목록 조회 | /pus/PushMessageList.do | selectPushMessageList | “pushDeviceAPIDAO.selectPushMessageList” |
| Pushnotifications 메세지 발송 화면 | Pushnotifications 메세지 송신 목록 화면 |
|---|---|
![]() | ![]() |
전송 : 메세지 전송
목록 : 디바이스 정보 목록 페이지를 호출한다.
메인화면이동 : 메인 페이지를 호출한다.
디바이스 어플리케이션에서 발생한 오류 내용 확인 및 디버깅을 위해서는 폰갭 프레임워크에서 제공하는 console.log를 이용할 수 있다. console.log 함수는 자바스크립트 구문에서 사용할 수 있는 디버그 코드로 이클립스 및 Xcode에서 확인 할 수 있다.
function fn_egov_network_check(doCheck)
{
console.log('DeviceAPIGuide fn_egov_network_check');
var networkState = navigator.network.connection.type;
...
}
PushnotificationsAPI 디바이스 API 가이드 다운로드 : Click