2016-10-06 3 views
2

내 앱에서 푸시 알림을 구현할 수 있도록 cordovaPushV5 플러그인을 사용하고 있습니다.

나는이 튜토리얼에서 정확히 뭐하는 거지 : 내 브라우저에서 응용 프로그램을 실행하면 https://github.com/yafraorg/yafra/wiki/Blog-Ionic-PushV5

, 나는 콘솔에서 위의 오류가 발생합니다.

아래 그림과 같이 플러그인을 올바르게 설치하고 필요한 코드 줄을 내 App.js 파일에 포함 시켰습니다.

누군가 내가 잘못 가고 있는지 알 수 있습니까?

/****ENABLE RECEIVING OF PUSH NOTIFICATIONS****/ 
 
/* 
 
* start within Platform ready 
 
*/ 
 
$ionicPlatform.ready(function() { 
 
    // register push notification and get local push token 
 
    localStorage.myPush = ''; // I use a localStorage variable to persist the token 
 
    $cordovaPushV5.initialize( // important to initialize with the multidevice structure !! 
 
     { 
 
      android: { 
 
       senderID: "704649974960" 
 
      }, 
 
      ios: { 
 
       alert: 'true', 
 
       badge: true, 
 
       sound: 'false', 
 
       clearBadge: true 
 
      }, 
 
      windows: {} 
 
     } 
 
    ).then(function (result) { 
 
     $cordovaPushV5.onNotification(); 
 
     $cordovaPushV5.onError(); 
 
     $cordovaPushV5.register().then(function (resultreg) { 
 
      localStorage.myPush = resultreg; 
 
      // SEND THE TOKEN TO THE SERVER, best associated with your device id and user 
 
     }, function (err) { 
 
      // handle error 
 
     }); 
 
    }); 
 
}); 
 

 
/* 
 
* Push notification events 
 
*/ 
 
$rootScope.$on('$cordovaPushV5:notificationReceived', function(event, data) { // use two variables here, event and data !!! 
 
    if (data.additionalData.foreground === false) { 
 
     // do something if the app is in foreground while receiving to push - handle in app push handling 
 
     
 
    } else { 
 
     // handle push messages while app is in background or not started 
 
    } 
 
    if (Device.isOniOS()) { 
 
     if (data.additionalData.badge) { 
 
      $cordovaPushV5.setBadgeNumber(NewNumber).then(function (result) { 
 
       // OK 
 
      }, function (err) { 
 
       // handle error 
 
      }); 
 
     } 
 
    } 
 

 
    $cordovaPushV5.finish().then(function (result) { 
 
     // OK finished - works only with the dev-next version of pushV5.js in ngCordova as of February 8, 2016 
 
    }, function (err) { 
 
     // handle error 
 
    }); 
 
}); 
 

 
$rootScope.$on('$cordovaPushV5:errorOccurred', function(event, error) { 
 
    // handle error 
 
}); 
 
/****END ENABLE RECEIVING OF PUSH NOTIFICATIONS****/
같은 배에서

+0

'$ cordovaPushV5'를 컨트롤러에 삽입 했습니까? ngCordova.plugins.push_v5 모듈을 앱에 종속성으로 추가 했습니까? –

+0

@RaviTeja 나는 주입 그 방과 코드는 내부에 : '.RUN (기능 ($ rootScope, $ cordovaPushV5, $ ionicPlatform, $ 상태, AuthService, AUTH_EVENTS) { // 코드를 여기에 }' 내가 추가하지 않은 그 종속성은 ngCordova를 설치 한 것입니다. 어떻게 추가합니까? –

답변

1

항해. 내 index.html 파일에서 누락 된 몇 가지를 봤어. 프로젝트 ionic을 사용하고 있습니다.

ng-cordova.min.js 파일에는 두 개의 폴더가 있습니다. lib/ngCordova/dist/ng-cordova.min.js에는 $cordovaPushV5 정의가 있습니다.

희망이 도움이됩니다.

+0

감사합니다. 또한 Ravi가 위에 언급 한 내용을 따라 오류를 해결했습니다. –

관련 문제