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.
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
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. 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
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";
[[V2TIMManager sharedInstance] sendMessage:msg receiver:receiver groupID:groupID priority:V2TIM_PRIORITY_DEFAULT onlineUserOnly:NO offlinePushInfo:pushInfo progress:nil succ:^{
} fail:^(int code, NSString *msg) {
}];
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.
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";
[[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:
For the sender, @tencentcloud/chat ≥ 3.3.2.
Supports Huawei, Xiaomi, FCM, and APNS.
Receiver
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
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)
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:
let promise = TUIChatService.sendTextMessage(
{
payload: { text: 'Hello world!' }
},
{
offlinePushInfo: {
androidInfo: {
sound: 'private_ring.mp3',
XiaoMiChannelID: '',
FCMChannelID: '',
},
apnsInfo: {
sound: 'private_ring.mp3',
}
}
}
);
promise.catch((error) => {
});
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:
chat.sendMessage(message, {
offlinePushInfo: {
androidInfo: {
sound: 'private_ring.mp3',
XiaoMiChannelID: '',
FCMChannelID: '',
},
apnsInfo: {
sound: 'private_ring.mp3',
}
}
});
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.
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.
Was this page helpful?