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

ionic2 - installation not saved #107

Open
marcelinne opened this issue Jul 14, 2017 · 11 comments
Open

ionic2 - installation not saved #107

marcelinne opened this issue Jul 14, 2017 · 11 comments

Comments

@marcelinne
Copy link

marcelinne commented Jul 14, 2017

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

@cleever
Copy link

cleever commented Jul 17, 2017

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 cleever mentioned this issue Jul 17, 2017
@marcelinne
Copy link
Author

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
`

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

`

@cleever
Copy link

cleever commented Jul 17, 2017

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" />

@marcelinne
Copy link
Author

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.

@cleever
Copy link

cleever commented Jul 17, 2017

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" />

@marcelinne
Copy link
Author

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
Copy link
Author

marcelinne commented Jul 18, 2017

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

@cleever
Copy link

cleever commented Jul 18, 2017

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:
#52
#57
#79

@drmark1989
Copy link

can you please tell me how to import into ts file

@marcelinne
Copy link
Author

@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

@stevenballs
Copy link

stevenballs commented Sep 14, 2017

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

4 participants