parse-push-plugin icon indicating copy to clipboard operation
parse-push-plugin copied to clipboard

ionic2 - installation not saved

Open marcelinne opened this issue 8 years ago • 11 comments

Hi I'm using ionic2, but it never creates the installation, is something more what we should change in order to use ionic2 ?, ParsePushPlugin.getInstallationId is working fine, it gets me an id, but when I check in database the "Installation" class continues empty, do you have any idea what it could be? Thanks in advance.

Here is my configuration in parse server:

`

var api = new ParseServer({

databaseURI: databaseUri || 'mongodb://127.0.0.1:27017/dev',

cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',

appId: process.env.APP_ID || 'placeId',

masterKey: process.env.MASTER_KEY || 'secret', 

serverURL: process.env.SERVER_URL || 'http://localhost:1337/api',

push: {

  android: {

    senderId: 'MySenderId',

    apiKey: 'MyApiKey'

  }

}

}); `

My cloud function: `

Parse.Cloud.define('sendPush', function(request, response) {

if (!request.user) return response.error("you are not a user;

var query = new Parse.Query(Parse.Installation);

query.equalTo('userId', request.user);

Parse.Push.send({
  "where": query ,
  "data": {
    "title": "The Shining",
    "alert": "This is a messagey."
  }
}, {
  useMasterKey: true,
  success: function() {
    console.log("push sent");
    response.success('push sent');
    
  },
  error: function(error) {
    console.log(error);
    response.error(error);
  }
});

}); `

In ionic2 after install parse-push-plugin, I added this to my config.xml: `

<preference name="ParseAppId" value="placeId" />

<preference name="ParseServerUrl" value="http://localhost:1337/parse/" />

<preference name="ParseGcmSenderId" value="MySenderId" />

<preference name="ParseMultiNotifications" value="true" />

<preference name="ParseNotificationIcon" value="icon" />`

In my ts file after the imports: `

declare var ParsePushPlugin: any; `

Then in the constructor class: `

ParsePushPlugin.getInstallationId(function(id) {

            // note that the javascript client has its own installation id,

            // which is different from the device installation id.

            console.log("device installationId: " + id);

            alert("device installationId: " + id);

    }, function(e) {

            console.log('error');

    });

` This last part gets me the installation id, but after check in database none row is created! Please help, I'm missing some configuration? Thanks in advance

marcelinne avatar Jul 14 '17 19:07 marcelinne

Hello,

Have you tried calling manual registration?

