3

I am trying to send a json format which doesn't have an "alert" attribute. The thing is, when I try to remove the alert attribute, the notification won't appear. Is there any way I can handle this? Thanks in advance

P.S I've tried to use action, however it still doesn't show up (I think this is only possible in android)

asked Mar 10, 2014 at 7:19
0

1 Answer 1

2

Yes, you can do it. It is possible to send a push notification without an alert. You can even register your application just to badge notifications, in which case the provider server won't even be able to send alerts or sounds.

The Notification Payload

Each push notification carries with it a payload. The payload specifies how users are to be alerted to the data waiting to be downloaded to the client application. The maximum size allowed for a notification payload is 256 bytes; Apple Push Notification Service refuses any notification that exceeds this limit. Remember that delivery of notifications is "best effort" and is not guaranteed.

For each notification, providers must compose a JSON dictionary object that strictly adheres to RFC 4627. This dictionary must contain another dictionary identified by the key aps. The aps dictionary contains one or more properties that specify the following actions:

An alert message to display to the user

A number to badge the application icon with

A sound to play

Note that it says one or more of the properties. The alert property is optional. You can even send a notification with an empty aps dictionary (i.e. send only custom properties).

The following example shows an empty aps dictionary; because the badge property is missing, any current badge number shown on the application icon is removed. The acme2 custom property is an array of two integers.

{
"aps" : {
},
"acme2" : [ 5, 8 ]
}

The only alert the user will see it the alert that asks him/her whether to allow push notifications. That alert will only be displayed the first time the app is launched after installation.

In the below example you register to non alert notifications (badges and sounds only) :

Registering for remote notifications

- (void)applicationDidFinishLaunching:(UIApplication *)app {
 // other setup tasks here....
 [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}
// Delegation methods
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
const void *devTokenBytes = [devToken bytes];
self.registered = YES;
[self sendProviderDeviceToken:devTokenBytes]; // custom method
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSLog(@"Error in registration. Error: %@", err);
}

Hope this will help you.

answered Mar 10, 2014 at 7:30
Sign up to request clarification or add additional context in comments.

6 Comments

very clear info thank you. Although once the "alert" attribute was taken out from the json. The instance that was sent to the device will not be able to prompt on the notification center?
You welcome, kindly explain your scenario what functionality you exactly want?
Actually I already made a format for sending push to android, see sample below: { "action": "com.sample.pAction", "header": "My Title", "letter": "My Message" } However, I may not be able to use this format, since in ios it might need an "alert" to be able to render in the pull down notification area in ios.
You can also do this by sending alert atribute with empty string as: { aps = { "content-available" = 1; "alert" = ""; }; }
Kindly also check this link may it will help you: stackoverflow.com/questions/19239737/…
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.