Parse-SDK-Android icon indicating copy to clipboard operation
Parse-SDK-Android copied to clipboard

getCurrentInstallation().saveInBackground() Adding extra ID string in front

Open devcheetah opened this issue 10 years ago • 18 comments

When using ParseInstallation.getCurrentInstallation().saveInBackground(); it is adding in "|ID}#|:" to the device Token. This is causing issues with pushAdapters because it sends that extra bit of string when trying to use a third party push service. like pushwoosh.

For example

|ID|1|:es3c-xxxxxxxxxxxxx

I assume its the ID stored in mongodb. Can we get this extra bit removed?

devcheetah avatar May 20 '16 16:05 devcheetah

when I stepped through the code it seemed to be the registration token that's been given by GCM, not Parse

if you set a breakpoint in GcmRegistrar.handleRegistrationIntentAsync() (which handles the intent) you should be able to see it there

kassim avatar May 23 '16 10:05 kassim

The only way to get the push to work is remove |ID|#|. So should I not use getCurrentInstallation? Or should that function be handling this? Having to go into parse to remove that string for every new installation would be a pain.

devcheetah avatar May 23 '16 12:05 devcheetah

This is causing issues with Amazon SNS for us, the token has an invalid format and is therefore rejected.

Is the GCM token generated with a different structure now that Firebase has taken over?

jackdewhurst avatar May 26 '16 09:05 jackdewhurst

Ok it seems GcmRegistrar receives two tokens from GCM when currentInstallation.saveInBackground() is called the first time.

The first looks correct:

com.parse.GcmRegistrar: Received deviceToken <APA91bEUQe7Hss2yjK11gq1E5UHCTYJyA2nWEpDArJqalOCR_lbp0PvSWz8jRD4NjEAvXgWsHdokq0KyTuZLFYZv5xgg1Cry7fz3RsMrFSXOxoLPoZZjKEs1gaq_pBIKruDaDdtd> from GCM

Then immediately after this is logged with the ID prefix:

com.parse.GcmRegistrar: Received deviceToken <|ID|1|:ei7dEQ3kHI4:APA91bFiJDFr-FqhevPOiKvBaZNk4ftA5sHmVx4Erbxuvf_2JL8-uoXvc1GRUFpKCtuMClHKgeM2gW1xfTeejYG2aiIGLLBpgGNjPg_cmFUAFiC4lk5Rvp> from GCM.

jackdewhurst avatar May 26 '16 10:05 jackdewhurst

If anyone has a solution or temporary work around for this, that would help a lot. At this point I would have to create something to constantly parse out all the extra prefix stuff.

devcheetah avatar May 31 '16 13:05 devcheetah

Hi,

dealing with the same problem. @jackdewhurst : you're right and the 2 GCM id is different from the first one (after the |ID|1|:...: pattern.

I tried to modify the PushAdapterUtils.js (server side) using installation.deviceToken.replace(/\|ID\|1\|:[^:.]*:/,""); but with no luck for now.

I encounter this issue just after moving to play-services: 9+ if it helps.

patmelua avatar May 31 '16 16:05 patmelua

For now we've written a job to trim tokens up to the first colon server side.

So if a token begins with |ID|1|: we trim the prefix and re-save the installation object. Devices with trimmed tokens seem to receive notifications ok for now.

Not ideal though.

jackdewhurst avatar Jun 01 '16 15:06 jackdewhurst

@devcheetah

My current work around is have a new class that extends ParseInstallation in the same package ( so that i can access the protected member of ParseIntallation) and have a helper function to read the current installation and modifiy it if it is in wrong format

however, since we don't know when and we don't have callback when the GCM token is received (it is in the background), i call this helper everytime in my activity onCreate, it's not ideal solution, but at least I only save the installation when the format is wrong, hence it's not that bad...

Before I have this "hack" solution, I tried manually get the GCM token, but parse won't save though

odaeagle avatar Jun 03 '16 16:06 odaeagle

Any update on this guys?

firaskafri avatar Jun 12 '16 07:06 firaskafri

For the time being I made cloud code beforeSave to remove this and is working for now.

Parse.Cloud.beforeSave(Parse.Installation, function(request, response){ var id = request.object.get("deviceToken").replace("|ID|1|:",""); request.object.set("deviceToken",id); response.success(); });

devcheetah avatar Jun 13 '16 20:06 devcheetah

We have had the same problem, but in our case was a conflict with the gms plugin and firebase lib, so we removed:

apply plugin: 'com.google.gms.google-services'

and

compile 'com.google.firebase:firebase-core:9.0.2'

ID's are now correct and push notifications are working again

FireZenk avatar Jun 14 '16 15:06 FireZenk

I have the same issue with:

  • Parse SDK 1.13.1
  • Play Services GCM 9.2.0
  • Google Services 3.0.0

How can I solve it?

Thank you!

javichaques avatar Jun 30 '16 07:06 javichaques

Yep +1 on this! @devcheetah Are you still using your cloud beforeSave trigger?

PiXeL16 avatar Jul 05 '16 23:07 PiXeL16

I am using the beforeSave still.

devcheetah avatar Jul 06 '16 13:07 devcheetah

Thanks, @FireZenk fix worked for me. Looks like compile 'com.google.firebase:firebase-core:9.0.2' Fix the issue

👍

PiXeL16 avatar Jul 06 '16 17:07 PiXeL16

I have the same issue, but if I remove apply plugin: 'com.google.gms.google-services' the screen trackers are down ...

I used:

compile 'com.google.android.gms:play-services-gcm:9.2.1'
compile 'com.google.android.gms:play-services-analytics:9.2.1'

apply plugin: 'com.google.gms.google-services'

Any ideas how I can solve this issue?

gm4s avatar Jul 28 '16 09:07 gm4s

I am adding the relevant parts that works for me:

Root-level build.gradle

       dependencies {
       .....
        classpath 'com.google.gms:google-services:3.0.0'
       .....
    }

Module build.gradle

   dependencies {
    compile 'com.google.android.gms:play-services-gcm:9.2.0'
   }

I didn't need the apply plugin: 'com.google.gms.google-services' here.

Manifest.xml

        <!--GCM Sender ID was provided by the GCM Project information on developerconsole.google.com-->
        <meta-data android:name="com.parse.push.gcm_sender_id"
            android:value="id:YourGCMSenderID" />

PiXeL16 avatar Jul 29 '16 17:07 PiXeL16

We can close by upgrading to a later version of GCM right?

rogerhu avatar Mar 09 '17 08:03 rogerhu