会前提醒

最近更新时间:2024-09-30 12:09:51

我的收藏
当您成功预定会议后,TUIRoomKit 组件将在会议开始前10分钟向参会成员推送会前提醒消息。本文档将指引您接入 TIMPush 推送插件,以开启会前提醒功能。

功能介绍

在进行离线推送功能的集成前,请确保已按照官方文档完成 厂商配置,以确保 TUIRoomKit 的离线推送功能正常运行。
TUIRoomKit 接入 TIMPush 推送插件的效果如下(以小米手机 Redmi Note 8 Pro 的显示效果为例):
应用在后台时或离线时
锁屏时







功能接入

Android
iOS
1. 请参见推送插件 TIMPush 快速接入文档,完成除步骤6以外的所有步骤(TUIRoomKit 组件内部已经进行会前提醒的离线消息推送,所以步骤6不需要单独配置)。
2. (可选) 若您想实现点击通知立即进房,可参见以下代码,注册回调时机建议放在应用 Application 的 onCreate() 函数中:
TUICore.registerEvent(TUIConstants.TIMPush.EVENT_NOTIFY, TUIConstants.TIMPush.EVENT_NOTIFY_NOTIFICATION, new ITUINotification() {
@Override
public void onNotifyEvent(String key, String subKey, Map<String, Object> param) {
if (TUIConstants.TIMPush.EVENT_NOTIFY.equals(key) && TUIConstants.TIMPush.EVENT_NOTIFY_NOTIFICATION.equals(subKey)) {
if (param != null) {
String extString = (String) param.get(TUIConstants.TIMPush.NOTIFICATION_EXT_KEY);
try {
// 可根据您的业务,点击通知跳转到相应的界面,以下是跳转到房间的示例。
JSONObject roomObject = new JSONObject(extString);
String roomId = roomObject.getString("RoomId");
if (!TextUtils.isEmpty(roomId)) {
loginAndEnterRoom(roomId);
}
} catch (Exception e) {
}
}
}
}
});

private void loginAndEnterRoom(String roomId) {
int sdkAppId = "您的appId";
String userId = "您的UserId"
String userSig = GenerateTestUserSig.genTestUserSig(userId);
// 登录
TUILogin.login(this.getApplicationContext(), sdkAppId, userId, userSig, new TUICallback() {
@Override
public void onSuccess() {
// 登录成功后进入房间
ConferenceDefine.JoinConferenceParams params = new ConferenceDefine.JoinConferenceParams(roomId);
Intent intent = new Intent(getApplicationContext(), ConferenceMainActivity.class);
intent.putExtra(KEY_JOIN_CONFERENCE_PARAMS, params);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(intent);
}
@Override
public void onError(int errorCode, String errorMessage) {
}
});
}
注意:
若您想实现点击推送进入房间,必须进房前完成登录
1. 集成 TIMPush 组件
pod 'TIMPush', '8.1.6108'
2. 配置推送参数
完成 厂商配置 后,可以在 即时通信 IM 控制台 得到证书 ID。您需要在 AppDelegate 中,实现 offlinePushCertificateID 协议方法并返回证书 ID 。
Swift
OC
import TIMPush

extension AppDelegate: TIMPushDelegate {
func offlinePushCertificateID() -> Int32 {
return kAPNSBusiId
}
}
#import "TIMPush/TIMPushManager.h"

@interface AppDelegate () <TIMPushDelegate>

- (int)offlinePushCertificateID {
return kAPNSBusiId;
}
3. 点击离线推送后自定义跳转(可选)
在默认情况下,点击通知会跳转到 app。您可以参见以下代码实现点击通知立即进入会议,也可以查看 github 中的 SceneDelegate 和 AppDelegate 文件。
如果是冷启动,需要在 SceneDelegate 中解析通知消息,得到要进入会议的 roomId。
Swift
OC
import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
let loginVC = TRTCLoginViewController() //您自己的登录页面
loginVC.roomId = processOfflinePush(connectionOptions: connectionOptions)
let nav = UINavigationController(rootViewController: loginVC)
window?.rootViewController = nav
window?.makeKeyAndVisible()
}

private func processOfflinePush(connectionOptions: UIScene.ConnectionOptions) -> String? {
guard let pushNotification = connectionOptions.notificationResponse?.notification.request.content.userInfo else { return nil }
guard let extString = pushNotification["ext"] as? String else { return nil }
guard let dict = extString.convertToDic() else { return nil }
return dict["RoomId"] as? String
}
#import "SceneDelegate.h"
#import <UserNotifications/UserNotifications.h>
#import "TUIRoomKit/TUIRoomKit-Swift.h"
#import "TIMDefine.h"

