목차

PushNotifications 디바이스API 가이드 프로그램

개요

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 가이드 프로그램은 크게 기기등록, 기기목록보기, 송신내역보기
기능으로 구성되어 있다.(관련기능 부분참조)

Device Application

관련 소스

유형대상소스명비고
CSSassets/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
HTMLassets/www/PushNotifications.htmlPushNotificationsAPI 메인 페이지
HTMLassets/www/intro.htmlPushNotificationsAPI Intro 페이지
HTMLassets/www/license.htmlPushNotificationsAPI 라이센스 페이지
HTMLassets/www/overview.htmlPushNotificationsAPI 기능설명 페이지
RES [Project_Name]/Resources/ PushNotificationsAPI 가이드 프로그램 주요 Resource 폴더
PLIST[Project_Name]/Resources/[Project_Name]-Info.plistiOS 어플리케이션 설정 파일

활용 API

device
	var uuid;
        var osVer;
        var token_id;
        var osType;      

변수설명비고
uuid디바이스 고유의 UUID를 반환한다.
version디바이스의 플랫폼 버전을 반환한다.
token_id 앱에 고유의 token_id를 반환한다.
osType디바이스 OS타입을 반환한다.
Event[batterycritical]
window.addEventListener("batterycritical", yourCallbackFunction, false);
Event[batterylow]
window.addEventListener("batterylow", yourCallbackFunction, false);
Event[batterystatus]
window.addEventListener("batterystatus", yourCallbackFunction, false);

Server Application

관련 소스

유형대상소스명비고
Controlleregovframework.hyb.add.dvc.web.EgovPushDeviceAPIController.javaPushnotificationsAPI 가이드 프로그램 Controller Class
Serviceegovframework.hyb.add.dvc.service.EgovPushDeviceAPIService.javaPushnotificationsAPI 가이드 프로그램 Service Class
ServiceImplegovframework.hyb.add.dvc.service.impl.EgovPushDeviceAPIServiceImpl.javaPushnotificationsAPI 가이드 프로그램 ServiceImpl Class
VOegovframework.hyb.add.dvc.service.PushDeviceAPIVO.javaPushnotificationsAPI 가이드 프로그램 VO Class
DAOegovframework.hyb.add.dvc.service.impl.PushDeviceAPIDAO.javaPushnotificationsAPI 가이드 프로그램 Dao Class
QUERY XMLresources/egovframework/sqlmap/hyb/mbl/pus/EgovPushDeviceAPIGuide_SQL_xxx.xmlPushnotificationsAPI 가이드 프로그램 QUERY XML

관련 테이블

테이블명테이블명(영문)비고
Push디바이스push_devicePush디바이스 정보 관리
Push메세지push_messagePush 메세지 정보 관리

테이블 정의서

* push_device

No컬럼ID컬럼명타입길이NULL
1SN일련번호NUMERIC6NotNull
2UUIDUUIDVARCHAR50NotNull
3OS_VER디바이스 버전VARCHAR2000Null
4DEVICE_NM디바이스 코도바 버전VARCHAR20Null
5TOKEN_ID앱 고유 번호VARCHAR250NotNull
6osType디바이스 OS타입VARCHAR20Null
7USEYN활성화여부CHAR1Null

* push_message

No컬럼ID컬럼명타입길이NULL
1SN일련번호NUMERIC6NotNull
2UUIDUUIDVARCHAR50NotNull
3MESSAGE메세지VARCHAR2000Null
4SND_DT메세지 발송 시간VARCHAR20Null
5TOKEN_ID앱 고유 번호VARCHAR250NotNull
6osType디바이스 OS타입VARCHAR20Null
7PG_VER폰갭버전VARCHAR40Null
8DEVICE_NM디바이스명VARCHAR200Null
9USEYN활성화여부CHAR1Null

ERD

환경설정

PushNotifications API 가이드 프로그램에서 제공하는 모바일 디바이스의 메타 정보 조회 기능을 활용하기 위하여 필요한 항목 및 그 환경 설정은 다음과 같다.

Device Application

Plugin
    <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>
ExternalHosts
    <access origin="ExternalHosts"/>
[Project_Name]/eGovModule/EGovComModule.h
#define kSERVER_URL     @"Server_URL"

Server Application

resource/egovframework/sqlmap/sql-map-config_[DB명].xml

<sqlMap resource="egovframework/sqlmap/hyb/add/dvc/EgovDeviceAndroidAPIGuide_SQL_[DB명].xml"/>

GCM Push 발급 Key 입력

* 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
/** 디바이스 정보  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();
    
    
}

관련 화면 및 수행매뉴얼

디바이스 정보조회 화면

OS: 플랫폼 정보 및 버전
UUID : 디바이스의 고유 아이디
Token ID : 디바이스 앱의 고유 아이디

디바이스 정보 서버에 전송하기

관련 코드

디바이스 정보 등록
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");
    
    
}

관련 화면 및 수행매뉴얼

ActionURLController methodQueryID
디바이스 정보 등록/pus/addPushDeviceInfo.doinsertDeviceInfo“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();
	        
	        
	    });    
	}	

관련 화면 및 수행매뉴얼

관련 화면 및 수행매뉴얼

ActionURLController methodQueryID
디바이스 정보 목록 조회/pus/pushDeviceInfoList.doselectVibratorInfoList“pushDeviceAPIDAO.selectPushDeviceList”
디바이스 정보 상세 조회/dvc/deviceInfo.doselectDeviceInfo“deviceaddAPIDAO.selectDeviceInfo”
메세지 발송/pus/requestPushInfo.doinsertVibratorInfo“pushDeviceAPIDAO.insertVibratorInfo”
메세지 정보 목록 조회/pus/PushMessageList.doselectPushMessageList“pushDeviceAPIDAO.selectPushMessageList”
Pushnotifications 메세지 발송 화면Pushnotifications 메세지 송신 목록 화면

전송 : 메세지 전송
목록 : 디바이스 정보 목록 페이지를 호출한다.
메인화면이동 : 메인 페이지를 호출한다.

컴파일 디버깅 배포

컴파일

Device Applicaton 컴파일 방법

Server Applicaton 컴파일 방법

디버깅

디바이스 어플리케이션에서 발생한 오류 내용 확인 및 디버깅을 위해서는 폰갭 프레임워크에서 제공하는 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

참고자료