js_55 js_55 - 5 months ago 20
iOS Question

I want to generate iOS push notification payload with badge and sound features, what classes and libraries can I use? [c#]

Apple Notification Class does not appear to have properties for badge and sound :

https://msdn.microsoft.com/en-us/library/azure/microsoft.azure.notificationhubs.applenotification.aspx

Is there some other class that could generate an iOS payload with sound and badge. I know I can do it manually by making strings, but would prefer to use a created class..

For example , this is undesired:

var alert = "{\"aps\":{\"alert\":\"" + pushNotificationMessage + "\",\"badge\":<input1>,\"sound\": <input2>"}}";


This would be better :

microsoftDefinedMethod( message = null, badge = false, sound = false);

Answer

You can use SendAppleNativeNotificationAsync method (or one of its overloads):

public Task<NotificationOutcome> SendAppleNativeNotificationAsync(string jsonPayload)

The jsonPayload parameter is the native iOS payload. Here's an example from the official documentation that looks like something you want to achieve:

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 9,
        "sound" : "bingbong.aiff"
    },
    "acme1" : "bar",
    "acme2" : 42
}

Also, there's an slightly different question on SO with an answer that has a code snippet potentially similar to what you'd write in your case.