raix-push
raix-push copied to clipboard
Meteor JS 1.8 Does it work?
I've been having a nightmare getting this going so far. Just wondering if it works on either Meteor 1.7 or 1.8 I've had no luck with basically an out of the box Meteor install
if(Meteor.isClient){
Push.debug = true;
Push.Configure({
android: {
senderID: xxxxx,
alert: true,
badge: true,
sound: true,
vibrate: true,
clearNotifications: true
// icon: '',
// iconColor: ''
},
ios: {
alert: true,
badge: true,
sound: true
}
});
}
if(Meteor.isServer){
Push.Configure({
apn: {
certData: Assets.getText('meteorApp-cert-dev.pem'),
keyData: Assets.getText('meteorApp-key-dev.pem'),
passphrase: '',
production: true,
sound: true,
badge: true,
alert: true,
vibrate: true,
// 'sendInterval': 15000,
// gateway: 'gateway.push.apple.com',
// production: Meteor.isProduction,
},
gcm: {
projectNumber: xxx,
apiKey: xxxx
}
});
Push.allow({
send: (userId, notification) => {
console.log('anything', userId, notification)
// allow all users to send notifications
return true;
}
})
}
I test this fork https://github.com/FishSaidNo/push la to switch to FCM on meteor 1.8 https://github.com/FishSaidNo/push/blob/master/docs/FCM.md (android target 26) be up to date at android studio (tool, sdk, ...)
for build you have to use that for me https://github.com/meteor/meteor/issues/7600#issuecomment-383327945 put the build-extras.gradle file at the root of the project meteor /cordova-build-override/platforms/android/build-extras.gradle
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:+'
classpath 'com.google.gms:google-services:3.0.0'
}
}
ext.postBuildExtras = {
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
def inAssetsDir = file("assets")
def outAssetsDir = inAssetsDir
def outFile = new File(outAssetsDir, "cdvasset.manifest")
def newTask = task("cdvCreateAssetManifest") << {
def contents = new HashMap()
def sizes = new HashMap()
contents[""] = inAssetsDir.list()
def tree = fileTree(dir: inAssetsDir)
tree.visit { fileDetails ->
if (fileDetails.isDirectory()) {
contents[fileDetails.relativePath.toString()] = fileDetails.file.list()
} else {
sizes[fileDetails.relativePath.toString()] = fileDetails.file.length()
}
}
outAssetsDir.mkdirs()
outFile.withObjectOutputStream { oos ->
oos.writeObject(contents)
oos.writeObject(sizes)
}
}
newTask.inputs.dir inAssetsDir
newTask.outputs.file outFile
def preBuildTask = tasks["preBuild"]
preBuildTask.dependsOn(newTask)
}
in /mobile-config.js add in addition to the rest
App.configurePlugin ('phonegap-plugin-push', {
SENDER_ID: xxxxxxxxxx
});
App.addResourceFile ('google-services.json', 'google-services.json', 'android');
add google-services.json to the root of your meteor project
be careful if you went from "raix:push" to this fork the client side configuration there is "cordovaOptions" which includes the config which was not present before
do not forget that "payload" must be JSON.stringify with FCM
you need to activate the FCM API https://console.developers.google.com/apis/api/fcm.googleapis.com/overview?project=XXXXXXXXXX
if you want to configure FCM for ios https://medium.com/@felipepucinelli/how-to-add-push-notifications-in-your-cordova-application-using-firebase-69fac067e821 and add GoogleService-Info.plist to the root of your project meteor and add these lines to your mobile-config.js, APP_NAME should be replaced with the real app name
App.addResourceFile ('GoogleService-Info.plist', 'APP_NAME/Resources/GoogleService-Info.plist', 'ios');
Doc https://github.com/raix/push/blob/master/docs/ANDROID.md https://github.com/FishSaidNo/push/blob/master/docs/FCM.md Migrate a GCM Client App for Android to Firebase Cloud Messaging https://developers.google.com/cloud-messaging/android/android-migrate-fcm https://github.com/meteor/meteor/pull/9748
Thanks for the speedy response. I'll see if this does it for me.
Okay so two days of continued head smashing and I've gotten very not far at all. Does anyone have a full version of this working they could share even something in 1.7 or just with more FCM. Even the guide above although detailed is super non-linear and gets really confusing around the Android channel requirements and what I'm suppose to actually include in Push.send. I attempted to install your fork pretty unsuccessfully, really no idea how to make sure its the right version. But even on install the blurb for Push.send has JS formatting errors and doesn't compile. See the misplace brackets before query.
I'm just going to list out various states I'm getting to. Common problems I'm having. I get my tokens successfully and even some activity in the firebase console but no messages appear to be sending. None of those Push sent to x ios and x android devices. Sometimes things show up in the the _raix_push_notifications collection sometimes they don't. Same with the app_tokes collection even though the call backs for the tokens appear to be valid every time.
Adding the cordova firebase plugin breaks xCode I get weird linking errors and when I try to run android with this in place my cordova errors go crazy.
Help? @raix
@nathans7 you are in meteor 1.8? you use fork indicated? did you update in android studio, sdk and tool?
copy what you put in client and server configuration and the code to send a push
I test and it works I will try to help you
my config
client startup
if (Meteor.isDevelopment) {
Push.debug = true;
}
Meteor.startup(function () {
if (Meteor.isCordova) {
PushNotification.createChannel(
function () {
console.log('Channel Created!');
},
function () {
console.log('Channel not created :(');
}, {
id: 'PushPluginChannel',
description: 'Channel Name Shown To Users',
importance: 3,
vibration: true,
},
);
Push.Configure({
cordovaOptions: {
// Options here are passed to phonegap-plugin-push
android: {
sound: true,
vibrate: true,
clearBadge: false,
clearNotifications: true,
forceShow: false,
// icon: 'ic_stat_co_24',
// iconColor: '#6B97AF',
},
},
appName: 'main'
});
Push.addListener('startup', function () {
Router.go('/notifications');
});
Push.addListener('message', function (notification) {
function alertDismissed(buttonIndex) {
if (buttonIndex === 1) {
const payload = JSON.parse(notification.payload.custom_key1);
if (payload.url) {
Router.go('/notifications');
} else {
Router.go('/notifications');
}
}
}
window.confirm(notification.message, alertDismissed, 'notifications', ['Voir', 'fermer']);
});
}
});
config server
const serviceAccountJson = JSON.parse(Assets.getText('FirebaseAdminSdkServiceAccountKey.json'));
/*
what to do to get the FirebaseAdminSdkServiceAccountKey.json credential file to copy to the /private directory of your meteor project
https://firebase.google.com/docs/admin/setup
To use the Firebase Admin SDKs, you'll need a Firebase project, a service account to communicate with the Firebase service, and a configuration file with your service account's credentials.
If you don't already have a Firebase project, add one in the Firebase console. The Add project dialog also gives you the option to add Firebase to an existing Google Cloud Platform project.
Navigate to the Service Accounts tab in your project's settings page.
Click the Generate New Private Key button at the bottom of the Firebase Admin SDK section of the Service Accounts tab.
After you click the button, a JSON file containing your service account's credentials will be downloaded. You'll need this to initialize the SDK in the next step.
you need to activate the FCM API https://console.developers.google.com/apis/api/fcm.googleapis.com/overview?project=id of your project
*/
if (Meteor.isDevelopment) {
Push.debug = true;
}
Push.Configure({
fcm: {
serviceAccountJson: serviceAccountJson
},
production: true,
sound: true,
badge: true,
alert: true,
vibrate: true,
appName: 'main',
});
Push.allow({
send(userId, notification) {
return true;
},
});
test push
const notId = Math.round(new Date().getTime() / 1000);
const title = 'new notification';
const text = 'you have a new notification';
//custom info
const payload = {info:'test', url:'http://www.google.fr'};
//number
const badge = 5;
const payloadStringify = {};
payloadStringify.custom_key1 = JSON.stringify(payload);
Push.send({
from: 'push',
title,
text,
payload: payloadStringify, // All payload values must be strings if sending using FCM
sound: 'default',
query,
badge,
apn: {
sound: 'default',
},
contentAvailable: 1,
androidChannel: 'PushPluginChannel',
notId,
});
};
Okay thank you so much! Once again. Desperation setting in.
@nathans7 this package does work.. look at this
https://github.com/raix/push/issues/341
https://github.com/raix/push/issues/341#issuecomment-430885023
https://github.com/da314pc/push
I have it working on Android hoping to get iOs functional but my xCode is getting errors reladed to firebase
@nathans7 your probably getting the pods related errors, you have to setup pods in the project on ios
https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/INSTALLATION.md#ios-details
I did get some pod related issues running pod install inside my meteor local file let me build to ios finally but there's still issues with ios. Using this fork doesn't seem to allow the apn usage in ios. I've been trying to figure out a version of cordova-plugin-firebase that works with this but it seems to be pretty buggy itself.
@nathans7 on iOS, check to see if the tokens are registering successfully in the console. Local builds on the device wont receive notifications if you are using the production certificate. Check what certificates your using, also turn the debug server on. You may get an error 8 which means delivery problem, (trying to send a notification without a production signed app).
Well I do have push notifications work on both. FCM for android and APN for iOS but randomly my meteor builds stopped working giving me a linker issue that I had which was initially resolved running pod install inside .meteor/local/cordova-builds/platforms/ios. I can run meteor run ios-device fine but do the build and my linker issue comes back.
Not sure if this is related but I had to re-install everything android related after getting the APN to work locally. And I had to re-add my ios platform to get rid of other issues. So these seem to be corrupting something in my system.
@nathans7 what version of meteor are you running? I remember when I used an earlier version of meteor every time I ran the build it was corrupted, so I had to do a meteor reset before each new build.
I am on 1.6 now so I can just run the build multiple times without resetting. But yea that sucks if you have to clear the build than you have to run a pod install every time.
I'm running Meteor 1.8 actually. The iOs stuff might be related just directly to the packages but the android issue did require me to re-install everything. I tried an xCode re-install.
Again podinstall inside .meteor/local fixes meteor run ios-device, but once I do the same build call the linker issue comes back.
Linker issue on ld: library not found for -lGoogleToolboxForMac has always been the problem.
Again locally for meteor runs I have it fixed but not for building
Well running pod install inside the builded folder for ios seems to let me build it.
Closing now fingers crossed there aren't anymore issues. If any admins want to a write up for Meteor 1.8 I feel like I hit every pitfall imagineable. And much thanks to all the speedy responses.
@nathans7 -lGoogleToolboxForMac this error can be annoying. but pod install the cordova platform ios build folder. Then run the meteor ios build. That should take care of everything. We'll get the instructions updated.
@nathans7 I had the same issue (meteor V 1.8), instead of reinstalling everything, try following these steps next time:
- Build your meteor app (meteor build ../output --server=yourServer)
- Traverse to output/ios/project/ in your terminal and install pods there Then open yourProjectName.xcdworkspace instead of yourProjectName.xcdproject
Well I do have push notifications work on both. FCM for android and APN for iOS but randomly my meteor builds stopped working giving me a linker issue that I had which was initially resolved running pod install inside .meteor/local/cordova-builds/platforms/ios. I can run meteor run ios-device fine but do the build and my linker issue comes back.
Not sure if this is related but I had to re-install everything android related after getting the APN to work locally. And I had to re-add my ios platform to get rid of other issues. So these seem to be corrupting something in my system.
Do you builder android and ios at the same time? (Mac)
if you have to do a meteor reset before rebuilder for android if yes then https://github.com/meteor/meteor/issues/10308
buildscript {
repositories {
maven {
url "https://maven.google.com"
}
jcenter ()
...
}
So another issue. I'm hoping to upgrade to 1.8.1 for HCP issues. But the beta versions all give this error inside the gradle file when I build to android. So meteor run android-device gives this
- What went wrong: A problem occurred evaluating project ':app'.
Cannot add task ':app:cdvCreateAssetManifest' as a task with that name already exists.
So the file appears to run twice? iOs seems to work fine though
@nathans7 with meteor 1.8.1 no need for the build-extras.gradle file
@nathans7 I trick I found to avoid having to fully upgrade your app is to just add the latest version of meteorwebapp to your cordova plugins file
I have [email protected] but I'm still on meteor 1.6
@aboire hi, i'm trying to follow this https://github.com/raix/push/issues/357#issuecomment-448511501 in here are you using https://github.com/FishSaidNo/push or https://github.com/raix/push ? if using https://github.com/FishSaidNo/push then how to install this in meteor?
@saikatharryc I use https://github.com/FishSaidNo/push , it must be installed locally
for anyone from google: this package (raix:push
) works well with Android 8 and Meteor 1.8.1 (latest). Just follow the instructions in the readme
Hi, Does anyone know how to resolve this error? File google-services.json is missing.
- Put google-services.json in .meteor and root
- Have tried with appname and without (in meteor-config.js) App.addResourceFile ('google-services.json', 'google-services.json', 'android'); Thanks
@frankwo1 google-services.json has to been in your android project folder. Usually I enter the command with my device not connected meteor run android-device --mobile-server 'your site' --settings settings-production.json --verbose --settings flag optional build should fail, with unable to connect, then open the project in android studio and make sure you copy that google-services.json into the root android project folder
@frankwo1 I got it solved by adding the following line App.addResourceFile ('google-services.json', 'app/google-services.json', 'android'); in the mobile-config.js file. google-services.json is in the root of the project.
Kr
Wout
@woetwoet this worked - did not get a chance to try @da314pc but thanks anyway
Well I do have push notifications work on both. FCM for android and APN for iOS but randomly my meteor builds stopped working giving me a linker issue that I had which was initially resolved running pod install inside .meteor/local/cordova-builds/platforms/ios. I can run meteor run ios-device fine but do the build and my linker issue comes back.
Not sure if this is related but I had to re-install everything android related after getting the APN to work locally. And I had to re-add my ios platform to get rid of other issues. So these seem to be corrupting something in my system.
Doing this fixed my archive issues, and it is repeatable. The error is due to Cocoa Pods causing an error as a result of a few plugins, phonegap-plugin-push in my case: https://ionic.zendesk.com/hc/en-us/articles/360000170008-iOS-Build-fails-with-error-ld-library-not-found-for-lGoogleToolboxForMac-
Thanks a ton!