接口概览
注册/反注册推送服务接口
初始化并成功登录 IM 后,可以注册推送服务。
API | 描述 |
注册推送服务,在登录完成之后调用(支持 IM 消息互通)。 | |
反注册离线推送服务,IM 账号登出时调用。 | |
关闭插件在登录后自动注册推送服务,需要在注册推送服务之前调用。 | |
注册推送服务,不需要登录 IM(默认不支持 IM 消息互通)。 | |
RegistrationID 是推送接收设备的唯一标识 ID。默认情况下,注册推送服务成功时自动生成该 ID,同时也支持您自定义设置。您可根据 RegistrationID 向指定设备推送消息。需要注意的是,卸载并重新安装设备会更改 RegistrationID,因此需要在注册推送服务之前调用 setRegistrationID 接口。 | |
在成功注册推送服务后,可通过调用 getRegistrationID 接口获取推送接收设备的唯一标识 ID,即RegistrationID。您可根据 RegistrationID 向指定设备推送消息。 |
统计 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
关闭插件自动注册推送服务,需要在登录之前调用。
注意:
用法:
[TIMPush disableAutoRegisterPush];
+ (void)registerPush:(int) sdkAppId appKey:(NSString *) appKey succ:(TIMPushSuccessCallback) successCallback fail:(TIMPushFailedCallback) failedCallback NS_EXTENSION_UNAVAILABLE_IOS("This API is not supported in App Extension");
注册离线推送服务 (注册推送服务需要的信息来自您 AppDelegate 实现的 TIMPushDelegate 协议的 offlinePushCertificateID )
参数说明:
参数 | 描述 | 获取路径 |
sdkAppId | IM 控制台为您分配的应用 ID | |
appKey | IM 控制台为您分配的客户端密钥 | |
+ (void)setRegistrationID:(NSString *)registrationID callback: (TIMPushCallback) callback;
设置注册离线推送服务使用的推送 ID 标识,即 RegistrationID,需要在注册推送服务之前调用。
参数说明:
参数 | 描述 |
registrationID | 设备的推送标识 ID,卸载重装会改变。 |
+ (void)getRegistrationID:(TIMPushValueCallback) callback;
注册离线推送服务成功后,获取推送 ID 标识,即 RegistrationID。
+ (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);}];}