I'm getting a crash when the app is open and it receives a push notification.
[PFPush handlePush:userInfo];
the JSON is a simple alert: title, body and one custom field that's a hex number.
userInfo:
{
aps = {
alert = {
body = "Test Body";
title = "Test Title";
};
};
url = "miner://item/5528c5aeaacfce1fd2d527dd";
}
Just checked your sample code and you're right: this kind of string messages are crashing while handled by PFPush handlePush:
The reason why this is happening: The Parse supports iOS and Android PushNotification services at the same time, which means it cannot use any service-specific format in the general JSON string.
iOS uses these kind of formats:
{
"aps" : {
"alert" : {
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
"badge" : 5,
},
"acme1" : "bar",
"acme2" : [ "bang", "whiz" ]
}
And Android
"data": {
"title": "Push Title",
"message": "Push message for Android",
"customData": "Custom data for Android"
}
In Parse, you need to use a different format type like
{
"alert": "Tune in for the World Series, tonight at 8pm EDT",
"sound": "chime",
"title": "Baseball News"
}
In an iOS app, this will be the userInfo object from the JSON string above:
{
aps = {
alert = "Tune in for the World Series, tonight at 8pm EDT";
sound = chime;
};
title = "Baseball News";
}
In this userInfo, the alert is an NSString instead of an NSDictionary. When the Parse SDK tries to process that, it sends a length message to the instance - which causes the crash.
Sources: https://www.parse.com/questions/json-format-to-send-notification-from-parse https://parse.com/questions/json-push-notification-format-for-web-console-for-android-and-ios
More example: https://parse.com/docs/rest/guide/#push-notifications-sending-pushes