Skip to content

Commit d59aaef

Browse files
author
Helperhaps
committed
support ios10 features
1 parent f2bde45 commit d59aaef

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

doc/api.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ $push->setNotificationAlert('alert');
7676

7777
```php
7878
// iosNotification($alert = '', array $notification = array())
79-
// 数组 $notification 的键支持 'sound', 'badge', 'content-available', 'category', 'extras' 中的一个或多个
79+
// 数组 $notification 的键支持 'sound', 'badge', 'content-available', 'mutable-available', category', 'extras' 中的一个或多个
8080

8181
// 调用示例
8282
$push->iosNotification();
@@ -96,10 +96,11 @@ $push->iosNotification('hello', [
9696

9797
| 参数 | 说明 |
9898
| --- | --- |
99-
| alert |表示通知内容,会覆盖上级统一指定的 alert 信息;默认内容可以为空字符串,表示不展示到通知栏 |
99+
| alert |表示通知内容,会覆盖上级统一指定的 alert 信息;默认内容可以为空字符串,表示不展示到通知栏, 支持字符串和数组两种形式 |
100100
| sound | 表示通知提示声音,默认填充为空字符串 |
101101
| badge | 表示应用角标,把角标数字改为指定的数字;为 0 表示清除,支持 '+1','-1' 这样的字符串,表示在原有的 badge 基础上进行增减,默认填充为 '+1' |
102-
| available | 表示推送唤醒,仅接受 true 表示为 Background Remote Notification,若不填默认表示普通的 Remote Notification |
102+
| content-available | 表示推送唤醒,仅接受 true 表示为 Background Remote Notification,若不填默认表示普通的 Remote Notification |
103+
| mutable-available | 表示通知扩展, 仅接受 true 表示支持 iOS10 的 UNNotificationServiceExtension, 若不填默认表示普通的 Remote Notification |
103104
| category | IOS8才支持。设置 APNs payload 中的 'category' 字段值 |
104105
| extras | 表示扩展字段,接受一个数组,自定义 Key/value 信息以供业务使用 |
105106

examples/push_example.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
'sound' => 'sound.caf',
4141
// 'badge' => '+1',
4242
// 'content-available' => true,
43+
// 'mutable-available' => true,
4344
'category' => 'jiguang',
4445
'extras' => array(
4546
'key' => 'value',

src/JPush/PushPayload.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ private function generateSendno() {
356356

357357
# new methods
358358
public function iosNotification($alert = '', array $notification = array()) {
359-
# $required_keys = array('sound', 'badge', 'content-available', 'category', 'extras');
359+
# $required_keys = array('sound', 'badge', 'content-available', 'mutable-available', category', 'extras');
360360
$ios = array();
361-
$ios['alert'] = is_string($alert) ? $alert : '';
361+
$ios['alert'] = (is_string($alert) || is_array($alert)) ? $alert : '';
362362
if (!empty($notification)) {
363363
if (isset($notification['sound']) && is_string($notification['sound'])) {
364364
$ios['sound'] = $notification['sound'];
@@ -369,6 +369,9 @@ public function iosNotification($alert = '', array $notification = array()) {
369369
if (isset($notification['content-available']) && is_bool($notification['content-available']) && $notification['content-available']) {
370370
$ios['content-available'] = $notification['content-available'];
371371
}
372+
if (isset($notification['mutable-available']) && is_bool($notification['mutable-available']) && $notification['mutable-available']) {
373+
$ios['mutable-available'] = $notification['mutable-available'];
374+
}
372375
if (isset($notification['category']) && is_string($notification['category'])) {
373376
$ios['category'] = $notification['category'];
374377
}

tests/JPush/PushPayloadTest.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,14 @@ public function testIosNotification() {
139139
}
140140
public function testIosNotificationWithArray() {
141141
$payload = $this->payload;
142+
$alert_array = array(
143+
'alert_k1' => 'alert_v1',
144+
'alert_k2' => 'alert_v2',
145+
'alert_k3' => 'alert_v3',
146+
'alert_k4' => 'alert_v4'
147+
);
142148
$array = array(
143-
'sound' => 'hello jpush',
149+
'sound' => 'jpush.caf',
144150
'badge' => 2,
145151
'content-available' => true,
146152
'category' => 'jiguang',
@@ -150,8 +156,9 @@ public function testIosNotificationWithArray() {
150156
),
151157
'invalid_key' => 'invalid_value'
152158
);
153-
$result = $payload->iosNotification('', $array)->build();
159+
$result = $payload->iosNotification($alert_array, $array)->build();
154160
$ios = $result['notification']['ios'];
161+
$this->assertTrue(is_array($ios['alert']));
155162
$this->assertEquals(6, count($ios));
156163
$this->assertFalse(array_key_exists('invalid_key', $ios));
157164
}
@@ -244,10 +251,15 @@ public function testOptions() {
244251

245252
public function testPushToAll() {
246253
$payload = $this->payload;
247-
248254
$platform = array('ios', 'android', 'blackberry');
255+
$ios_alert = array(
256+
'k1' => 'v1',
257+
'k2' => 'v2',
258+
'k3' => 'v3',
259+
'k4' => 'v4'
260+
);
249261
$ios_notification = array(
250-
'sound' => 'hello jpush',
262+
'sound' => 'jpush.caf',
251263
'badge' => 2,
252264
'content-available' => true,
253265
'category' => 'jiguang',
@@ -277,7 +289,7 @@ public function testPushToAll() {
277289
);
278290

279291
$result = $payload->setPlatform($platform)
280-
->iosNotification('Hello IOS', $ios_notification)
292+
->iosNotification($ios_alert, $ios_notification)
281293
->androidNotification('Hello Android', $android_notification)
282294
->message('Hello JPush', $message)
283295
->build();

0 commit comments

Comments
 (0)