iOS Push Notification custom format -
i'm new ios push notification domain. have tried basic push notification using following code , works perfectly. i'm using "using jdsoft.apple.apns.notifications;" accomplish this. here's code:
notification alertnotification = new notification(testdevicetoken); alertnotification.payload.alert.body = "hello world"; alertnotification.payload.sound = "default"; alertnotification.payload.badge = 1;
this gives output iphone in following structure:
{ aps = { alert = "hello world"; badge = 1; sound = default; }; }
i have got requirement add custom tag follows:
{ "aps": { "alert": "hello world", "sound": "default", "person": { "address": "this test address", "name": "first name", "number": "023232323233" } } }
i find difficult "person" inside "aps". know can add custom attribute using following code:
alertnotification.payload.addcustom("person", newtonsoft.json.jsonconvert.serializeobject(stat));
but above code not add withing "aps" tag. please tell me how can achieved?
you not allowed put custom tags inside aps tag. here's documentations says it:
providers can specify custom payload values outside apple-reserved aps namespace. custom values must use json structured , primitive types: dictionary (object), array, string, number, , boolean.
so in case should like:
{ "aps": { "alert": "hello world", "sound": "default" }, "person": { "address": "this test address", "name": "first name", "number": "023232323233" } }
therefore can read custom payload looking it's key in main json, rather in "aps":
nslog(@"%@",notification['person']['address']);
above output:
this test address
you find more custom payloads, along examples in apple docs.
regards, hristo
Comments
Post a Comment