iOS

最近更新时间:2024-03-21 16:47:21

我的收藏

接口概览

注册/反注册推送服务接口

初始化并成功登录 IM 后,可以注册推送服务。
API
描述
注册推送服务, 在登录完成之后调用
反注册离线推送服务,IM 账号登出时调用。
关闭插件在登录后自动注册推送服务,需要在注册推送服务之前调用

统计 TIMPush 的推送抵达率

如果您需要统计推送的抵达和点击数据,您需要在 Notification Service Extension 中主动调用本函数。
API
描述
仅支持在 Notification Service Extension 的 '- didReceiveNotificationRequest:withContentHandler:' 方法中调用; appGroup 标识当前主 App 和 Extension 之间共享的 App Group,需要在主 App 的 Capability 中配置 App Groups 能力。

接口详情

函数说明

+ (void)registerPush

注册离线推送服务, IM 账号登录成功时调用。(注册推送服务需要的信息来自您 AppDelegate 实现的 TIMPushDelegate 协议的 offlinePushCertificateID )
注意:
您需要使用 TUICore 组件中的 TUILogin 提供的 login 接口登录,插件会自动感知并注册推送服务。
如果您不想使用 TUILogin 提供的接口,您需要在完成登录操作后,手动调用该接口注册服务。
用法: [TIMPush registerPush];

+ (void)unRegisterPush

反注册离线推送服务,IM 账号登出时调用。
注意:
您需要使用 TUICore 组件中的 TUILogin 提供的 login 接口登录,插件会自动感知并注册推送服务。
如果您不想使用 TUILogin 提供的接口,您需要在完成登录操作后,手动调用该接口注册服务。
用法: [TIMPush unRegisterPush];

+ (void)disableAutoRegisterPush

关闭插件自动注册推送服务,需要在登录之前调用。
注意:
如果您使用 TUICore 组件中的 TUILogin 提供的 login 接口登录,插件默认自动注册推送服务,调用该接口可关闭自动注册。
用法: [TIMPush disableAutoRegisterPush];

+ (void)onReceiveNotificationRequest:(UNNotificationRequest *)request inAppGroupID:(NSString *)appGroupID callback:(TIMPushNotificationExtensionCallback)callback

统计 TIMPush 的推送抵达率
您需要在 AppDelegate.m 文件中实现 `- applicationGroupID` 方法,返回 App Group ID。
并在 Notification Service Extension 的 '- didReceiveNotificationRequest:withContentHandler:' 方法中调用本函数。
注意:
appGroup 标识当前主 App 和 Extension 之间共享的 App Group,需要在主 App的 Capability 中配置 App Groups 能力。
参数说明:
request
appGroupID
appGroup 标识当前主 App和 Extension 之间共享的 App Group,需要在主 App 的 Capability 中配置 App Groups 能力。
callback
typedef void(^TIMPushNotificationExtensionCallback)(UNNotificationContent *content) 统计函数Callback,携带content信息
用法:

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.contentHandler = contentHandler;
NSString * appGroupID = kTIMPushAppGorupKey;
__weak typeof(self) weakSelf = self;
[TIMPush onReceiveNotificationRequest:request inAppGroupID:appGroupID callback:^(UNNotificationContent *content) {
weakSelf.bestAttemptContent = [content mutableCopy];
// Modify the notification content here...
// self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
weakSelf.contentHandler(weakSelf.bestAttemptContent);
}];
}