phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

InvalidRegistration Error , please help.. #563

Closed robertrutenge closed 6 years ago

robertrutenge commented 8 years ago

Hi , i have done all the steps in registering and connecting APN to GCM service , i have a provisional profile , created certificate as well as uploading p12 file to GCM , but still i get {"multicast_id":5831927541084427787,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]} error when i try to tegister , i have researched for hours now but could not get the solution . On Console the registration token is generated successfully , and when i try send push notification with APN Tester Free i can receive notifications. I have no idea what is wrong to this point , please help...

macdonst commented 8 years ago

@Bobin56 what does the registration ID you are trying to send to look like?

robertrutenge commented 8 years ago

@macdonst , This is my registration id part of the code $registrationIds = array("e975d224df18445bd70301840a3a54f82b745d12378651223d7488cb56db9d04" ); But in my xcode it logs it in a format of <e975d224 df18445b d7030184 0a3a54f8 2b745d12 37865122 3d7488cb 56db9d04>and even with the APN Test free i put the code with <> . Thanks again .

macdonst commented 8 years ago

@Bobin56 that is not a GCM ID, that is an APNS ID. It should be in the format of XXXXX:YYYYYYYYYYYY. It is the : between the two values that is the key. So if you try to send a GCM push to the ID you posted it won't work and that's proper.

What are you passing into init?

robertrutenge commented 8 years ago
 var push = PushNotification.init({
            "android": {
                "senderID": "5061481XXXXX"
            },
            "ios": {
            "senderID": "5061481XXXXX",
            "gcmSandbox": "true",
            "alert": "true",
            "badge": "true",
            "sound": "true"
            },
            "windows": {}
        });

``

By the way , i am able to receive android notification with the same codes , here is my PHP

// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'AIzaSyC4VZx0E3qubfM3XD1mMCl4VBXXXXXXXXXX' );

$registrationIds = array("e975d224df18445bd70301840a3a54f82b745d12378651223d7488cb56db9d04" );

// prep the bundle
$msg = array
(
    'message'       => 'here is a message. message',
    'title'         => 'This is a title. title',
    'subtitle'      => 'This is a subtitle. subtitle',
    'tickerText'    => 'Ticker text here...Ticker text here...Ticker text here',
    'vibrate'   => 1,
    'sound'     => 1
);

$fields = array
(
    'registration_ids'  => $registrationIds,
    'data'              => $msg
);

$headers = array
(
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );

echo $result;
macdonst commented 8 years ago

@Bobin56 the init looks correct but instead of reading the console in Xcode what does your registration event handler report? I'm betting that you are reading the wrong console log in Xcode.

robertrutenge commented 8 years ago

@macdonst , I don't have access to the device right now , but running on an emulator , it brings these logs , while normally with an actual device the registration is succesful .

2016-02-02 18:00:49.087 BBG Tanzania[495:4656] active

2016-02-02 18:00:49.088 BBG Tanzania[495:4656] PushPlugin skip clear badge

2016-02-02 18:00:49.194 BBG Tanzania[495:4656] Resetting plugins due to page load.

2016-02-02 18:00:49.720 BBG Tanzania[495:4656] Finished load of: file:///Users/apple/Library/Developer/CoreSimulator/Devices/5F2EB57E-D1E9-48F3-BDBC-1DE9247A29C1/data/Containers/Bundle/Application/ED329D7B-BC16-41B9-B620-07BAFF9FF344/BBG%20Tanzania.app/www/index.html

2016-02-02 18:00:50.176 BBG Tanzania[495:4784] Push Plugin register called

2016-02-02 18:00:50.176 BBG Tanzania[495:4784] PushPlugin.register: setting badge to false

2016-02-02 18:00:50.177 BBG Tanzania[495:4784] PushPlugin.register: clear badge is set to 0

2016-02-02 18:00:50.177 BBG Tanzania[495:4784] PushPlugin.register: better button setup

2016-02-02 18:00:50.178 BBG Tanzania[495:4784] GCM Sender ID (null)

2016-02-02 18:00:50.179 BBG Tanzania[495:4784] Using APNS Notification

2016-02-02 18:00:50.184 BBG Tanzania[495:4656] Push Plugin register failed

