1.效果展示介绍
iOS 10 以下支持设置标题 title ,设置后 title 值将取代通知栏上的应用名称:
iOS 10 及以上支持设置标题 title 和 subtitle,title 和 subtitle 自带加粗效果,无法取消,展示效果如下图:
2.官网推送传值介绍
选择推送通知 → 选择 iOS 目标平台 → 展开可选设置 → iOS 可选设置下有 title 和 subtitle 选择
3.push api推送传值介绍
IOS的alert字段可以设置String或者JSON Object,需要设置标题和子标题,需要以JSON Object的形式传入,具体可参考:
https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#notification
{
"notification" : {
"ios" : {
"alert" : {
"title" : "JPush Title", //可选设置
"subtitle" : "JPush Subtitle" , //可选设置
"body" : "JPush Body" //必填,否则通知将不展示,在不设置 title 和 subtitle 时直接对 alert 传值即可,不需要特地写 body 字段
},
"sound" : "sound.caf",
"badge" : 1,
"extras" : {
"news_id" : 134,
"my_key" : "a value"
}
}
}
}
4.代码示例
1、Java SDK
public static void testSendIosAlert() {
JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY);
IosAlert alert = IosAlert.newBuilder()
.setTitleAndBody("test alert", "subtitle", "test ios alert json")
.setActionLocKey("PLAY")
.build();
try {
PushResult result = jpushClient.sendIosNotificationWithAlias(alert, new HashMap<String, String>(), "alias1");
LOG.info("Got result - " + result);
} catch (APIConnectionException e) {
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Code: " + e.getErrorCode());
LOG.info("Error Message: " + e.getErrorMessage());
}
}
补充:
//设置IOS通知消息
.setNotification(Notification.newBuilder()
//设置ios通知消息
.addPlatformNotification(IosNotification.newBuilder()
//设置ios标题
.setAlert(IosAlert.newBuilder()
.setTitleAndBody("title", "subtitle", "test ios alert json")
.build()).build())
2、PHP SDK
try {
$response = $client->push()
->setPlatform(array('ios', 'android'))
->addRegistrationId($registration_id)
->setNotificationAlert('Hi, JPush')
->iosNotification(array(
'title' => 'title', //可选设置
'subtitle' => 'subtitle', //可选设置
'body' => 'body'//必填,否则通知栏不展示
),array(
'sound' => 'sound.caf',
'extras' => array(
'key' => 'value',
'jiguang'
),
))
->options(array(
// True 表示推送生产环境,False 表示要推送开发环境;如果不指定则默认为推送生产环境
'apns_production' => false,
))
->send();
print_r($response);
} catch (\JPush\Exceptions\APIConnectionException $e) {
// try something here
print $e;
} catch (\JPush\Exceptions\APIRequestException $e) {
// try something here
print $e;
}