Ionic push service not loading app on Android


#1

So i have my project and i have setup Ionic push for iOS and it works perfectly but when i copy the same project and try to run it for android. I get this error. I dont know why. Also if i set it up to work for Android, when i copy the project to iOS i get the same error.

"CORE: Unable to load app ID or API key, falling back to $ionicApp.getApp()…

Why is this so?

Must we do ionic io init in our Android and iOS project? because that will open up two projects on apps.ionic which i dont want. I only want just one project on d ionic service.


#2

Hey there,

Sorry you’re having trouble with the Push Notifications service.

Please find my answer to this other thread that has solved other people’s issues with push notifications: Push notifications problem as of february 2016 new problem because of updating

There seems to be a lot of outdated code out there that is causing people to face many issues.


#3

Looks good but i want to be able to save the user on the ionic.io service under my apps in apps.ionic


#4

Can you provide me with the link for the tutorial/documentation you followed to setup the push service?


#5

https://devdactic.com/android-push-notifications/


#6

What are the contents of your .io-config.json file in your root directory?
Does it have the gcm_key?


#7

yes it has app id, api_key nd gcm_key


#8

Is your new Ionic.push() wrapped up with $ionicPlatform.ready() ?


#9

app.js

.config(['$ionicAppProvider', function($ionicAppProvider) {
    $ionicAppProvider.identify({
      app_id: 'app_id',
      api_key: 'api_key'
    });
}])

ionic push nd register

$scope.ionicRegister = function() {
    console.log("im in ionic register")
    var io = Ionic.io();
    var user = Ionic.User.current();
    var push = new Ionic.Push({
      "onNotification": function(notification) {
        console.log("on notification or smthg")
        alert('Received push notification!');
      },
      "onRegister": function(data) {
        console.log("PUSH NOTIFICATION TOKEN")
        push.addTokenToUser(user);
        user.save();
        $rootScope.token = data.token;
      }
    });

    if (!user.id) {
      user.id = Ionic.User.anonymousId();
    }

    // Just add some dummy data..
    user.set('name', 'Billy');
    user.set('bio', 'Real Estate Agent');
    user.save();


    $timeout(function() {
      push.register();
    }, 1500)
}

This is my code. I am calling the push notification and registering to ionic io service upon login. So i call this method during login method.


#10

You replaced the values here with app_id and api_key or that’s how you have them saved?

According to Ionic.io documentation if your app_id or app_key are invalid then it should give you error code 1. But since you are getting that other error I’m guessing the Ionic.Push() isn’t even able to reach your config for some reason.


#11

I changed it with the right details. I can reach ionic Push nd it saves my device on the ionic service now but i still get the Warn; CORE: Unable to load app ID or API key, falling back to $ionicApp.getApp()


#12

Try this:


#13

There is another solution, same page, first or second comment…

@shieer Have you run ionic config build and ionic prepare PLATFORM.


#14

done all tht. still get the same error message. its weird i know haha bcos it still sends me the device token and saves the user in my app on ionic service. So dont know why im getting the message. Maybe something gets triggered somewhere. Thanks @ihadeed for all the assistance


#15

Track the issue by placing a console.log() before each method call … this will help you identify what is being called before that issue occurs. Then check what that function is doing …


#16

@ihadeed i forgot to mention tht my widget id: in my config.xml for my android and my iOS is different. I had already pushed out the android version to play store when we found out th we couldnt use d same identifier for app store and we had to use another one. Does it me tht it will think the apps r different nd hence cant find d app thts why it gives d error?


#17

Your package identifier (ex: com.example.myapp) and your ionic app id must match what you have on ionic.io. Also your config must be pointing to the same account.

But since you mentioned that it does register on the ionic.io dashboard fine then I highly doubt you have a problem with your configuration, but it’s worth looking into.


#18

@ihaheed i have gotten all to be working now but i want to catch the onNotification event when the push notification is sent from my backend and reset the badge number and also set the state payload tht the page should go to when d notification is clicked on. Nothing happens on my current onNotification event which is like this

var push = new Ionic.Push({
“onNotification”: function(notification) {
console.log(“on notification or smthg”)
alert(‘Received push notification!’);
}
})

So i am not sure when to catch the onNotification event to set the badge number and state payload


#19

hello boyfunky

i facing the same error, can you tell me how you fix it?

thanks


#20

you can only catch the onNotification event when the app is in the foreground. what u hv to do is install this plugin cordova-plugin-badge and when d app is in the foreground and u receive a notification, u can update the badge number.

If u want to aslo send a notification when the app is in the foreground, u can use the cordova-local-notification plugin to do tht as well.

Cheers, let me knw if u need any help.