@interface SceneDelegate ()
@property (nonatomic, strong) NSString *roomId;
@end

@implementation SceneDelegate

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
[self processOfflinePush:connectionOptions];
}

- (void)processOfflinePush: (UISceneConnectionOptions *)connectionOptions {
NSDictionary *pushNotification = connectionOptions.notificationResponse.notification.request.content.userInfo;
NSString *notice = pushNotification[@"ext"];
NSDictionary *dic = [self dictionaryFromString:notice];
NSString *roomId = dic[@"RoomId"];
//将roomId传给您自己的登录页面YourLoginViewController
}

@end
在您的登录页面完成 TUICore 的登录,并且判断是否需要跳转到会议主界面。
Swift
OC
import TUICore
import TUIRoomKit

//YourLoginViewController 是您自己的登录页面
class YourLoginViewController: UIViewController {
var roomId: String?

override func viewDidLoad() {
super.viewDidLoad()
TUILogin.login(Int32(SDKAppID), userID: "yourUserName", userSig: "yourUserSig") { [weak self] in
guard let self = self else { return }
self.navigationController?.pushViewController(YourSelfViewController(), animated: false)
//YourSelfViewController是正常登录后应该显示的您自己的界面
guard let roomId = self.roomId else { return }
//通过roomId判断是否通过离线通知进入前台,由此判断是否再跳转到会议主界面
self.showConferenceMainViewController(roomId: roomId)
self.roomId = nil
} fail: { (code, errorDes) in
print("code:\\(code), errorDes:\\(String(describing: errorDes))")
}
}
func showConferenceMainViewController(roomId: String) {
let conferenceViewController = ConferenceMainViewController()
let params = JoinConferenceParams(roomId: roomId)
conferenceViewController.setJoinConferenceParams(params: params)
navigationController?.pushViewController(conferenceViewController, animated: true)
}
}

#import "YourLoginViewController.h"
#import "TUIRoomKit/TUIRoomKit-Swift.h"
#import "TUILogin.h"

@interface YourLoginViewController ()
@property (nonatomic, strong) NSString *roomId;
@end

@implementation YourLoginViewController

- (void)viewDidLoad {
[super viewDidLoad];
[TUILogin login:yourSDKAPPID userID:@"youruserID" userSig:@"yourUserSig" succ:^{
//先显示您自己的界面
//如果roomId有值,说明是从离线推送进来的,可以调用showConferenceMainViewController再跳转到会议主界面
} fail:^(int code, NSString * _Nullable msg) {
}];
// Do any additional setup after loading the view.
}

- (void)showConferenceMainViewController: (NSString *)roomId {
ConferenceMainViewController * vc = [[ConferenceMainViewController alloc]init];
JoinConferenceParams * params = [[JoinConferenceParams alloc]initWithRoomId:
roomId isOpenMicrophone:true isOpenCamera:false isOpenSpeaker:true];
[vc setJoinConferenceParamsWithParams:params];
[self.navigationController pushViewController:vc animated:true];
}
如果是从后台进入前台,需要在 AppDelegate文件中实现 onRemoteNotificationReceived 方法。
Swift
OC
import TUIRoomKit
import TIMPush

@main
class AppDelegate: UIResponder, UIApplicationDelegate, TIMPushDelegate {
var roomId: String?
func onRemoteNotificationReceived(_ notice: String?) -> Bool {
guard let notice = notice else { return false }
guard let dict = convertToDic(string: notice) else { return false }
guard let roomId = dict["RoomId"] as? String else { return false }
if V2TIMManager.sharedInstance().getLoginStatus() == .STATUS_LOGINED {
//如果从后台唤醒并且已经完成登录,可以直接进入会议。
showConferenceMainViewController(roomId: roomId)
}
return true
}
}
#import "AppDelegate.h"
#import "TIMPush/TIMPushManager.h"
#import "TUIRoomKit/TUIRoomKit-Swift.h"
#import "TIMDefine.h"

@interface AppDelegate ()<TIMPushDelegate>
@property (nonatomic, strong) NSString *roomId;
@end
@implementation AppDelegate

- (BOOL)onRemoteNotificationReceived:(NSString *)notice {
NSDictionary * dic = [self dictionaryFromString:notice];
NSString * roomId = dic[@"RoomId"];
if (!roomId) {
return false;
}
if ([V2TIMManager sharedInstance].getLoginStatus == V2TIM_STATUS_LOGINED ) {
//如果从后台唤醒并且已经完成登录,可以直接进入会议。
[self showConferenceMainViewController:roomId];
}
return true;
}

