2017-11-28 5 views
0

현지 알림을 예약하기 위해 cordova-plugin-local-notifications를 사용하고 있습니다. 응용 프로그램이 로컬 알림에서 열리면 내 홈 페이지에서보기를 확장해야하지만 내 페이지로 데이터를 보내는 데 문제가 있습니다. 응용 프로그램은 지역 알림에서 열렸다 경우Ionic 3의 특정 페이지에 로컬 알림 데이터 보내기

,이 코드는 index.html을에서 실행 :

<script type="text/javascript"> 
    document.addEventListener('deviceready', function() { 
     cordova.plugins.notification.local.on('click', function (notification) { 
     console.log("notification ", notification); 
     let data = JSON.parse(notification.data); 
     //TODO: send data to the desired page (HomePage) 
     }); 
    }, false); 
</script> 

나는 내 탐색을 설정하고 app.component.ts에이 코드 조각을 넣어 시도 스택 및 초기 작업 페이지,하지만 계속 Cannot find name cordova 점점. declare var cordova:any을 거기에 추가하면 런타임 오류 Uncaught ReferenceError: cordova is not defined가 발생합니다. 그래서이 코드를 index.html에 넣기로 결정했는데 여기에서 데이터를 내 페이지로 보내는 방법을 모르겠습니다. 누구나 해결책이 있습니까?

답변

2

당신은 platform.ready() 블록 내부에 app.component 내부 파일을 코드를 넣을 수 있습니다.

platform.ready().then(() => { 
    this.localNotification.on('click', function (notification) { 
     console.log("notification ", notification); 
     let data = JSON.parse(notification.data); 
     //Open page you want (Send data with push or root method) 
     }); 
}; 
+0

예, 감사합니다. – Margaret