Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meteor JS 1.8 Does it work? #357

Open
n-th-n-n opened this issue Dec 15, 2018 · 30 comments
Open

Meteor JS 1.8 Does it work? #357

n-th-n-n opened this issue Dec 15, 2018 · 30 comments

Comments

@n-th-n-n
Copy link

n-th-n-n commented Dec 15, 2018

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;
		}
	})
}
@aboire
Copy link
Collaborator

aboire commented Dec 15, 2018

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
meteor/meteor#7600 (comment)
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
meteor/meteor#9748

@n-th-n-n
Copy link
Author

Thanks for the speedy response. I'll see if this does it for me.

@n-th-n-n
Copy link
Author

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

@aboire
Copy link
Collaborator

aboire commented Dec 19, 2018

@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

@aboire
Copy link
Collaborator

aboire commented Dec 19, 2018

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,
  });
};

@n-th-n-n
Copy link
Author

Okay thank you so much! Once again. Desperation setting in.

@da314pc
Copy link
Collaborator

da314pc commented Dec 21, 2018

@nathans7 this package does work.. look at this

#341

#341 (comment)

https://github.com/da314pc/push

@n-th-n-n
Copy link
Author

I have it working on Android hoping to get iOs functional but my xCode is getting errors reladed to firebase

@da314pc
Copy link
Collaborator

da314pc commented Dec 27, 2018

@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

@n-th-n-n
Copy link
Author

n-th-n-n commented Jan 6, 2019

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.

@da314pc
Copy link
Collaborator

da314pc commented Jan 7, 2019

@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).

@n-th-n-n
Copy link
Author

n-th-n-n commented Jan 7, 2019

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.

@da314pc
Copy link
Collaborator

da314pc commented Jan 8, 2019

@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.

@n-th-n-n
Copy link
Author

n-th-n-n commented Jan 8, 2019

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.

@n-th-n-n
Copy link
Author

n-th-n-n commented Jan 8, 2019

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

@n-th-n-n
Copy link
Author

n-th-n-n commented Jan 8, 2019

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.

@da314pc
Copy link
Collaborator

da314pc commented Jan 8, 2019

@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.

@shivang007
Copy link
Collaborator

@nathans7 I had the same issue (meteor V 1.8), instead of reinstalling everything, try following these steps next time:

  1. Build your meteor app (meteor build ../output --server=yourServer)
  2. Traverse to output/ios/project/ in your terminal and install pods there
    Then open yourProjectName.xcdworkspace instead of yourProjectName.xcdproject

@aboire
Copy link
Collaborator

aboire commented Jan 8, 2019

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
meteor/meteor#10308

buildscript {
     repositories {
        
         maven {
             url "https://maven.google.com"
         }
   jcenter ()
      ...
     }

@n-th-n-n
Copy link
Author

n-th-n-n commented Jan 31, 2019

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

@aboire
Copy link
Collaborator

aboire commented Feb 1, 2019

@nathans7 with meteor 1.8.1 no need for the build-extras.gradle file

@da314pc
Copy link
Collaborator

da314pc commented Feb 1, 2019

@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 cordova-plugin-meteor-webapp@1.6.4
but I'm still on meteor 1.6

@saikatharryc
Copy link

@aboire hi, i'm trying to follow this #357 (comment)
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?

@aboire
Copy link
Collaborator

aboire commented Mar 14, 2019

@saikatharryc I use https://github.com/FishSaidNo/push , it must be installed locally

@yorrd
Copy link

yorrd commented Apr 26, 2019

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

@frankwo1
Copy link

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

@da314pc
Copy link
Collaborator

da314pc commented Aug 13, 2019

@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

@woetwoet
Copy link

woetwoet commented Aug 14, 2019

@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

@frankwo1
Copy link

@woetwoet this worked - did not get a chance to try @da314pc but thanks anyway

@aeonei
Copy link

aeonei commented Jan 17, 2020

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants