Firebase Cloud Messaging with $ cordovaPush, how to work for iPhone too?

0

I am emulating my application by Intel XDK for IOS. I use it, by working with Windows and it emulates and gives the error messages very well.

The first error is that when the user logs in, he takes the senderID from Cloud Messaging and registers GCM in my database to send notifications according to the rules of my app.

However, at line 29, which is:

$cordovaPush.register(androidConfig).then(function (result) {

Obviously it gives a mistake, because I'm not using Android, I want to use iOS as well. How can I adapt my code for use with iOS too?

Follow the complete code:

$scope.register_gcm = function () {

            $ionicLoading.show();
            var androidConfig = {
                "senderID": "MEU_ID_DO_GOOGLE_MESSAGE",

            };


            document.addEventListener("deviceready", function () {
                //            alert("device ready");
                $cordovaPush.register(androidConfig).then(function (result) {
                    // Success
                }, function (err) {
                    $ionicLoading.hide();
                })

                $rootScope.$on('$cordovaPush:notificationReceived', function (event, notification) {
                    //                 alert("Passa do rootScope.on");
                    $ionicLoading.hide();
                    switch (notification.event) {
                        case 'registered':
                            if (notification.regid.length > 0) {
                                console.log(notification.regid);

                          //      alert(notification.regid);

                                $http.get("http://MEUSITE_ONDE_FACO_UPDATE_NA_TABELA_DE_USUARIO.com.br/admin/apis/push_config_vovo/set_gcmkey.php?user_id=" + window.localStorage.getItem("user_id") + "&gcm_key=" + notification.regid)
                                    .then(function (result) {
                                        console.log("printo the result.data: " + result.data);
                                //        alert(result.data);
                                        window.localStorage.setItem("gcm", notification.regid);
                                //        alert("GCM REGISTERED!!");
                                        $ionicLoading.hide();
                                    }, function (result) {
                                        console.log(result);
                                        $ionicLoading.hide();
                                    })



                            }
                            break;

                        case 'message':
                            // this is the actual push notification. its format depends on the data model from the push server
                            //alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
                            break;

                        case 'Erro':
                            alert('GCM error = ' + notification.msg);
                            break;

                        default:
                            alert('Nenhum evento GCM foi encontrado');
                            break;
                    }
                });

            }, false);


        }

It works great for Android, but how do I also work on iOS?

    
asked by anonymous 14.08.2017 / 16:30

1 answer

2

I understand that you need to configure the settings according to the platform. So you need to check if it's iOS / Android and then pass the parameters to the $ cordovaPush.register. For this you can use link .

  // CONFIGS
  var pushConfig = {
    android: {
      "senderID": "ID_GOOGLE",
    }, 
    ios: {
      "senderID": "ID_IOS",
    }
  };

  // SELECIONAR CONFIG DE ACORDO COM PLATFORM
  function getPushConfig() {
    return pushConfig[device.platform.toLowerCase()];
  }

  document.addEventListener("deviceready", function () {
      $cordovaPush.register(getPushConfig()).then(function (result) {
    
14.08.2017 / 20:53