adobkin / libcapn

A simple C Library for interact with the Apple Push Notification Service (APNs)
MIT License
100 stars 37 forks source link

Library does not send notification when apn_payload_add_custom_property_string is used. #1

Closed Lorune closed 11 years ago

Lorune commented 11 years ago

In the example on the documentation page replace the apn_payload_add_custom_property_int with apn_payload_add_custom_property_string and put in a string value, and the library stops sending messages.

[edit]

I recompiled the library with some print outs, it seems the string variable gets converted to a float somewhere along the way :

apn_payload_add_custom_property_string(payload_ctx, "string_var", "hoi", NULL);

Gives :

{"aps": {"sound": "default", "alert": "Let me know if you get this.", "badge": 10}, "string_var": 6.4416655778056372e-314}

[2nd Edit]

Seems the problem is in the payload construction :

if (payload_ctx->custom_properties && payload_ctx->__custom_properties_count) {
    for (i = 0; i < payload_ctx->__custom_properties_count; i++) {
        apn_payload_custom_property_ref property = *(payload_ctx->custom_properties + i);
        switch (property->value_type) {
            case APN_CUSTOM_PROPERTY_TYPE_BOOL:
                json_object_set_new(root, property->key, ((property->value.bool_value == 0) ? json_false() : json_true()));
                break;
            case APN_CUSTOM_PROPERTY_TYPE_NUMERIC:
                json_object_set_new(root, property->key, json_integer((json_int_t) property->value.numeric_value));
                break;
            case APN_CUSTOM_PROPERTY_TYPE_NULL:
                json_object_set_new(root, property->key, json_null());
                break;
            case APN_CUSTOM_PROPERTY_TYPE_STRING:
                json_object_set_new(root, property->key, json_string(property->value.string_value.value));
            case APN_CUSTOM_PROPERTY_TYPE_DOUBLE:
                json_object_set_new(root, property->key, json_real(property->value.double_value));
                break;
            case APN_CUSTOM_PROPERTY_TYPE_ARRAY:
            {
                for (array_i = 0; array_i < property->value.array_value.array_size; array_i++) {
                    json_array_append(array, json_string(*(property->value.array_value.array + array_i)));
                }
                json_object_set_new(root, property->key, array);
            }
                break;
        }
    }
}

APN_STRING case is missing the break, once added it will work again it seems.