Something like this in your app.component.ts:

 if (window['ParsePushPlugin'] !== undefined) {
            let ParsePushPlugin = window['ParsePushPlugin'];
            ParsePushPlugin.register(() => {

            }, (e) => {

            });

or setting up the following line in the config.xml

<preference name="ParseAutoRegistration" value="false" />

cleever avatar Jul 17 '17 21:07 cleever

Thank a lot @cleever for the helping, I've just tried and also it is not working yet :'( .The Installation class continues empty. I'm going to share you my AndroidManifest.xml ` <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:name="github.taivo.parsepushplugin.ParsePushApplication" android:supportsRtl="true">

    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">

        <intent-filter android:label="@string/launcher_name">

            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />

        </intent-filter>

    </activity>

    <provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">

        <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />

    </provider>

    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/fb_app_id" />
    <meta-data android:name="com.facebook.sdk.ApplicationName" android:value="@string/fb_app_name" />

    <activity android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/fb_app_name" android:name="com.facebook.FacebookActivity" />

    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

    <provider android:authorities="${applicationId}.sharing.provider" android:exported="false" android:grantUriPermissions="true" android:name="nl.xservices.plugins.FileProvider">

        <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/sharing_paths" />

    </provider>

    <service android:name="com.parse.PushService" />

    <receiver android:exported="false" android:name="github.taivo.parsepushplugin.ParsePushPluginReceiver">

        <intent-filter>

            <action android:name="com.parse.push.intent.RECEIVE" />

            <action android:name="com.parse.push.intent.DELETE" />

            <action android:name="com.parse.push.intent.OPEN" />

        </intent-filter>

    </receiver>

    <receiver android:name="com.parse.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">

        <intent-filter>

            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="${applicationId}" />

        </intent-filter>

    </receiver>

    <meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/icon" />

    <meta-data android:name="com.parse.push.gcm_sender_id" android:value="id:MyGCM_senderID" />

</application>

`

marcelinne avatar Jul 17 '17 22:07 marcelinne

Your AndroidManifest.xml seems fine. Did you put the registration inside a platform.ready() function?

Also, what about the following line in your config.xml ?

<preference name="ParseAppId" value="YOUR_APP_ID" />

cleever avatar Jul 17 '17 22:07 cleever

Yes I did put the register function in platdorm.ready() and also a message if it is succesful or there is some error, and the succesful message is thrown, but still no creating the installation.

About the ParseAppId, yes I added in my code, sorry my mistake I did not added above, I'll update.

marcelinne avatar Jul 17 '17 23:07 marcelinne

Ok.

Try to set your clientKey on parse-server, and restart the server. After that, put your clientkey in config.xml:

<preference name="ParseClientKey" value="your-parse-client-key" />

cleever avatar Jul 17 '17 23:07 cleever

It is frustrating, also that way is not working, but shouldn't be requiered as well as clientKey is used with Parse are no longer necessary with Parse Server.

marcelinne avatar Jul 18 '17 15:07 marcelinne

After debugging I see that this part of the code is thowing an error (ParsePushApplication.java line79): `

ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {

    @Override

    public void done(ParseException ex) {

      if (null != ex) {

        Log.e(LOGTAG, ex.toString());

      } else {

        Log.d(LOGTAG, "Installation saved");

      }

    }

  });

`

The error is:

com.parse.ParseRequest$ParseRequestException: bad json response

marcelinne avatar Jul 18 '17 19:07 marcelinne

Strange...

I have ionic1 and ionic2 apps working well with this plugin, with the same configuration:

platform.ready().then(() => {
     if (window['ParsePushPlugin']) {
                ParsePushPlugin.register(function () {

                }, function () {

                });
                ParsePushPlugin.getInstallationId(function (id) {
                    // note that the javascript client has its own installation id,
                    // which is different from the device installation id.
                   alert("device installationId: " + id);
                }, function (e) {
                    alert('error');
                });

At config.xml:

    <preference name="ParseAppId" value="appid" />
    <preference name="ParseClientKey" value="clientid" />
    <preference name="ParseServerUrl" value="serverurl/" /> <-- Do not forget the backslash at the end
    <preference name="ParseGcmSenderId" value="gcmid" />
    <preference name="ParseAutoRegistration" value="true" />
...
<plugin name="parse-push-plugin" spec="https://github.com/taivo/parse-push-plugin" />

That's is all you need to get the plugin working. All my parse instances requires ClientKey.

I think these links may help you: https://github.com/taivo/parse-push-plugin/issues/52 https://github.com/taivo/parse-push-plugin/pull/57 https://github.com/taivo/parse-push-plugin/issues/79

cleever avatar Jul 18 '17 20:07 cleever

can you please tell me how to import into ts file

drmark1989 avatar Sep 12 '17 22:09 drmark1989

@drmark1989 if you are using ionic2, the only thing you need is add this line in your ts file:

declare var ParsePushPlugin: any;

The place where you should add is after the imports, like this:

import { AlertController } from 'ionic-angular'; import { LoadingController } from 'ionic-angular'; ...... declare var ParsePushPlugin: any;

That is it! Regards

marcelinne avatar Sep 13 '17 17:09 marcelinne

https://stackoverflow.com/questions/46297009/how-to-use-parse-push-notification-with-ionic-2-and-ionic-3

stevenballs avatar Sep 14 '17 03:09 stevenballs