Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple Push Notification with Sending Custom Data

People also ask

How do I make custom push notifications?

1. Configure custom push notifications in the Dashboard. You can configure Helpshift to send the push notification message to a custom URL instead of through APNS (For iOS) and FCM/GCM (for Android). The first step to do so is for an Admin to set up a custom push notification.

Can push notifications be personalized?

Clearly, personalized push notifications can change the way you do business online. But according to a study, 70% of personalization experiences on an eCommerce website happen only when the user has logged into the account. But ideally, you'd want to offer a personalized experience even when they're not logged in.

Does Apple send push notifications?

Remote Notifications Communicate with Apple Push Notification service (APNs) and receive a unique device token that identifies your app. Use basic macOS command-line tools to send push notifications to Apple Push Notification service (APNs).


Regardless of the language and library you use, the push notification payload is a JSON payload:

{
    "aps": {
         "badge": 10,
         "alert": "Hello world!",
         "sound": "cat.caf"
    }
}

The aps token is the Apple APN data. You can add custom data to your payload as well:

{
    "aps": {
         "badge": 10,
         "alert": "Hello world!",
         "sound": "cat.caf"
    },
    "job_id": 1
}

When you receive the notification in the app, check for your param in the notification dictionary:

- (void)handleBackgroundNotification:(NSDictionary *)notification
{
    NSDictionary *aps = (NSDictionary *)[notification objectForKey:@"aps"];
    NSMutableString *alert = [NSMutableString stringWithString:@""];
    if ([aps objectForKey:@"alert"])
    {
        [alert appendString:(NSString *)[aps objectForKey:@"alert"]];
    }
    if ([notification objectForKey:@"job_id"])
    {
        // do something with job id
        int jobID = [[notification objectForKey:@"job_id"] intValue];
    }
}

Keep in mind that the total size of the payload is 256 bytes, and that includes, of course, your custom parameters. So you may have to (at risk of reducing readability) call your custom param "ji" instead of "job_id" to squeeze bytes.

All of this is documented in the Local and Push Notification Programming Guide in the iOS documentation. Definitely would recommend a read because it's more complex than it initially sounds (at least, that's what I thought).


Yes you can send custom data, check apns-php library for all push notification needs: