一.有關(guān)Android推送
1.常見(jiàn)推送通道
- 自建通道
FCM通道:Firebase Cloud Messaging,是一項(xiàng)針對(duì)Android降传、iOS及Web的消息與通知的跨平臺(tái)解決方案,由Google擁有的Firebase公司提供勾怒。
極光通道:Aurora Mobile搬瑰,全面兼容和支持Android、iOS控硼、鴻蒙泽论、快應(yīng)用和winphone平臺(tái),提供極光通道卡乾、APNS翼悴、FCM、華為幔妨、小米鹦赎、OPPO、VIVO误堡、魅族古话、華碩等系統(tǒng)級(jí)消息下發(fā)通道。
- 廠商通道:
華為通道
小米通道
OPPO通道
VIVO通道
魅族通道
榮耀通道
2.離線是否可收到推送
極光通道:極光通道是自建通道锁施,需要長(zhǎng)依賴才能收到推送陪踩,設(shè)備離線消息不會(huì)下發(fā)果覆。
FCM通道:FCM通道是自建通道反症,設(shè)備離線可以收到推送。FCM服務(wù)器將消息發(fā)送到平臺(tái)特定的傳輸層:
Android:Android transport layer(ATL)钉汗,僅適用于運(yùn)行Google Play的安卓設(shè)備姥饰。
iOS:適用于Apple設(shè)備的Apple推送服務(wù)器(APNs)傻谁。
Web:Web應(yīng)用的網(wǎng)絡(luò)推送協(xié)議。
- 廠商通道:廠商通道是系統(tǒng)通道列粪,設(shè)備離線也可以收到推送审磁。例如小米、華為岂座、OPPO态蒂、vivo、魅族掺逼、榮耀吃媒、FCM通道,需要集成各自的廠商通道才行吕喘。
3.通知渠道
從Android 8.0(API級(jí)別26)開(kāi)始赘那,必須為所有通知分配渠道,否則通知將不會(huì)顯示氯质。通過(guò)將通知?dú)w類(lèi)到不同的渠道中募舟,用戶可以停用應(yīng)用的特定通知渠道(而非停用您的所有通知),還可以控制每個(gè)渠道的視覺(jué)和聽(tīng)覺(jué)選項(xiàng)闻察。
在Android 7.1(API級(jí)別25)及更低版本的設(shè)備上拱礁,每個(gè)應(yīng)用其實(shí)只有一個(gè)渠道,用戶僅可以按應(yīng)用來(lái)管理通知辕漂。
注意:界面將渠道稱作“類(lèi)別”呢灶。
4.通知的重要程度
從Android 8.0(API級(jí)別26)開(kāi)始,渠道還可以指定通知的重要程度等級(jí)importance
钉嘹,因此鸯乃,發(fā)布到同一通知渠道的所有通知的行為都相同。
-
Urgent(緊急)
:發(fā)出聲音并彈出對(duì)話框跋涣。 -
High(高)
:發(fā)出聲音缨睡。 -
Medium(中)
:靜音。 -
Low(低)
:靜音陈辱,且不會(huì)在狀態(tài)欄中顯示奖年。
二.iOS自定義推送提示音
1.格式要求
音頻數(shù)據(jù)格式必須是Linear PCM
、MA4 (IMA/ADPCM)
沛贪、μLaw
陋守、aLaw
中的一種,且時(shí)長(zhǎng)要求在30s以下利赋,否則就是系統(tǒng)默認(rèn)的鈴聲嗅义。
可以將音頻數(shù)據(jù)打包到aiff
、wav
或caf
文件中隐砸。
2.客戶端設(shè)置
方式一:將聲音文件導(dǎo)入工程之碗,操作步驟:選中工程Target --> Build Phases --> Copy Bundle Resources。
方式二:直接拖入到某文件夾下:
3.服務(wù)端設(shè)置
指定iOS平臺(tái)下的sound參數(shù)季希,具體傳入值是聲音文件名+后綴褪那,例如FCM
自定義聲音格式:
{
"message":{
"token":"ce3_Fi431Eonq-_qPrvDP0:APA91bHr8R7-AXYbzw9JmwSi6C0rpx7hXABbKMtT1CJ5GrDhwozAXuBLmUOV3tRo3Nxt4DV6R3wmEI2AfVXhnw8XafNNksFLC5TnYmHq0XWpYVxOpP0yyDT19sCkPBshZGGUGhhPEJeq",
"notification":{
"title":"FCM Message",
"body":"This is an FCM notification message!"
},
"apns":{
"payload":{
"aps":{
"sound":"叮咚.caf"
}
}
}
}
}
三.Android自定義推送提示音
1.格式要求
支持的文件格式包括mp3
、wav
式塌、mpeg
等博敬。
2.極光/OPPO/FCM通道通知實(shí)現(xiàn)
a.客戶端設(shè)置
<1>將音頻文件拖入到src/main/res/raw
文件夾下:
<2>創(chuàng)建channel并設(shè)置sound:
const String channelGroupId = 'custom sound group';
const AndroidNotificationChannel channelHappy = AndroidNotificationChannel(
'custom sound happy',
'自定義鈴聲happy',
description: '自定義鈴聲通道happy',
importance: Importance.high,
sound: RawResourceAndroidNotificationSound('happy'),
groupId: channelGroupId,
);
const AndroidNotificationChannel channelSpring = AndroidNotificationChannel(
'custom sound spring',
'自定義鈴聲spring',
description: '自定義鈴聲通道spring',
importance: Importance.high,
sound: RawResourceAndroidNotificationSound('spring'),
groupId: channelGroupId,
);
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
調(diào)用下面的方法創(chuàng)建:
Future<void> _createNotificationChannelGroup() async {
/// 創(chuàng)建分組
const androidNotificationChannelGroup = AndroidNotificationChannelGroup(
channelGroupId,
'自定義鈴聲分組',
description: '用于自定義鈴聲的分組',
);
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()!
.createNotificationChannelGroup(androidNotificationChannelGroup);
/// 創(chuàng)建通知渠道并關(guān)聯(lián)到分組
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()!
.createNotificationChannel(channelHappy);
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()!
.createNotificationChannel(channelSpring);
}
b.服務(wù)器設(shè)置
推送時(shí)需要在notification
下配置sound
和channel_id
字段,channel_id
字段需與客戶端創(chuàng)建的channel id
一致峰尝。
例如FCM平臺(tái)的服務(wù)端設(shè)置:
{
"message":{
"token":"fH-B3A9-Rky5jr-OlXC-Cj:APA91bGPOLYrkttswUrN9-maUZDUpbywTWptREHRMbwqCYSnvkTMio485Drfm1JQtmdRWgZ42h4NPp0zPLXU6iH7BPzE6RNkgoOW9P8hJU8H7hRvTzTTrb8eHUaKTC_S5l0yOPWuggs_",
"notification":{
"title":"FCM Message",
"body":"This is an FCM notification message!"
},
"android":{
"notification":{
/// 如果 sound 和 channel_id都有傳偏窝,那么會(huì)以 channel_id 的鈴聲為準(zhǔn)
/// Android 8.0以上,需傳入channel_id,否則自定義鈴聲失效
"channel_id": "custom sound happy",
"sound":"happy"
}
}
}
}
四.iOS推送語(yǔ)音播報(bào)
1.新增通知擴(kuò)展Notification Service Extension
:
2.修改通知擴(kuò)展支持的最低版本:
后續(xù)待定祭往。伦意。。