Is this the wrong log ? i will send you the actual logs using the device later when i get access . Thanks again for helping :-)

macdonst commented 8 years ago

@Bobin56 you can't test on a simulator.

MerlinMags commented 8 years ago

I am having the exact same problem as @Bobin56 when testing on a real iPhone/iPad. The plugin returns a 64 char string (looks like lowercase Hex). I can use this token with an APNS testing tool, successfully, which proves my certificates are correct. GCM gives the "InvalidRegistration" error, which @macdonst explained (above) is because it is an APNS token, not a GCM token.

I'm using Phonegap Build, with this in my config.xml file... gap:plugin name="phonegap-plugin-push" source="npm" version="1.5.3"

On Android, the exact same Javascript code as used on iOS gives me a 162 char alphanumeric string for the token, which GCM is happy to send messages to. Here's a snippet of the registration code...

var sProjectNumber = '390035978459'; //GCM
var oSettings = { "android": {"senderID": sProjectNumber}, "ios": {"senderID": sProjectNumber, "gcmSandbox": "true", "alert": "true", "badge": "false", "sound": "true"}, "windows": {} };
var push = PushNotification.init(oSettings);
push.on('registration', function(data) {
   sNotificationToken = data.registrationId;
   alert('token length=' + sNotificationToken.length)' //is 64 on iOS, 162 in Android

I guess I need to change the 64 char APNS token for a proper GCM token...but how?! I've been Googling for two whole days on this, so I would be immensely grateful for any advice. Thanks!

andres-torres-marroquin commented 8 years ago

I have just run into this, since 28 Jan 2016 it started to register to my backend a 64 chars ids only on iOS.

edit: I forgot to mention that it was working properly before that date.

andres-torres-marroquin commented 8 years ago

@macdonst you asked for a log, you got it!

2016-02-02 14:26:22.069 Buckets[7022:2883696] PushPlugin skip clear badge
2016-02-02 14:26:25.980 Buckets[7022:2883791] Push Plugin register called
2016-02-02 14:26:25.982 Buckets[7022:2883791] PushPlugin.register: setting badge to true
2016-02-02 14:26:25.984 Buckets[7022:2883791] PushPlugin.register: clear badge is set to 1
2016-02-02 14:26:27.257 Buckets[7022:2883696] Push Plugin register success: <be5b2358 6ac4df6d c3fb2b83 49bda5eb 9a67f9f8 d6f696b1 261d6bbe 891cd55f>
andres-torres-marroquin commented 8 years ago

@Bobin56 are you using cordova-plugin-googleplus ? After I uninstalled it everything started to work.

andres-torres-marroquin commented 8 years ago

Looks like I was using version 1.4.5, the current version 1.5.3 works fine. It is a bit related to phonegap/phonegap-plugin-push#449, I tried downgrading to phonegap-plugin-push@1.4.5 to fix the build conflicts with cordova-plugin-googleplus, and yeah, I fixed them but the notifications stopped working. If someone needs more details about this, please let me know.

robertrutenge commented 8 years ago

@andres-torres-marroquin , i dont use cordova-plugin-googleplus , glad it worked on your end , @macdonst ,i am using version 1.5.3 and here is my log on an actual device , please help .

2016-02-03 09:50:59.058 BBG Tanzania[874:907] Apache Cordova native platform version 3.9.2 is starting.

2016-02-03 09:50:59.078 BBG Tanzania[874:907] Multi-tasking -> Device: YES, App: YES

2016-02-03 09:50:59.095 BBG Tanzania[874:907] Unlimited access to network resources

2016-02-03 09:50:59.116 BBG Tanzania[874:907] 

Started backup to iCloud! Please be careful.

Your application might be rejected by Apple if you store too much data.

For more information please read "iOS Data Storage Guidelines" at:

https://developer.apple.com/icloud/documentation/data-storage/

To disable web storage backup to iCloud, set the BackupWebStorage preference to "local" in the Cordova config.xml file

2016-02-03 09:50:59.346 BBG Tanzania[874:907] [CDVTimer][splashscreen] 154.404998ms

2016-02-03 09:50:59.348 BBG Tanzania[874:907] [CDVTimer][TotalPluginStartup] 156.488001ms

2016-02-03 09:50:59.378 BBG Tanzania[874:907] active

2016-02-03 09:50:59.382 BBG Tanzania[874:907] PushPlugin skip clear badge

2016-02-03 09:51:00.020 BBG Tanzania[874:907] Resetting plugins due to page load.

2016-02-03 09:51:02.929 BBG Tanzania[874:907] Finished load of: file:///var/mobile/Applications/0EC593A3-33C5-4414-98B5-189FEC551D3B/BBG%20Tanzania.app/www/index.html#/var/mobile/Applications/0EC593A3-33C5-4414-98B5-189FEC551D3B/BBG%20Tanzania.app/www/home.html

2016-02-03 09:51:03.402 BBG Tanzania[874:1803] Push Plugin register called

2016-02-03 09:51:03.407 BBG Tanzania[874:1803] PushPlugin.register: setting badge to false

2016-02-03 09:51:03.409 BBG Tanzania[874:1803] PushPlugin.register: clear badge is set to 0

2016-02-03 09:51:03.410 BBG Tanzania[874:1803] PushPlugin.register: better button setup

2016-02-03 09:51:03.440 BBG Tanzania[874:907] Push Plugin register success: <e975d224 df18445b d7030184 0a3a54f8 2b745d12 37865122 3d7488cb 56db9d04>

2016-02-03 09:51:03.447 BBG Tanzania[874:1803] GCM Sender ID (null)

2016-02-03 09:51:03.457 BBG Tanzania[874:1803] Using APNS Notification
MerlinMags commented 8 years ago

I'm using 1.5.3 and still getting the problem. (I tried versions 1.5.1 and 1.5.2 as well, but they acted the same.)

macdonst commented 8 years ago

@Bobin56 double check your code as these lines:

2016-02-03 09:51:03.440 BBG Tanzania[874:907] Push Plugin register success: <e975d224 df18445b d7030184 0a3a54f8 2b745d12 37865122 3d7488cb 56db9d04>
2016-02-03 09:51:03.447 BBG Tanzania[874:1803] GCM Sender ID (null)
2016-02-03 09:51:03.457 BBG Tanzania[874:1803] Using APNS Notification

indicate the plugin is not getting your GCM sender ID.

robertrutenge commented 8 years ago

@macdonst , can you please suggest the reason as to why this is happening , as you can see my init code , i can't see what's wrong here...

var push = PushNotification.init({
            "android": {
                "senderID": "5061481XXXXX"
            },
            "ios": {
            "senderID": "5061481XXXXX",
            "gcmSandbox": "true",
            "alert": "true",
            "badge": "true",
            "sound": "true"
            },
            "windows": {}
        });
MerlinMags commented 8 years ago

I'm getting exactly the same as @Bobin56 and I don't think I can see anything wrong with the call to init:

var sProjectNumber = '3900XXXX8459'; var oSettings = { "android": {"senderID": sProjectNumber}, "ios": {"senderID": sProjectNumber, "gcmSandbox": "true", "alert": "true", "badge": "false", "sound": "true"}, "windows": {} };

Error404j commented 8 years ago

I am using phonegap build and I am having trouble as well. When I use phonegap-plugin-push 1.4.5 I get an APN registration id. When I use phonegap-plugin-push 1.5.3 it doesn't register on iOS. Both ask the user permission to send notifications. Android works with both versions.

var settings = {
  android: {
    senderID: MyApp.db.sender_id,
  },
  ios:{
    senderID: MyApp.db.sender_id,
    gcmSandBox: "true",
    alert: "true",
    badge: "true",
    sound: "true",
    vibration: "true",
  },
  windows: {},
}
var push = PushNotification.init(settings);
MerlinMags commented 8 years ago

What you describe with 1.4.5 under iOS, is correct; it only gives an APNS token. The ability to use GCM with iOS was only added in 1.5.0 - see bottom of https://github.com/phonegap/phonegap-plugin-push/pull/282 (However, that does make three of us having iOS issues with 1.5.3 now.)

Error404j commented 8 years ago

Well I did have a configuration issue on my side (failed to upload the p12 to google). I have since found that screen and uploaded it. I am now getting an gcm style registration id. I am not however getting notifications on iOS, still only getting them on android.

robertrutenge commented 8 years ago

@macdonst . i don't know what happened but when i run the app today on xcode , sender ID was returned and the sandbox log was generated , but still i get invalidRegistration , here is my log

success: <e975d224 df18445b d7030184 0a3a54f8 2b745d12 37865122 3d7488cb 56db9d04>

2016-02-08 10:40:57.981 BBG Tanzania[315:1703] GCM Sender ID 506148111438

2016-02-08 10:40:57.984 BBG Tanzania[315:1703] Using GCM Notification

2016-02-08 10:40:57.987 BBG Tanzania[315:1703] Using GCM Sandbox

purgeIdleCellConnections: found one to purge conn = 0x208a3060
MerlinMags commented 8 years ago

@Error404j did you have an incorrect .P12 lodged with Google previously then? Or none at all? I'm curious if this will solve my situation too.

tonholis commented 8 years ago

Did anyone solve this issue? I'm facing the same problem on iOS. Everything is working fine with Android.

But on iOS I have a failure when I send a message.

{ multicast_id: 7697720705401116000,
  success: 1, <android>
  failure: 1, <ios>
  canonical_ids: 0,
  results: 
   [ { error: 'InvalidRegistration' },
     { message_id: '0:1457125139093161%a2e5e414f9fd7ecd' } ] 
}

On Xcode I have this output:

2016-03-04 17:44:48.459 myapp[2374:1703] Push Plugin register called
2016-03-04 17:44:48.464 myapp[2374:1703] PushPlugin.register: setting badge to true
2016-03-04 17:44:48.474 myapp[2374:1703] PushPlugin.register: clear badge is set to 1
2016-03-04 17:44:48.480 myapp[2374:1703] PushPlugin.register: better button setup
2016-03-04 17:44:48.498 myapp[2374:907] Push Plugin register success: <0be251d0 5f3aa82a f197e278 49337936 1ada2a20 286babd4 356325e8 eb29f64b>
2016-03-04 17:44:48.559 myapp[2374:1703] GCM Sender ID 863466799999
2016-03-04 17:44:48.569 myapp[2374:1703] Using GCM Notification
2016-03-04 17:44:48.577 myapp[2374:1703] Using GCM Sandbox
MerlinMags commented 8 years ago

I finally got my GCM tokens registering correctly, after making my eyes ache checking every step of my Apple certification process very carefully. Once the newly-compiled-with-new-certificate was live in the App Store, then the tokens being sent to me by various iOS apps out in the wild were all 150 chars long. (Previously they were all 64 chars long for iOS devices, so the certificates I had passed to Google must have been wrong.)

I still haven't been able to send a notification out though. I get a successful {"message_id":5211790101863015410} back from the GCM http call, but still no beeps from my iPhone...

sunojvijayan commented 8 years ago

Hi Any update on this issue?

clembo590 commented 8 years ago

any news? I am not using phonegap build. I think I opened a duplicate:

833

tahoura commented 8 years ago

I change my GCM ID but as a result i have a blank page without json.

ef33zy commented 8 years ago

@Bobin56 just as an FYI, in your PHP file, change data to notification as below, to recieve notification on both iOS & Android $fields = array ( 'registration_ids' => $registrationIds, 'data' => $msg );

to:

$fields = array ( 'registration_ids' => $registrationIds, 'notification' => $msg );

fredgalvao commented 8 years ago

Wrong, @ef33zy + @Bobin56 , Android needs the payload to be in the data field, while iOS needs it to be in the notification field. You need to send a different payload to each platform. That may change with 2.0.0 with FCM support, but for now that's how it works. If you send a {notification:...} for both Android and iOS, this plugin will be unable to provide extra functionality on Android and most probably won't work properly.

ef33zy commented 8 years ago

@fredgalvao You are correct.... I've just experienced that. Using just the notification field causes Android to behave like iOS (i.e. no inbox stacking, no recognition of the phone sound settings e.t.c).

I've used an if{OS=Android use "data"}, else{use "notification"} in my PHP to resolve this.

Thanks for that. What will Windows use?

fredgalvao commented 8 years ago

I can't answer that about the windows platform.

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

lock[bot] commented 6 years ago

This thread has been automatically locked.