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 'TXIMSDK_Plus_iOS_XCFramework'pod '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 {//businessIDprovided by the back consoleint 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 {// Certificate ID provided by the back consolereturn 0}@objc func applicationGroupID() -> String {//AppGroup IDreturn "group.com.yourcompony.pushkey"}@objc func onRemoteNotificationReceived(_ notice: String?) -> Bool {// custom navigatereturn false}
const int sdkAppId = your sdkAppId;static const NSString *appKey = @"Client Key";[TIMPushManager registerPush:sdkAppId appKey:appKey succ:^(NSData * _Nonnull deviceToken) {} fail:^(int code, NSString * _Nonnull desc) {}];
let sdkAppId: Int = 0let appKey: String = "Client Key"TIMPushManager.registerPush(Int32(sdkAppId), appKey: appKey, succ: { deviceToken in// success}, fail: { code, desc in// failed})
- (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 arrival 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)}}}

masukan