Varis Darasirikul
Varis Darasirikul

Reputation: 3063

How to increase badge number from push notification using own php APNS server by swift?

Now I'm working on IOS app project by swift. So I need to increase badge number every time when the server push notification to the device. Right now it is always 1 badge no increasing.

This is my payload.

// Create the payload body
$body['aps'] = array(
    'alert' => $message,
    'sound' => 'default',
    'badge' => 1
    );
// Encode the payload as JSON
$payload = json_encode($body);
$messageId = $randomNotiId;

Thanks!

Upvotes: 2

Views: 2656

Answers (1)

Norolim
Norolim

Reputation: 956

You just need to save the badge number every time you push a notification and clear all if user sees them.

You need to upload value to the server when seen and then when you push a notification to that user you can retrieve how many notification he/she has and use that number + 1.

I think thats the best choice, but you can save the number with NSUserDefaults or something like that, but you will have a problem if the user remove the app and DLs it again.

Upvotes: 1

Related Questions