As in this post i tried all the ways, but still not getting registration id. Kindly some one help me on this.
I am able to see the registration id in eclipse's logcat but it is not calling onNotificationGCM method.
First of all use latest push plugin. Install plugin to your project with this command:
ionic plugin add phonegap-plugin-push
To register your device use this line in your js code, this line will only register your device.
var push = PushNotification.init({ "android": {"senderID": "your-sender-id"}} );
Now that your device has been registered, and event with device token is generated from GCM service,which you can receive in your application using following code
push.on('registration', function(data) {
// data.registrationId , use this token
});
That is it. You do not have to use old plugin because latest one is more simpler to use. Here is link to documentation of latest plugin.
Related
I created my first expo app, who can send notification to multiple users. I use the expo-notification package to generate the ExponentToken and handle incoming notification.
Everythings works perfecly when I use the expo go app, but recently I build my app in apk with eas
$ eas build -p android --profile genAPK
//the genAPK profile :
build: {
"genAPK":{
"android": {
"buildType":"apk"
}
}
}
I downloaded the builded apk, but when my real app want to generate the ExponentToken it just not works and return me a empty string... (I know it because my app crash do a alert() if the token is empty)
I don't know if this help, but I dont use the firebase way, I use the expo node sdk and my own database and API to store tokens and send notifications
Is this a common mistake and how can I fix this ?
Or at least can I see the output of my package even if this is a apk ?
Thanks in advance
My notification is also not working when i upgrade to EAS.
And i found this in Expo discord group:
No experienceId or projectId found. If one or the other can't be inferred from the manifest (eg. in bare workflow), you have to pass one in yourself.
at http://192.168.7.186:8081/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:102608:321 in _createSuperInternal
at node_modules/expo-modules-core/build/errors/CodedError.js:10:8 in constructor
at http://192.168.7.186:8081/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:313197:49 in getExpoPushTokenAsync$
There is a problem with ExpoPushToken, and you can see the source of this error from here expo-notifications-repo. The cause of this error in my case is the projectId, because in the expo-notifications-repo they use expo-constant package which have change in the latest SDK. So i need to add projectId to my app.json
"extra":{
"eas":{
"projectId":"(PROJECT_ID-Expo.dev)"
}
}
As mentioned in git of BLE for IONIC 2 we can register for BLE enable or disable state : https://github.com/don/cordova-plugin-ble-central#startstatenotifications . But It gives me error Property startStateNotification does not exist on type of BLE. My code is :
ble.startStateNotifications(
function(state) {
console.log("Bluetooth is " + state);
});
What I am missing here.I want success and failer both callbacks as well. Please provide solution..
You are calling the plugin through
import {ble} from ionic-native is it?
If you take a look at the files in ionic-native>dist>plugins>ble.js, there are a list of commands provided. Check if there is a command called startStateNotifications.
Property startStateNotification does not exist on type of BLE
This would most likely mean ble does not have this function.
You have to check if ionic-native is using the latest version of cordova-plugin-ble-central.
UPDATE
Instead of importing through ionic-native, you can import the plugin by running this command in command prompt:
cordova plugin add cordova-plugin-ble-central
Afterwards, you will use this as a plugin. So just call ble.startStateNotification() You will not need to include import {ble} from ionic-native already.
I prefer directly importing cordova-plugin-ble-central from the main author instead of going through ionic-native to call cordova-plugin-ble-central. In the event of any updates from the plugin, you can update immediately. Else, you will have to wait on ionic-native
I'm trying to use ionic.io to send push notification. Here is what I did :
Create an app in GCM and enable GCM API.
Create credentials and get the api key.
Create an app in ionic.io dashboard
Create a security profile and add the api key
Create an api token in ionic.io dashboard
My source code in app.js which generated by ionic start pushdemo
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
"debug": true
});
push.register(function(token) {
alert(token.token);
console.log("Device token:",token.token);
push.saveToken(token);
});
7.Add push plugin:
ionic plugin add phonegap-plugin-push --variable
SENDER_ID="myproject_number"
I tried both with or without quotation mark around myproject_number. It's the project number in step 1.
8.Set the dev_push to false
9.Hook my app to ionic.io by ionic io init
10.Run ionic run android -lc
Found the following error message:
What's wrong with it? Can anybody help? Thanks.
i had the same problem its generally because of proxy issue
you are behind the proxy it means you are using internet by making request to the server ,so first you should use your own internet (in this case if you use WIFI
then also it will work )
second aafter creating your project dirsctly make login from your cinsole to ionic io
it will ake for email and password that will make your app live
third
ionic plugin add phonegap-plugin-push --variable SENDER_ID="myproject_number"
use quotes for entering your project number.project number also called GCM number and your server key is the key you generated in same project means google console which enable you to use google services.
and dont forget to add android platform
ionic start pushCall
ionic login
ionic upload
//open google console
1-create project
2-use google api
1-mobile APIs
2-select google cloud messaging and eneble it
3- go to credential and create API key
//after that add following plugin
ionic add ionic-platform-web-client
ionic plugin add phonegap-plugin-push --variable SENDER_ID="991785317333"
(dont remove quotes while adding gcm number)
//add platfom
ionic platform add android
ionic io init
ionic config set dev_push true
//open ionic io
go to setting
1-create api key
2-go to certificate and create security profile name edit id click on android and add GCM key
and save it.
//add this code to app.js
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
"debug": true
});
push.register(function(token) {
console.log("My Device token:",token.token);
push.saveToken(token); // persist the token in the Ionic Platform
});
});
})
//to test wether your configure correctly with ionic io open launch postman
//and then do the following things:
1-create collection give it a valid name
2-in body click on text and select Application/json
it will add header automatically
3-add another header
key as Authorization
value as bearer followed by your api token from ionic io
4-select "raw " as the format of our json
2-in body section of your collection write
following code
{
"tokens": ["DEV_DEVICE_TOKEN"],
"profile": "PROFILE_NAME",
"notification":
{
"message": "This is my demo push!"
}
}
//now it will prompt message on browser
ionic config set gcm_key
ionic config set dev_push false
ionic build android
install your app in mobile and send the notification from postman
(Mahesh Sampat Nighut)
navi mumbai
add this code in your app.js
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
"debug": true
});
push.register(function(token) {
console.log("My Device token:",token.token);
push.saveToken(token); // persist the token in the Ionic Platform
});
});
})
and dont forget to run below command
ionic config set dev_push true
when you are testing it on browser make above cammand true,this means developmant mode ,and when you are making apk this time you have to make above command false
In My ionic Cordova Application, I am using In App Purchase Plugin: https://github.com/j3k0/cordova-plugin-purchase
Here is the method that I use to initialise store:
storekit.init({
debug: true, // Enable IAP messages on the console
ready: service.IAP.onReady,
purchase: service.IAP.onPurchase,
restore: service.IAP.onRestore,
error: service.IAP.onError
});
This Initialization works fine with iOS and all the products loading fine as well, But Android device does not load In Purchase.
I guess, For android there is a different initialization method.
I have added plugin in app:
cordova plugin add cc.fovea.cordova.purchase --variable BILLING_KEY="<BILLING_KEY>"
Please help.
Firstly, when I was using it, the npm version was a little buggy on android. Try removing it and adding it from Git.
cordova plugin add https://github.com/j3k0/cordova-plugin-purchase.git --variable BILLING_KEY="MIIB...AQAB"
Secondly, it looks like you are maybe using some older syntax. The doco for this plugin doesnt really have very good version control. There are different versions of doco all over the net. I think this is the latest version.
This is my initialisation code. See if it works for you too.
products = ["my.test.product"];
for (var i = 0; i < products.length; i++) {
if (window.store) {
store.register({
id: products[i],
alias: 'alias '+i,
type: store.NON_CONSUMABLE
});
}
}
// When everything goes as expected, it's time to celebrate!
if (window.store) store.ready(function() {
console.log("\\o/ STORE READY \\o/");
});
// After we've done our setup, we tell the store to do
// it's first refresh. Nothing will happen if we do not call store.refresh()
if (window.store) store.refresh();
You can also send the store object to console.log to have a good look at it in chrome debugger.
Oh, and if you have more than one app, make sure you are using the correct BILLING_KEY by removing and readding the plugin.
Good Luck!
I have spent the last few days trying to get notifications working, reading up on all sorts of plugins and I've come to the end of my rope. I've been able to successfully receive notifications with Parse's test apps on Android and iOS, but whenever I try to add to my own app I see an error in adb logcat
cordova version: 3.5.0-0.2.4
phonegap-parse-plugin
These are the steps I perform:
cordova create pushTest
cordova platform add android
cordova plugin add https://github.com/benjie/phonegap-parse-plugin
then inside of www/js/index.js I alter the onDeviceReady function to look like this (with my actual appID and clientKey substituted)
onDeviceReady: function() {
app.receivedEvent('deviceready');
parsePlugin.initialize(appId, clientKey, function() {
parsePlugin.subscribe('', function() {
alert('OK');
}, function(e) {
alert('error');
});
}, function(e) {
alert('error');
});
}
Then I clear out my Installation class in Parse to make sure the app registers successfully. I also make sure any previous app I've installed to my android device has been deleted. Then...
cordova build
adb install platforms/android/ant-build/HelloCordova-debug.apk
I get an alert popup that says 'OK' and I have a new record in the Installation class in Parse. I make sure the app is not running in the foreground on my android device. I then send a push notification from Parse, and I don't see anything while running adb logcat
From some other debugging I had tried, I tried replacing the version of the Parse SDK from 1.3.8 to 1.5.1 by just removing the old file from the platforms/android/libs dir and putting the new one there. Once I do that, I see the below error in adb logcat
( 2795): GCM message io.cordova.hellocordova 0:1402793727153630%0#39597f64f9fd7ecd
W/GCM-DMM ( 2795): broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=io.cordova.hellocordova (has extras) }
That error is what I've been stuck at, and would love guidance with.
My code (minus my appID and clientKey) is available at: https://github.com/rpiwetz/notif7
You may want to check this plugin for sending and receiving notification using parse for android
I had very similar problems, the init function worked fine but I wasn't receiving notifications. In the end I manually added some code to the main Activity class:
// register device for parse
Parse.initialize(this, "app_id", "client_key");
PushService.setDefaultPushCallback(this, MyApp.class);
ParseAnalytics.trackAppOpened(getIntent());
ParseInstallation.getCurrentInstallation().saveInBackground();
From: https://stackoverflow.com/a/24426563/884842