Skip to content

Erro send push notification to IOS #333

@pedromramalho

Description

@pedromramalho

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();
 });

});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions