iOS

最近更新时间:2024-09-24 14:47:21

我的收藏

接口概览

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

API
描述
注册推送服务 (必须在 App 用户同意了隐私政策后,再调用该接口使用推送服务)。
反注册关闭推送服务。
RegistrationID 是推送接收设备的唯一标识 ID。默认情况下,注册推送服务成功时自动生成该 ID,同时也支持您自定义设置。您可根据 RegistrationID 向指定设备推送消息。需要注意的是,卸载并重新安装设备会更改 RegistrationID,因此需要在注册推送服务之前调用 setRegistrationID 接口。
在成功注册推送服务后,可通过调用 getRegistrationID 接口获取推送接收设备的唯一标识 ID,即RegistrationID。您可根据 RegistrationID 向指定设备推送消息。
添加 Push 监听器
移除 Push 监听器

统计 TIMPush 的推送抵达率

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

接口详情

函数说明

+ (void)registerPush:(int) sdkAppId inAppKey:(NSString *) appKey succ:(TIMPushSuccessCallback) successCallback fail:(TIMPushFailedCallback) failedCallback;

注册推送服务 (注册推送服务需要的信息来自您 AppDelegate 实现的 TIMPushDelegate 协议的 offlinePushCertificateID )
参数说明:
参数
描述
获取路径
sdkAppId
IM 控制台为您分配的应用 ID。


appKey
IM 控制台为您分配的客户端密钥。
代码示例:
const int sdkAppId = 您的 sdkAppId;
static const NSString *appKey = @"客户端密钥";

[TIMPushManager registerPush:sdkAppId appKey:appKey succ:^(NSData * _Nonnull deviceToken) {
//
} fail:^(int code, NSString * _Nonnull desc) {
//error
}];

+ (void)unRegisterPush:(TIMPushCallback) successCallback fail:(TIMPushFailedCallback) failedCallback;

反注册关闭推送服务
代码示例:
[TIMPushManager unRegisterPush:^{
//success
} fail:^(int code, NSString * _Nonnull desc) {
//error
}];

+ (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 的推送抵达率
1. 您需要在 AppDelegate.m 文件中实现 `- applicationGroupID` 方法,返回 App Group ID。
2. 并在 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信息
示例代码:

@implementation NotificationService

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
//appGroup 标识当前主 APP 和 Extension 之间共享的 APP Group,需要在主 APP 的 Capability 中配置 App Groups 能力。
//格式为group + [主bundleID]+ key
//如group.com.tencent.im.pushkey
NSString * appGroupID = kTIMPushAppGorupKey;
__weak typeof(self) weakSelf = self;
[TIMPushManager 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);
}];
}

@end

+ (void)addPushListener:(id<TIMPushListener>)listener

添加 Push 监听器。

+ (void)removePushListener:(id<TIMPushListener>)listener

移除 Push 监听器。