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 mistake, is that when the user logs in, he takes the Cloud Messaging senderID and logs the GCM in my database to send the notifications according to the rules of my app.
However, on line 29, which is:
$cordovaPush.register(androidConfig).then(function (result) {
Obviously gives an error, because I’m not using Android, I want to use iOS too. How can I adapt my code to use with iOS too?
Follow the full 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);
}
Works great for Android, but how to make it work also on IOS?