このページは現在英語版のみで提供されており、日本語版も近日中に提供される予定です。ご利用いただきありがとうございます。

Custom Definition Ringtone

Android

Pre-8.0 systems

1. Custom ringtone resource files for Android should be added to the project's raw directory; for iOS, link them into the Xcode project.
2. Please use the message invocation interfaces setAndroidSound() and setIOSSound().
V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
v2TIMOfflinePushInfo.setAndroidSound("Ringtone Name");
v2TIMOfflinePushInfo.setIOSSound("Ringtone Name.mp3");

String msgID = V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, isGroup ? null : userID, isGroup ? groupID : null,
V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {
@Override
public void onProgress(int progress) {

}

@Override
public void onError(int code, String desc) {

}

@Override
public void onSuccess(V2TIMMessage v2TIMMessage) {

}
});
Note:
Supported in IMSDK v6.1.2155 or above.
The interface supports Huawei, Xiaomi, FCM, and APNS.

System version 8.0 and later

Huawei and APNs

Huawei, APNS use setAndroidSound() and setIOSSound() to set the offline push ringtone prompt.

OPPO

1. Locally create a custom notification channel
// Example
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://package_name/raw/private_ring" notificationChannel.setSound(Uri.parse("sound"), null); nm.createNotificationChannel(notificationChannel); }
2. Use the created channel
Push messages carry the channel ID field. For details, see setAndroidOPPOChannelID. For console settings, see Certificate Editing ChannelID field. Setting one of the two is sufficient.

Mi

1. log in to the Manufacturer Console to create a channel and configure, where the ringtone file needs to be added to the raw directory of your local Android Studio project.



2. Send a message specifying the channel ID of the custom ringtone; for details, please refer to setAndroidXiaoMiChannelID.
V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
v2TIMOfflinePushInfo.setAndroidXiaoMiChannelID("Channel ID Applied by Manufacturer");

String msgID = V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, isGroup ? null : userID, isGroup ? groupID : null,
V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false, v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {
@Override
public void onProgress(int progress) {
TUIChatUtils.callbackOnProgress(callBack, progress);
}

@Override
public void onError(int code, String desc) {
TUIChatUtils.callbackOnError(callBack, TAG, code, desc);
}

@Override
public void onSuccess(V2TIMMessage v2TIMMessage) {

}
});

FCM

1. Custom ringtone resource files should be added to the project's raw directory. To configure FCM's custom ringtone parameters, call before registering for push services. For details, see configFCMPrivateRing.
2. Send a message specifying the channel ID for the custom ringtone; for details, please refer to setAndroidFCMChannelID.
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>() {
@Override
public void onProgress(int progress) {
TUIChatUtils.callbackOnProgress(callBack, progress);
}

@Override
public void onError(int code, String desc) {
TUIChatUtils.callbackOnError(callBack, TAG, code, desc);
}

@Override
public void onSuccess(V2TIMMessage v2TIMMessage) {

}
});
Note:
Supported in IMSDK v7.0.3754 or above.
FCM custom ringtones or setting channel ID is supported only in Certificate Mode.

iOS

1. When calling sendMessage to send a message, set the V2TIMOfflinePushInfo's iOSSound field. Pass in the voice file name to iOSSound.
Note:
Offline push notification sound settings (effective only for iOS), when `iOSSound = kIOSOfflinePushNoSound`, it indicates no sound will be played upon receiving.
When `iOSSound = kIOSOfflinePushDefaultSound`, it indicates the system sound will be played upon receiving.
To customize `iOSSound`, you first need to link the audio file into the Xcode project, and then set the audio filename (including the extension) to `iOSSound`.
V2TIMOfflinePushInfo *pushInfo = [[V2TIMOfflinePushInfo alloc] init];
pushInfo.title = @"push title";
pushInfo.iOSSound = @"phone_ringing.mp3"; // 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) {

}];
2. When calling sendMessage to send a message, set the V2TIMOfflinePushInfo's AndroidSound field; pass in the voice file name to AndroidSound.
Note:
Offline push notification sound settings (effective only for Android, supported only in imsdk 6.1 and above) are supported only on Huawei and Google phones for setting ringtone prompts.
For Xiaomi ringtone settings, please refer to: Server-side Java SDK documentation.
To customize `AndroidSound`, you first need to place the audio file in the raw directory of the Android project, and then set the `AndroidSound` with the audio filename (without the extension).
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) {

}];


uniapp

Note:
The receiver needs to integrate TencentCloud-TIMPush.
For the sender, @tencentcloud/chat ≥ 3.3.2.
Supports Huawei, Xiaomi, FCM, and APNS.

Receiver

Android
iOS
Custom ringtone resource files should be added to the project nativeResources/android/res/raw directory, as shown:



