厂商 | 是否支持自定义铃音 |
iOS | 支持 |
FCM | 支持 |
{// ..."OfflinePushInfo": {"AndroidInfo": {"Sound": "shake" // 不带后缀},"ApnsInfo": {"Sound": "apns.caf",}}}
V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();v2TIMOfflinePushInfo.setAndroidSound("铃音名称");v2TIMOfflinePushInfo.setIOSSound("铃音名称.mp3");String msgID = V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, isGroup ? null : userID, isGroup ? groupID : null,V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {@Overridepublic void onProgress(int progress) {}@Overridepublic void onError(int code, String desc) {}@Overridepublic void onSuccess(V2TIMMessage v2TIMMessage) {}});
// 自定义创建示例if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {NotificationManager nm = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);NotificationChannel notificationChannel =new NotificationChannel("channelId", "channelName", NotificationManager.IMPORTANCE_HIGH);notificationChannel.enableLights(true);notificationChannel.enableVibration(true);notificationChannel.setShowBadge(true);notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);// "android.resource://包名/raw/private_ring"notificationChannel.setSound(Uri.parse("sound"), null);nm.createNotificationChannel(notificationChannel);}
{// ..."OfflinePushInfo": {"AndroidInfo": {"GoogleChannelID": "test_Google_channel_id",}}}
V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();v2TIMOfflinePushInfo.setAndroidFCMChannelID(PrivateConstants.fcmPushChannelId);String msgID = V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, isGroup ? null : userID, isGroup ? groupID : null,V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {@Overridepublic void onProgress(int progress) {TUIChatUtils.callbackOnProgress(callBack, progress);}@Overridepublic void onError(int code, String desc) {TUIChatUtils.callbackOnError(callBack, TAG, code, desc);}@Overridepublic void onSuccess(V2TIMMessage v2TIMMessage) {}});
{// ..."OfflinePushInfo": {"ApnsInfo": {"Sound": "apns.caf"}}}
V2TIMOfflinePushInfo *pushInfo = [[V2TIMOfflinePushInfo alloc] init];pushInfo.title = @"push title";pushInfo.iOSSound = @"phone_ringing.caf"; // your voice file's name[[V2TIMManager sharedInstance] sendMessage:msg receiver:receiver groupID:groupID priority:V2TIM_PRIORITY_DEFAULT onlineUserOnly:NO offlinePushInfo:pushInfo progress:nil succ:^{} fail:^(int code, NSString *msg) {}];
AndroidSound 字段, AndroidSound 传语音文件名。{"OfflinePushInfo": {"AndroidInfo": {"Sound": "shake", // 不带后缀"XiaoMiChannelID": "test_XiaoMi_channel_id","OPPOChannelID": "test_OPPO_channel_id","GoogleChannelID": "test_Google_channel_id"},"ApnsInfo": {"Sound": "apns.caf"}}}
V2TIMOfflinePushInfo *pushInfo = [[V2TIMOfflinePushInfo alloc] init];pushInfo.title = @"push title";pushInfo.AndroidSound = @"phone_ringing"; // your voice file's name[[V2TIMManager sharedInstance] sendMessage:msg receiver:receiver groupID:groupID priority:V2TIM_PRIORITY_DEFAULT onlineUserOnly:NO offlinePushInfo:pushInfo progress:nil succ:^{} fail:^(int code, NSString *msg) {}];
iOSSound 及 androidSound 字段。{// ..."OfflinePushInfo": {"AndroidInfo": {"Sound": "shake", // 不带后缀"XiaoMiChannelID": "test_XiaoMi_channel_id","OPPOChannelID": "test_OPPO_channel_id","GoogleChannelID": "test_Google_channel_id"},"ApnsInfo": {"Sound": "apns.caf"}}}

App.vue 中设置 FCM 私信通道。如图所示:import * as Push from '@/uni_modules/TencentCloud-Push';Push.createNotificationChannel({channelID: '', // 自定义 channel 的 ID。OPPO 为控制台配置的 channelIDchannelName: '自定义channel',// 自定义channel 名称channelDesc: '这只是描述', // 自定义 channel 描述channelSound: 'private_ring' // 自定义铃音的名称且不需要后缀名}, () => {console.log('Push | createNotificationChannel ok');})

npm install @tencentcloud/chat@latest



// 发送普通文本消息let promise = TUIChatService.sendTextMessage({payload: { text: 'Hello world!' }},{// 如果接收方不在线,则消息将存入漫游,且进行离线推送(在接收方 App 退后台或者进程被 kill 的情况下)。接入侧可自定义离线推送的标题及内容offlinePushInfo: {androidInfo: { // Android 推送配置sound: 'private_ring.mp3', // Android 自定义铃音FCMChannelID: '', // 谷歌手机 FCM 在 Android 8.0 及以上系统设置声音提示,必须设置 FCMChannelID。},apnsInfo: { // APNs 推送配置// apnsInfo.sound = TUIChatEngine.TYPES.IOS_OFFLINE_PUSH_NO_SOUND,表示接收时不会播放声音。// apnsInfo.sound = TUIChatEngine.TYPES.IOS_OFFLINE_PUSH_DEFAULT_SOUND,表示接收时播放系统声音。sound: 'private_ring.caf', // iOS 自定义铃音}}});promise.catch((error) => {// 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理});
// 消息发送选项chat.sendMessage(message, {// 如果接收方不在线,则消息将存入漫游,且进行离线推送(在接收方 App 退后台或者进程被 kill 的情况下)。接入侧可自定义离线推送的标题及内容offlinePushInfo: {androidInfo: { // Android 推送配置sound: 'private_ring.mp3', // Android 自定义铃音XiaoMiChannelID: '', // 小米手机在 Android 8.0 及以上版本必须设置 XiaoMiChannelIDFCMChannelID: '', // 谷歌手机 FCM 在 Android 8.0 及以上系统设置声音提示,必须设置 FCMChannelID。OPPOChannelID: '', // OPPO手机必须设置 OPPOChannelID},apnsInfo: { // APNs 推送配置// apnsInfo.sound = TencentCloudChat.TYPES.IOS_OFFLINE_PUSH_NO_SOUND,表示接收时不会播放声音。// apnsInfo.sound = TencentCloudChat.TYPES.IOS_OFFLINE_PUSH_DEFAULT_SOUND,表示接收时播放系统声音。sound: 'private_ring.caf', // iOS 自定义铃音}}});
const TUICallKit = uni.requireNativePlugin('TencentCloud-TUICallKit');const options = {userID: '',callMediaType: 1, // 语音通话(callMediaType = 1)、视频通话(callMediaType = 2)callParams: {// 如果接收方不在线,进行离线推送(在接收方 App 退后台或者进程被 kill 的情况下)。接入侧可自定义离线推送的标题及内容offlinePushInfo: {title: 'test-title',description: 'you have a test call',androidSound: 'private_ring', // Android 离线推送的自定义铃音iOSSound: 'private_ring.caf', // iOS 离线推送的自定义铃音},},};TUICallKit.call(options, (res) => {if (res.code === 0) {console.log('call success');} else {console.log(`call failed, error message = ${res.msg}`);}});

项目 | Xcode |
![]() | ![]() |
// 消息发送选项chat.sendMessage(message, {// 如果接收方不在线,则消息将存入漫游,且进行离线推送(在接收方 App 退后台或者进程被 kill 的情况下)。接入侧可自定义离线推送的标题及内容offlinePushInfo: {androidInfo: { // Android 推送配置sound: 'private_ring.mp3', // Android 自定义铃音FCMChannelID: '', // 谷歌手机 FCM 在 Android 8.0 及以上系统设置声音提示,必须设置 FCMChannelID。},apnsInfo: { // APNs 推送配置// apnsInfo.sound = TencentCloudChat.TYPES.IOS_OFFLINE_PUSH_NO_SOUND,表示接收时不会播放声音。// apnsInfo.sound = TencentCloudChat.TYPES.IOS_OFFLINE_PUSH_DEFAULT_SOUND,表示接收时播放系统声音。sound: 'private_ring.caf', // iOS 自定义铃音}}});

import Push from "@tencentcloud/donut-push"App({onLaunch: function () {Push.createNotificationChannel({channelID: "", // 自定义 channel 的 ID。channelName: "", // 自定义channel 名称channelDesc: "", // 自定义 channel 描述channelSound: "" // 自定义铃音文件的名称且不需要文件扩展名}).then((ret) => {console.info("createNotificationChannel success", ret);}).catch((ret) => {console.error("createNotificationChannel failed", ret);});}})


{"From_Account": "administrator","To_Account": ["100480"],"MsgRandom": 3674128,"OfflinePushInfo": {"PushFlag": 0,"Title": "离线推送标题1adad1","Desc": "离线推送内容11adasd1","Ext":"{\\"aa\\":12123}","AndroidInfo": {"Sound": "private_ring123", // 跟客户端创建的 channel 中的铃声文件名称一致"GoogleChannelID": "test_google_channel_id"},"ApnsInfo": {"Sound": "01.caf"// 跟接收端 ipa 包内的铃声文件名称一致}}}
文档反馈