taivo / parse-push-plugin

Push notification plugin for Cordova/Phonegap/ionic on Parse platform
118 stars 102 forks source link

Android doesn't register device tokens #119

Open khactam opened 6 years ago

khactam commented 6 years ago

Im using the version 1.0.8 and device registered a new Installation object fine but there is not device token has been saved in the object. The version 1.0.7 works fine but not the 1.0.8. What I want to use the version 1.0.8 is the silent notification (when I use 1.0.7, android gets the empty notification)

screen shot 2018-05-15 at 13 01 11

ionic: 3.20.0 cordova: 8.0.0

I use parse-server and it works fine until now.

My implement:

app.js

if(window.ParsePushPlugin){
      ParsePushPlugin.getInstallationId(function(id) {
          console.log("device installationId: " + id);
      }, function(e) {
          alert('error');
      });
}

config.xml

<preference name="ParseAppId" value="gijfdguo........." />
<preference name="ParseServerUrl" value="http://......../parse/" />
<preference name="ParseGcmSenderId" value="1........" />
taivo commented 6 years ago

Hi @khactam , would you be able to help figure out what caused the loss of that functionality from the last version bump? And submit a PR. I don't currently have the setup to debug this quickly.

khactam commented 6 years ago
05-15 17:50:20.381 1169-13676/? I/ChromeSync: [Sync,SyncIntentOperation] Handling the intent: Intent { act=com.google.android.gms.chromesync.SCHEDULED_SYNC cat=[targeted_intent_op_prefix:.chromesync.sync.SyncIntentOperation] dat=content://com.google.android.gms.chromesync.sync.ChimeraSyncReceiverService/109125016589231836921 flg=0x4 cmp=com.google.android.gms/.chimera.GmsIntentOperationService launchParam=MultiScreenLaunchParams { mDisplayId=0 mBaseDisplayId=0 mFlags=0 } (has extras) }.
05-15 17:50:20.502 4333-4365/? E/Auth: [GoogleAccountDataServiceImpl] getToken() -> BAD_AUTHENTICATION. Account: <ELLIDED:1264340651>, App: com.google.android.gms, Service: oauth2:https://www.googleapis.com/auth/login_manager
    fzk: Long live credential not available.
        at fzl.b(:com.google.android.gms@12673021@12.6.73 (040306-194189626):20)
        at fzl.a(:com.google.android.gms@12673021@12.6.73 (040306-194189626):50)
        at fxv.a(:com.google.android.gms@12673021@12.6.73 (040306-194189626):38)
        at hox.a(:com.google.android.gms@12673021@12.6.73 (040306-194189626):8)
        at hox.a(:com.google.android.gms@12673021@12.6.73 (040306-194189626):189)
        at hnx.a(:com.google.android.gms@12673021@12.6.73 (040306-194189626):2)
        at hnu.a(:com.google.android.gms@12673021@12.6.73 (040306-194189626):17)
        at hnu.a(:com.google.android.gms@12673021@12.6.73 (040306-194189626):6)
        at cyb.a(:com.google.android.gms@12673021@12.6.73 (040306-194189626):25)
        at cyb.a(:com.google.android.gms@12673021@12.6.73 (040306-194189626):82)
        at cyb.onTransact(:com.google.android.gms@12673021@12.6.73 (040306-194189626):8)
        at android.os.Binder.transact(Binder.java:507)
        at dah.onTransact(:com.google.android.gms@12673021@12.6.73 (040306-194189626):3)
        at android.os.Binder.execTransact(Binder.java:573)
05-15 17:50:20.502 4333-4365/? W/Auth: [GetToken] GetToken failed with status code: BadAuthentication

And here from the terminal

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'get' of null
    at module.exports (/Users/... 1/Documents/Tam/ionic-v1.3.1/../../plugins/parse-push-plugin/scripts/afterAndroidPrepare.js:15:99)
    at runScriptViaModuleLoader (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:188:18)
    at runScript (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:164:16)
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:132:20
    at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:787:54)
    at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:816:30)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:816:13)
    at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:624:44
    at runSingle (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:137:13)
    at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:125:13)
(node:32312) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:32312) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Not pretty sure if this could be useful

khactam commented 6 years ago

I found the problem. It's here in the afterAndroidPrepare.js.

 var parsePushNotificationIcon = configXml.data.find('preference[@name="ParseNotificationIcon"]').get('value');
  if (!!parsePushNotificationIcon) {
    // add to AndroidManifest.xml
    var manifestPushNotificationIconNode = applicationNode.find('meta-data[@android:name="com.parse.push.notification_icon"]');

    if (!manifestPushNotificationIconNode) {
      manifestPushNotificationIconNode = new ET.Element('meta-data', { 'android:name': 'com.parse.push.notification_icon' });
      applicationNode.append(manifestPushNotificationIconNode);
    }
    manifestPushNotificationIconNode.set('android:resource', '@drawable/' + parsePushNotificationIcon);

    // COPY ICON
    // create target path
    var iconTargetPath = path.join(context.opts.projectRoot, 'platforms', 'android', 'res', 'drawable');
    try {
      fs.mkdirSync(iconTargetPath);
    } catch (err) {
      // Directory already exists
    }

    // copy icon to android folder
    fs
      .createReadStream(path.join(context.opts.projectRoot, 'resources', parsePushNotificationIcon + '.png'))
      .pipe(fs.createWriteStream(path.join(iconTargetPath, parsePushNotificationIcon + '.png')));
  }

Just after I remove this (because I dont have the icon so it cant prepare perfectly. I put 1 condition there and everything is fine.

taivo commented 6 years ago

@khactam thanks for figuring out the problem. Could you help by submitting a pull request?

saisreeharsha commented 5 years ago

I found the problem. It's here in the afterAndroidPrepare.js.

 var parsePushNotificationIcon = configXml.data.find('preference[@name="ParseNotificationIcon"]').get('value');
  if (!!parsePushNotificationIcon) {
    // add to AndroidManifest.xml
    var manifestPushNotificationIconNode = applicationNode.find('meta-data[@android:name="com.parse.push.notification_icon"]');

    if (!manifestPushNotificationIconNode) {
      manifestPushNotificationIconNode = new ET.Element('meta-data', { 'android:name': 'com.parse.push.notification_icon' });
      applicationNode.append(manifestPushNotificationIconNode);
    }
    manifestPushNotificationIconNode.set('android:resource', '@drawable/' + parsePushNotificationIcon);

    // COPY ICON
    // create target path
    var iconTargetPath = path.join(context.opts.projectRoot, 'platforms', 'android', 'res', 'drawable');
    try {
      fs.mkdirSync(iconTargetPath);
    } catch (err) {
      // Directory already exists
    }

    // copy icon to android folder
    fs
      .createReadStream(path.join(context.opts.projectRoot, 'resources', parsePushNotificationIcon + '.png'))
      .pipe(fs.createWriteStream(path.join(iconTargetPath, parsePushNotificationIcon + '.png')));
  }

Just after I remove this (because I dont have the icon so it cant prepare perfectly. I put 1 condition there and everything is fine.

@khactam Where do i find this file named "afterAndroidPrepare.js" ???

budda commented 11 months ago

afterAndroidPrepare.js

@khactam Where do i find this file named "afterAndroidPrepare.js" ???

It's in the scripts folder

https://github.com/taivo/parse-push-plugin/blob/5b616c0ce2993a7104fee7833481b91102695b12/scripts/afterAndroidPrepare.js#L15