Closed jerone closed 5 years ago
Hi, thanks you! I will check it!
Hello! you may be able to fix it?
@KSemenenko commented on 10 Feb 2017, 11:34 CET:
Hello! you may be able to fix it?
Not really, I have no idea why this is happening.
Still having this issue. I think it's related to debugging our application. When testing a new feature, we run the app and then stop it through Visual Studio. Then the next time we debug the application it registers itself, without unregistering itself first, aldo we use UnregisterFromAzurePushNotification
to unregister first.
This is only an issue for Android, not iOS.
I think I got why this library generates duplicate registrations on Android. NOTE: I use the Azure Notification Hubs services, I don't implement my own management of Hubs registering procedure.
Basically, it relies on Android native GCM service (this is why asks you for "GoogleApiSenderId", if it used direct only Hubs, it would not need this parameter). Everytime a new REGISTRATION is performed (on Android):
InternalRegister()
HandleRegistration()
OnRegistered()
Now, what's wrong? Between 1-2-3 check the registrations list from Hubs (I used NotificationHubClient.GetAllRegistrationsAsync(0);
from my server): right after 1, you will see that all the duplicate registrations linked with your device have ALREADY their PNSHandle updated!
Running step 3 will anyway create a new record with (again, the same new PNS) and a new RegistrationId.
On Step 2, you can reuse your saved old PNSHandle to delete all Hubs registrations linked to that previous PNS. But wait.. it should not make sense since after Step 1 all Handles were updated in Hubs right? Wrong! It will actually delete your last Hubs registration, and leave all duplicates behind. So, what happened?
What is shown in NotificationHubClient.GetAllRegistrationsAsync(0);
for each Registrations is (as far as I understood) the canonicalID, which is the LAST PNSHandle released for that device. For some reason, when you ask Hubs to delete all my previous Registrations giving it my LAST PNSHandle.. it deletes nothing. In a way, you never told him to Register your device with that PNSHandle.. so nothing to Unregister. But it remembers if you ask him to Unregister with the previous PNSHandle.
By asking Hubs to UnregisterAll()
with the previous PNSHandle, I was able to stop creating duplicates even when never calling library's UnregisterFromAzurePushNotification()
.... but this is only a PARTIAL solution! Why?
What happens if I uninstall and reinstall application? I lose my previous PNSHandle. So, again, duplicate.
The complete solution requires you to use an ApplicationID and communicating with your own back-end. ApplicationID is your own way of identifying your device/registration. Client is not capable of removing registrations belonging previous installations. Read the "PNS handle, registration ID and application ID" paragraph from: https://dzimchuk.net/push-notification-flow-with-azure-notification-hubs/ Maybe there is a way of doing it with the new Hubs SDK, but as far as I can see there is no way of asking if a device was already registered... this is because PNSHandle is transient and will not be used as a device identifier.
BUT what I noticed is that, after the first App registration to Hubs, if you simply comment OnRegistered()
and OnUnregistered()
calls, the registration will keep always unique EVEN when App is uninstalled and reinstalled! This maked me think that the PNSHandle is somehow correlated to the device (since you find the PNSHandle automatically updated on Hubs.
The question would then be: how do I know if this is the first installation for this App?
I did not go yet deeper on the topic.
Lost a day figuring this out, hope it helps!
@fakkoweb Thank you so much! Thank you for your time! I think that together we can do it!
@KSemenenko Hi Konstantin, is there any change that you will fix this in near future? Because of this issue Android version of our app gets an exception: WindowsAzure.Messaging.NotificationHubResourceNotFoundException: Resource not found
when user log out from app and tries to log in again. As a workaround we just commented out call to UnregisterFromAzurePushNotification()
in app code, but we need a real fix to make this plugin works as intended.
Hello! I would be grateful for any help in this! @Mony25
@KSemenenko commented on 23 jun. 2017 14:26 CEST:
Hello! I would be grateful for any help in this! @Mony25
Are you still using this package? Can you reproduce the issues described here?
Hi, maybe it's time for remove GCM and replace it to something new?
@KSemenenko commented on 30 jun. 2017 07:52 CEST:
Hi, maybe it's time for remove GCM and replace it to something new?
Yes, please... https://github.com/KSemenenko/AzurePushNotificationsForXamarinForms/issues/5
Hi, any update on the issue ?
FYI, we moved to Visual Studio App Center. Their API implementation is really simple and stable. James Montemagno gives a good comparison: https://montemagno.com/push-notification-options-for-xamarin/
@jerone @SanjeevKarki It's good idea to use App Center.
GCM is not unregistering itself from Azure is when called by
CrossAzurePushNotifications.Current.UnregisterFromAzurePushNotification();
.I'm using it in an Xamarin.Forms application and the same code also executes for Apple (APNS), which I see unregistering.
Xamarin 4.2.2.11 (00fa5cc) Xamarin.Android 7.0.2.42 (501e63c) Xamarin.iOS 10.3.1.8 (7beaef4) Xamarin.Forms 2.3.3.180