Connect Ionic with Firebase to push Notifications

I follow this guide


to set up for pushing notifications and i might have done a problem that i don’t get it.

I had put on Security Profiles & Credentials the firebase server key. I put Cloud Configurations on app.js
and this on controllers.js at the controller of my first page.

.controller(‘MyCtrl’, function($scope, $ionicPush) {
$ionicPush.register().then(function(t) {
return $ionicPush.saveToken(t);
}).then(function(t) {
console.log(‘Token saved:’, t.token);
});

$scope.$on(‘cloud:push:notification’, function(event, data) {
var msg = data.message;
alert(msg.title + ': ’ + msg.text);
});

})

The code run and i don’t get any error but i don’t get notification
Any idea about the problem?

Does your app actually register for push and log a push token to the console?

PS: By the way, it would help the legibility of your post a lot if you could format you code as code. Just select the code use the </> button in the toolbar that adds the necessary 3 space in front of your code lines. Thanks.

Hi thanks for the info.

When you mean register for a push you mean i have make Cloud Configuration?

 .config(function($ionicCloudProvider) {
  $ionicCloudProvider.init({
    "core": {
      "app_id": "APP_ID"
    },
    "push": {
          "sender_id": "SENDER_ID",
          "pluginConfig": {
            "ios": {
              "badge": true,
              "sound": true
            },
            "android": {
              "iconColor": "#343434"
            }
          }
        }
  });
})

But I am getting this error on console “TypeError: Cannot read property ‘register’ of undefined”

No. When an app first starts it “registers” with Apple/Google to get a notification token. This is initiated by calling a register() method on the Push object created by the library.

Ok now we are getting somehwere. The register() call is actually in the code you posted in the first post you made here - and as it is called on $ionicPush this doesn’t seem to be present. This is you problem.

Ok i get it.

But why it isn’t present once it is a function on lib?

I assume something went wrong during the installation process. You might want to create a new, blank Ionic 1 app and redo the installation process to see if you get better results then. If so, see what’s the difference between the new and your current project.

Ok i will try it out.

Also i check the program on emulator. Is this a problem?

Yes, there are no push notifications on the iPhone/Pad emulators. You will need a physical device to test push.

Former versions of Ionic Cloud offered a “dev” mode where you could also test Push in the browser, but I don’t know if this is available in the current version. Sorry.

(But if I remember correctly testing in the emulator shouldn’t result in $ionicPush being broken / non-existent.)

Nice so i found my problem.

Thanks a lot

Does it work on a real device?

No it didn’t work but i might have some errors on the code because i can’t do anything on the first page that i have the controller for the push notifications

I fix some bugs and now in the console i get this message

“Ionic Push: Disabled! Native push notifications will not work. Run your app on an actual device to use push.”

But when i run in on my device i don’t get any notification

But do you get the console output when registering the token?
Ionic Docs - Ionic Documentation

I don’t get any token on the console

Any idea on how to solve the problem?

I’m getting the same error…
Ionic Push: Disabled! Native push notifications will not work. Run your app on an actual device to use push.

The console doesn’t show me nothing at all.

I’m quite lost here!!!

You can just read my posts above and answer all the questions I posed…

Most important: Are you testing on a real device?

Yes. I’m testing on a real device!

It’s the same situation for me it doesn’t work and i don’t get anything on the console.Also i have put native Auth because i thought it might be the problem that i don’t have register users and still nothing happen

A post was split to a new topic: Cannot build with cordova-plugin-fcm