Note:
For iOS custom ringtones, the uniapp must be the official package.
Custom ringtone resource files should be added to the project nativeResources/ios/Resources directory, as shown:




Sender

1. Upgrade @tencentcloud/chat to the latest version.

npm install @tencentcloud/chat@latest
web
uniapp
Check the TencentCloudChat.VERSION in the browser console to confirm @tencentcloud/chat ≥ 3.3.2 as shown:



Check the TencentCloudChat.VERSION in the HBuilder logs to confirm @tencentcloud/chat ≥ 3.3.2 as shown:




2. Send a message, set related parameters for the custom ringtone in offlinePushInfo.

Note:
On Xiaomi phones with Android 8.0 and above, setting androidInfo.XiaoMiChannelID is mandatory, please refer to:Xiaomi Custom Ringtone.
Google Phone FCM Push on Android 8.0 and above systems requires setting androidInfo.FCMChannelID for sound notifications.
Integration (UI Included)
Integration Without UI
Note:
When apnsInfo.sound = TUIChatEngine.TYPES.IOS_OFFLINE_PUSH_NO_SOUND, it means no sound will be played upon receiving.
When apnsInfo.sound = TUIChatEngine.TYPES.IOS_OFFLINE_PUSH_DEFAULT_SOUND, it means the system sound will be played upon receiving.
When using TUIChatService in UIKit to send messages, set related offlinePushInfo parameters. For example, to send a regular text message, the code is as follows:
// Send Plain Text Message
let promise = TUIChatService.sendTextMessage(
{
payload: { text: 'Hello world!' }
},
{
// If the recipient is offline, the message will be stored for roaming and an offline push will be executed (when the recipient's App is in the background or the process has been killed). The integrator can define the title and content of the offline push
offlinePushInfo: {
androidInfo: { // Android Push Configuration
sound: 'private_ring.mp3', // Custom ringtone for Android
XiaoMiChannelID: '', // On Xiaomi Mobile Phone with Android 8.0 and above, setting XiaoMiChannelID is mandatory
FCMChannelID: '', // Google Phone FCM on Android 8.0 and above systems requires setting FCMChannelID for sound notifications.
},
apnsInfo: { // APNs Push Configuration
// apnsInfo.sound = TUIChatEngine.TYPES.IOS_OFFLINE_PUSH_NO_SOUND, indicates no sound will be played upon receiving.
// apnsInfo.sound = TUIChatEngine.TYPES.IOS_OFFLINE_PUSH_DEFAULT_SOUND, indicates the system sound will be played upon receiving.
sound: 'private_ring.mp3', // Custom ringtone for iOS
}
}
}
);
promise.catch((error) => {
// Business side can handle errors by catching exceptions through promise.catch when an invocation exception occurs
});
Reference Documentation:
Note:
When apnsInfo.sound = TencentCloudChat.TYPES.IOS_OFFLINE_PUSH_NO_SOUND, it means no sound will be played upon receiving.
When apnsInfo.sound = TencentCloudChat.TYPES.IOS_OFFLINE_PUSH_DEFAULT_SOUND, it means the system sound will be played upon receiving.
When sending a message in chat, set the related fields for offlinePushInfo as follows:
// Message Sending Options
chat.sendMessage(message, {
// If the recipient is offline, the message will be stored for roaming and an offline push will be executed (when the recipient's App is in the background or the process has been killed). The integrator can define the title and content of the offline push
offlinePushInfo: {
androidInfo: { // Android Push Configuration
sound: 'private_ring.mp3', // Custom ringtone for Android
XiaoMiChannelID: '', // On Xiaomi Mobile Phone with Android 8.0 and above, setting XiaoMiChannelID is mandatory
FCMChannelID: '', // Google Phone FCM on Android 8.0 and above systems requires setting FCMChannelID for sound notifications.
},
apnsInfo: { // APNs Push Configuration
// apnsInfo.sound = TencentCloudChat.TYPES.IOS_OFFLINE_PUSH_NO_SOUND, indicates no sound will be played upon receiving.
// apnsInfo.sound = TencentCloudChat.TYPES.IOS_OFFLINE_PUSH_DEFAULT_SOUND, indicates the system sound will be played upon receiving.
sound: 'private_ring.mp3', // Custom ringtone for iOS
}
}
});

Flutter

Note:
The interface supports Huawei, Xiaomi, FCM, and APNS.
Custom ringtone resource files for Android should be added to the project's raw directory; for iOS, link them into the Xcode project.
When calling sendMessage to send a message, set the fields offlinePushInfo, iOSSound, and androidSound.
For specific manufacturer configurations, please refer to the content of the Android and iOS modules below. The methods called are all available under the same name in the Flutter version of the IM SDK.