ionic framework parse push notifications device no

2019-08-22 07:00发布

问题:

I'm trying to get parse push notifications to work on my android device. I have done the GCM setup and tested it with urbanairship. It works. But for some reasons I need to get it to run with parse. What I have done so fare...

in my $ionicPlatform.ready function I initialize the parse plugin like this:

window.parsePlugin.initialize(
"XXX",
"XXX",
function() {
    alert( 'PARSE INIT OK' );
    window.parsePlugin.getInstallationId(function(id) {
        installationID = id;

    }, function(e) {
        console.log("Error Getting ID: " + e.code + " : " + e.message);
    })
 },
  function( e ) {
    alert( 'PARSE FAILED' );
  });
});

In my HelloCordova.java files onCreate function I added this:

Parse.initialize(this, "XXX", "XXX");
PushService.setDefaultPushCallback(this, HelloCordova.class);
ParseAnalytics.trackAppOpened(getIntent());
ParseInstallation.getCurrentInstallation().saveInBackground();

I followed the Parse Android instructions to modify my AndroidManifest.xml. And I added the parse and phonegap notification plugin to the project.

cordova plugin add https://github.com/avivais/phonegap-parse-plugin

But I can't register the device for Parse notification.

回答1:

i also tried so many times on this. iOS did work but not android. but after i installed this plugin it worked.

https://github.com/avivais/phonegap-parse-plugin

Use this in app.js and it did work.

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
    try{
        parsePlugin.initialize('xxx', 'yyy', function() {
            alert('success');
        }, function(e) {
            alert('error');
        });

    }catch(err){
        alert('Parse Error '+err.message); //this gets executed all time
    }
  });
})