1. 程式人生 > >【測試深度】Ios10含以下,Json結構中,body的value為“”時,作業系統無法展示Notification

【測試深度】Ios10含以下,Json結構中,body的value為“”時,作業系統無法展示Notification

{
	"open_ids": "6456064906536960",
	"data": {
		"title": "A friend wants to share mood with you. Check it out.",
		"content": "",
		"url": "",
		"uid": "5477168498518016",
		"channel": 1,
		"action": 203,
		"source": 1,
		"large_img_url": "",
		"description": "",
		"event_type": "8",
		"unread_count": 1
	},
	"apns_data": {
		"aps": {
			"alert": {
				"title": "A friend wants to share mood with you. Check it out.",
				"body": ""    //出現原因為body的value是個空字串
			},
			"badge": 1,
			"sound": "default"
		},
		"u": {
			"t": 203,
			"url": "",
			"uid": "5477168498518016",
			"channel": 1,
			"source": 1,
			"action": 203,
			"event_type": "8"
		}
	},
	"gcm_type": "8"
}

0、被坑等級:五星

⭐️⭐️⭐️⭐️⭐️

1、測試過程&結果

本來測試中,N臺手機,接收push正常,畢竟Ios11、Ios12上收發push都是正常的,機型你也相容了好幾個,結果,沒想到相容性出現問題

結果:一臺iphone se ,ios 10.3.3的系統,launcher上有數字提示,震動也有,通知欄就是沒有Notificaiton

2、相容型別:作業系統

3、解決方案,兩種方式

方案1:不要讓body的值是空的“”,下面例子中,還加入了subtitle

{
  "aps" : {
    "alert" : {
      "title" : "iOS遠端訊息,我是主標題!-title",
      "subtitle" : "iOS遠端訊息,我是主標題!-Subtitle",
      "body" : "Dely,why am i so handsome -body"
    },
    "badge" : "2"
  }
}

方案2:alert的值不要json物件,直接用字串即可

{
  "aps" : {
    "alert" : “方案2”,
    "badge" : "2"
  }
}


4、總結

相容性測試的重要性,可見不容忽視,不然就是一個大坑,該現象極為嚴重。push驗證記住一定要在所有大系統上都ok