target 'YourAppName' do# Uncommment the next line if you're using Swift or would like to use dynamic frameworksuse_frameworks!use_modular_headers!# Pods for Examplepod 'TIMPush', 'VERSION'end
pod install# If you cannot install the latest version of TUIKit, run the following command to update your local CocoaPods repository list.pod repo update

- businessID protocol method in AppDelegate to return the certificate ID.#pragma mark - TIMPush- (int)businessID {//ThebusinessIDID obtained in the previous step in the console, such as 1234567int kBusinessID = 0;return kBusinessID;}- (NSString *)applicationGroupID {//AppGroup IDreturn kTIMPushAppGroupKey;}- (BOOL)onRemoteNotificationReceived:(NSString *)notice {// custom navigatereturn NO;}
#pragma mark - TIMPush//Swift must carry the @objc keyword@objc func businessID() -> Int32 {//The businessID ID given by the console in the previous stepreturn 0}@objc func applicationGroupID() -> String {//AppGroup IDreturn "group.com.yourcompony.pushkey"}@objc func onRemoteNotificationReceived(_ notice: String?) -> Bool {// custom navigatereturn false}
#import <TUICore/OfflinePushExtInfo.h>V2TIMOfflinePushInfo *pushInfo = [[V2TIMOfflinePushInfo alloc] init];pushInfo.title = @"Push title";pushInfo.desc = @"Push content";BOOL isGroup = groupID.length > 0;NSString *senderId = isGroup ? (groupID) : ([TUILogin getUserID]);NSString *nickName = isGroup ? (conversationData.title) : ([TUILogin getNickName] ?: [TUILogin getUserID]);OfflinePushExtInfo *extInfo = [[OfflinePushExtInfo alloc] init];OfflinePushExtBusinessInfo * entity = extInfo.entity;entity.action = 1;entity.content = @"Push content";entity.sender = senderId;entity.nickname = nickName;entity.faceUrl = [TUILogin getFaceUrl] ?: @"";entity.chatType = [isGroup ? @(V2TIM_GROUP) : @(V2TIM_C2C) integerValue];entity.version = kOfflinePushVersion;pushInfo.ext = [extInfo toReportExtString];//The following fields are compatible with Android and need to be filled inpushInfo.AndroidOPPOChannelID = @"tuikit";pushInfo.AndroidSound = TUIConfig.defaultConfig.enableCustomRing ? @"private_ring" : nil;pushInfo.AndroidHuaWeiCategory = @"IM";pushInfo.AndroidVIVOCategory = @"IM";
import TIMPushimport TUICoreimport ImSDK_Pluslet pushInfo = V2TIMOfflinePushInfo()pushInfo.title = "Push title"pushInfo.desc = "Push content"let isGroup = groupID!.count > 0let senderId = isGroup ? groupID : TUILogin.getUserID()let nickName = isGroup ? "conversationData Title" : (TUILogin.getNickName() ?? TUILogin.getUserID())let extInfo = OfflinePushExtInfo()let entity = extInfo.entityentity.action = 1entity.content = "Push content"entity.sender = senderId ?? ""entity.nickname = nickName ?? ""entity.faceUrl = TUILogin.getFaceUrl() ?? ""entity.chatType = isGroup ? Int(V2TIMConversationType.GROUP.rawValue) : Int(V2TIMConversationType.C2C.rawValue)entity.version = 1pushInfo.ext = extInfo.toReportExtString()//The following fields are compatible with Android and need to be filled inpushInfo.androidOPPOChannelID = "tuikit"pushInfo.androidSound = TUIConfig.default().enableCustomRing ? "private_ring" : nilpushInfo.androidHuaWeiCategory = "IM"pushInfo.androidVIVOCategory = "IM"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[TIMPushManager addPushListener:self];return YES;}#pragma mark - TIMPushListener- (void)onNotificationClicked:(NSString *)ext {// Getting ext for Definition redirect}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {// Override point for customization after application launch.TIMPushManager.addPushListener(listener: self)return true}@objc func onNotificationClicked(_ ext: String) {//Clicked}@objc func onRecvPushMessage(_ message: TIMPushMessage) {//onRecvPushMessage}@objc func onRevokePushMessage(_ messageID: String) {//onRevokePushMessage}
- onRemoteNotificationReceived method in the AppDelegate.m file.#pragma mark - TIMPush- (BOOL)onRemoteNotificationReceived:(NSString *)notice {//- If YES is returned, TIMPush will not execute the built-in TUIKit offline push parsing logic, leaving it entirely to you to handle.//NSString *ext = notice;//OfflinePushExtInfo *info = [OfflinePushExtInfo createWithExtString:ext];//return YES;//- If NO is returned, TIMPush will continue to execute the built-in TUIKit offline push parsing logic and continue to callback - navigateToBuiltInChatViewController:groupID: method.return NO;}
@objc func onRemoteNotificationReceived(_ notice: String) -> Bool {//- If YES is returned, TIMPush will not execute the built-in TUIKit offline push parsing logic, leaving it entirely to you to handle.// let ext = notice// let info = OfflinePushExtInfo.create(withExtString: ext)// return true//- If false is returned, TIMPush will continue to execute the built-in TUIKit offline push parsing logic and continue to callback - navigateToBuiltInChatViewController:groupID: method.return false}
- applicationGroupID method in the AppDelegate.m file and return the App Group ID (the generation method can be referred to in Vendor Configuration - Generating App Group ID).- didReceiveNotificationRequest:withContentHandler: method, call the push reach rate statistics function:@implementation NotificationService- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {//appGroup identifies the app group shared between the main app and extension. It needs to be configured in the App Groups capability of the main app.//Format: group + [mainBundleID] + key//E.g., group.com.tencent.im.pushkeyNSString * appGroupID = kTIMPushAppGroupKey;__weak typeof(self) weakSelf = self;[TIMPushManager handleNotificationServiceRequest:request appGroupID: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
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {self.contentHandler = contentHandlerbestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)//appGroup identifies the app group shared between the main app and extension. It needs to be configured in the App Groups capability of the main app.//Format: group + [mainBundleID] + key//E.g., group.com.tencent.im.pushkeyTIMPushManager.handleNotificationServiceRequest(request: request, appGroupID: "appGroupID") {[weak self] content inif let bestAttemptContent = self?.bestAttemptContent {// Modify the notification content here...bestAttemptContent.title = "\\(bestAttemptContent.title) [modified]"contentHandler(bestAttemptContent)}}}

Feedback