@end

常见问题

1. 若在集成过程中遇到问题,请务必先查阅 插件推送-常见问题 进行自助排查。
2. 条件说明:部分厂商要求必须上架应用市场才可以正常使用推送服务,详情参见下表:
厂商通道
是否需要上架
账号说明
小米
需要注册企业开发者账号
vivo
需要注册企业开发者账号
OPPO
需要注册企业开发者账号
荣耀
需要注册企业开发者账号
华为
个人开发者账号即可
魅族
个人开发者账号即可
如有问题,欢迎您加入我们的 TUIRoomKit 技术交流平台 zhiliao 进行反馈。

功能定制

如果您想自定义会前提醒时间,您可以通过修改源码来实现,不同平台请参见:
Android
iOS
您可通过修改Android/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/view/page/widget/ScheduleConference/view/ScheduleConferenceView.javaREMINDER_TIME 成员变量的值,设置会前提醒的时间(秒)。
您可通过修改 iOS/TUIRoomKit/Source/ScheduleConferenceViewController.swiftreminderSecondsBeforeStart 成员变量的值,设置会前提醒的时间(秒)。
注意:
若会前提醒的时间大于会议预定的时间,则不会推送会前提醒的通知。
说明:
若您还有其他问题,可通过 TUIRoomKit 技术交流平台 zhiliao,向我们反馈。

关键代码

会前提醒时间的设置,不同平台可参见:
Android
iOS
public abstract void scheduleConference(ConferenceInfo conferenceInfo, TUIRoomDefine.ActionCallback callback);
您可以通过修改 conferenceInfo 的 reminderSecondsBeforeStart 字段设置会前提醒时间(秒),详情请参见 scheduleConference 。示例代码如下:
TUIConferenceListManager manager = (TUIConferenceListManager) TUIRoomEngine.sharedInstance().getExtension(CONFERENCE_LIST_MANAGER);
TUIConferenceListManager.ConferenceInfo conferenceInfo = new TUIConferenceListManager.ConferenceInfo(); conferenceInfo.basicRoomInfo.roomId = "您的roomId"; conferenceInfo.reminderSecondsBeforeStart = 600; // 请替换600为您的会前提醒时间
manager.scheduleConference(conferenceInfo, new TUIRoomDefine.ActionCallback() { @Override public void onSuccess() {
// 预定会议成功回调 } @Override public void onError(TUICommonDefine.Error error, String message) {
// 预定会议失败回调 } });
- (void)scheduleConference:(TUIConferenceInfo *)conferenceInfo onSuccess:(TUISuccessBlock)onSuccess onError:(TUIErrorBlock)onError NS_SWIFT_NAME(scheduleConference(_:onSuccess:onError:));
您可以通过修改 conferenceInfo 的 reminderSecondsBeforeStart 字段设置会前提醒时间(秒),详情请参见 scheduleConference 。示例代码如下:
Swift
OC
import RTCRoomEngine

func scheduleConference() {
let manager = TUIRoomEngine.sharedInstance().getExtension(extensionType: .conferenceListManager) as? TUIConferenceListManager
let conferenceInfo = TUIConferenceInfo()
conferenceInfo.basicRoomInfo.roomId = "111111" // 请替换 "111111" 为您自定义的房间号
conferenceInfo.reminderSecondsBeforeStart = 600 // 请替换 600 为您自定义的会前提醒时间
manager?.scheduleConference(conferenceInfo, onSuccess: {
print("ScheduleConference success")
}, onError: { code, message in
print("ScheduleConference error, code:\\(code), message:\\(message)")
})
}
#import "RTCRoomEngine/TUIRoomEngine.h"
#import "RTCRoomEngine/TUIConferenceListManager.h"

- (void)scheduleConference {
TUIConferenceListManager * manager = [[TUIRoomEngine sharedInstance] getExtension: TUIExtensionTypeConferenceListManager];
TUIConferenceInfo * conferenceInfo = [[TUIConferenceInfo alloc] init];
conferenceInfo.basicRoomInfo.roomId = @"111111"; // 请替换 @"111111" 为您自定义的房间号
conferenceInfo.reminderSecondsBeforeStart = 600; //请替换 600 为您自定义的会前提醒时间
[manager scheduleConference:conferenceInfo onSuccess:^{
NSLog(@"ScheduleConference success");
} onError:^(TUIError code, NSString * _Nonnull message) {
NSLog(@"ScheduleConference failed, code:%ld, message:%@", (long)code, message);
}];
}