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

Erro send push notification to IOS #333

Open
pedromramalho opened this issue Dec 23, 2024 · 0 comments
Open

Erro send push notification to IOS #333

pedromramalho opened this issue Dec 23, 2024 · 0 comments

Comments

@pedromramalho
Copy link

Can some one help I have the same problem IOS14, and when i try the test in Azure Portal I get
apple | 6321218213637372908-5225854469778412245-3 | The Push Notification System handle for the registration is invalid
with this basic payload {"aps":{"alert":"Notification Hub test notification"}}, and the registration is removed from the hub

Is in Xamarin forms and the code for registration in AppDelegate are:

Hub.UnregisterAll(deviceToken, (unregisterError) =>
{
if (unregisterError != null)
{
Console.WriteLine("Error calling Unregister: {0}", unregisterError.ToString());
return;
}

 NSSet tags = new NSSet("xxxxxx"); // create tags if you want
 var expirationTime = DateTime.UtcNow.AddYears(1); // Set expiration time to one year from now

 var template = new Dictionary<string, string>
 {
     { "body", "{\"aps\":{\"alert\":\"$(message)\"}}" }
 };
 Hub.RegisterNative(deviceToken, tags, (errorCallback) =>
 {
     if (errorCallback != null)
     {
         Console.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
         return;
     }
     
 });
 Hub.RegisterTemplate(deviceToken, "defaultTemplate", template["body"], "defaultTemplate", tags, (registerError) =>
 {
     if (registerError != null)
     {
         Console.WriteLine("RegisterTemplateAsync error: " + registerError.ToString());
         return;
     }

     var tokenStringBase64 = deviceToken.Description;
     byte[] bytes = deviceToken.ToArray<byte>();
     string[] hexArray = bytes.Select(b => b.ToString("x2")).ToArray();
     var DeviceToken = string.Join(string.Empty, hexArray);

     App.Current.Properties["idregistration"] = Hub.Handle.ToString();
     App.Current.Properties["tokenNoti"] = DeviceToken.ToString();
     App.Current.SavePropertiesAsync().GetAwaiter();
 });

});

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

1 participant