功能介绍
在进行离线推送功能的集成前,请确保已按照官方文档完成 厂商配置,以确保 TUIRoomKit 的离线推送功能正常运行。
TUIRoomKit 接入 TIMPush 推送插件后收到会中呼叫提醒消息的效果如下:
应用在后台时或离线时 | 锁屏时 |
| |
功能接入
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) && param != null) { String extString = (String) param.get(TUIConstants.TIMPush.NOTIFICATION_EXT_KEY); try { JSONObject roomObject = new JSONObject(extString); String notificationType = roomObject.getString("NotificationType"); if ("conference_invitation".equals(notificationType)) { login(new TUICallback() { @Override public void onSuccess() { } @Override public void onError(int errorCode, String errorMessage) { } }); } } catch (Exception e) { } } } });private void login(TUICallback callback) { int sdkAppId = 您的sdkappid; String userId = "您的userId"; String userSig = "您的userSig"; TUILogin.login(this.getApplicationContext(), sdkAppId, userId, userSig, new TUICallback() { @Override public void onSuccess() { if (callback != null) { callback.onSuccess(); } } @Override public void onError(int errorCode, String errorMessage) { if (callback != null) { callback.onError(errorCode, errorMessage); } } }); }
1. 集成 TIMPush 组件:
pod 'TIMPush', '8.1.6108'
2. 配置推送参数:
import TIMPushextension AppDelegate: TIMPushDelegate {func offlinePushCertificateID() -> Int32 {return kAPNSBusiId}}
#import "TIMPush/TIMPushManager.h"@interface AppDelegate () <TIMPushDelegate>- (int)offlinePushCertificateID {return kAPNSBusiId;}
3. 单击离线推送后拉起被呼叫界面
如果是冷启动,您需要在 SceneDelegate 中解析通知消息,得到推送消息的 extString。
import UIKitclass 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 = YourLoginViewController() // 您自己的登录页面loginVC.extString = processOfflinePush(connectionOptions: connectionOptions)let nav = UINavigationController(rootViewController: loginVC)window?.rootViewController = navwindow?.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 }return extString}
#import "SceneDelegate.h"#import <UserNotifications/UserNotifications.h>#import "TUIRoomKit/TUIRoomKit-Swift.h"#import "TIMDefine.h"@interface SceneDelegate ()@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 *extString = pushNotification[@"ext"];//将extString传给您自己的登录页面YourLoginViewController}@end
在您的登录页面完成 TUICore 的登录,并且判断是否需要跳转到被呼叫界面。
import TUICoreimport TUIRoomKit//YourLoginViewController 是您自己的登录页面class YourLoginViewController: UIViewController {var extString: String?override func viewDidLoad() {super.viewDidLoad()TUILogin.login(Int32(SDKAppID), userID: "yourUserName", userSig: "yourUserSig") { [weak self] inguard let self = self else { return }self.navigationController?.pushViewController(YourSelfViewController(), animated: false)// YourSelfViewController是正常登录后应该显示的您自己的界面guard let extString = self.extString else { return }guard let notificationType = dict["NotificationType"] as? String else { return }// 通过notificationType判断是否为会中呼叫提醒,由此判断是否再拉起被呼叫页面if notificationType == "conference_invitation" {InvitationObserverService.shared.show(extString: extString) // 调用此方法以拉起被呼叫界面}self.extString = nil} fail: { (code, errorDes) inprint("code:\\(code), errorDes:\\(String(describing: errorDes))")}}}
#import "YourLoginViewController.h"#import "TUIRoomKit/TUIRoomKit-Swift.h"#import "TUILogin.h"@interface YourLoginViewController ()@property (nonatomic, strong) NSString *extString;@end@implementation YourLoginViewController- (void)viewDidLoad {[super viewDidLoad];[TUILogin login:yourSDKAPPID userID:@"youruserID" userSig:@"yourUserSig" succ:^{//先显示您自己的界面//如果extString有值,说明是从离线推送进来的,可以调用showInitationView拉起被呼叫界面} fail:^(int code, NSString * _Nullable msg) {}];// Do any additional setup after loading the view.}- (void)showInitationView: (NSString *)extString {[[InvitationObserverService shared] show:extString];}
如果是从后台进入前台,需要在 AppDelegate文件中实现 onRemoteNotificationReceived 方法。
import TUIRoomKitimport TIMPush@mainclass 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 {InvitationObserverService.shared.show(extString: extString) // 调用此方法以拉起被呼叫界面}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 ) {[[InvitationObserverService shared] show:extString];}return true;}@end
常见问题
1. 若在集成过程中遇到问题,请务必先查阅 插件推送-常见问题 进行自助排查。
2. 条件说明:部分厂商要求必须上架应用市场才可以正常使用推送服务,详情参见下表:
厂商通道 | 是否需要上架 | 账号说明 |
小米 | 是 | 需要注册企业开发者账号 |
vivo | 是 | 需要注册企业开发者账号 |
OPPO | 否 | 需要注册企业开发者账号 |
荣耀 | 否 | 需要注册企业开发者账号 |
华为 | 否 | 个人开发者账号即可 |
魅族 | 否 | 个人开发者账号即可 |
功能定制
如您需要自定义被呼叫页面的视图,请参考以下路径进行更改:
// 文件位置:Android/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/view/component/component└──InvitationReceivedView.java
// 文件位置:iOS/TUIRoomKit/Source/View/ConferenceOptions/ConferenceInvitationConferenceInvitation└── ConferenceInvitationViewController.swift // 被呼叫页面视图