Quick Integration
If you want to integrate the TIMPush component as simply as possible, you need to use the login/logout interfaces of TUILogin for IM account login/logout operations. The TIMPush component can automatically detect login/logout events.
Step 1. Integrate the TIMPush component
1. The TIMPush component supports CocoaPods integration. You need to add the component dependencies in the Podfile.
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
2. Run the following command to install the TIMPush component.
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
Step 2. Set push parameters
1. After you upload the certificate to the IM console, the IM console allocates a certificate ID for you, as shown below:
2. You need to implement the
- businessID
protocol method in AppDelegate to return the certificate ID.#pragma mark - TIMPush- (int)businessID {//The certificate ID obtained in the previous step in the console, such as 1234567int kBusinessID = 1234567;return kBusinessID;}- (NSString *)applicationGroupID {return kTIMPushAppGorupKey;}- (void)navigateToBuiltInChatViewController:(NSString *)userID groupID:(NSString *)groupID {// custom navigate}
At this point, you have completed the basic push feature integration.
Note:
1. After you log in, when you see the APNs configuration success log printed on the console, it indicates that the integration is successful.
2. If your app has obtained push permissions, you will receive remote push notifications when it goes to the background or the process is stopped.
3. If you have not integrated the TUICore component and do not need to use TUILogin for login/logout but still want to implement offline push, you only need to:
After your app/IM login is complete, actively call the registerPush method to register for push notifications.
When logging out, actively call the unRegisterPush method to unregister push notifications.
4. If you only want to support push notifications without login, you can switch the registration interface to: call the registerPush interface of TIMPushManager. For details on sending messages in step 3, see - restApi interface.
Step 3. Set offline push parameters when sending messages (TUIChat has already added this by default when integrating with UI, you can skip this step)
When calling sendMessage to send messages, you can set offline push parameters through V2TIMOfflinePushInfo. Use the ext of V2TIMOfflinePushInfo to set custom ext data. When the user receives the offline push and launches the app, they can get the ext field in the callback of clicking the notification and then navigate to the specified UI based on the ext field content. Refer to the sendMessage: method of TUIMessageBaseDataProvider:
#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";
Step 4: Customize the tap-to-redirect logic for offline push
If you need to customize the parsing of received remote push notifications, you can implement it as follows:
Note:
It is recommended to place the registration callback timing in the didFinishLaunchingWithOptions function of the AppDelegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {[TIMPushManager addPushListener:self];return YES;}#pragma mark - TIMPushListener- (void)onNotificationClicked:(NSString *)ext {// Getting ext for Definition redirect}
1. If you need to customize the parsing of received remote push notifications, you need to implement the - 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;}
2. If you want to use the built-in TUIChat push parsing logic and navigate to the TUIChat chat page, you can implement the
- navigateToBuiltInChatViewController
method.#pragma mark - TIMPush- (void)navigateToBuiltInChatViewController:(NSString *)userID groupID:(NSString *)groupID {UITabBarController *tab = [self getMainController];if (![tab isKindOfClass: UITabBarController.class]) {// Logging in…return;}if (tab.selectedIndex != 0) {[tab setSelectedIndex:0];}self.window.rootViewController = tab;UINavigationController *nav = (UINavigationController *)tab.selectedViewController;if (![nav isKindOfClass:UINavigationController.class]) {return;}UIViewController *vc = nav.viewControllers.firstObject;if (![vc isKindOfClass:NSClassFromString(@"ConversationController")]&& ![vc isKindOfClass:NSClassFromString(@"ConversationController_Minimalist")]) {return;}if ([vc respondsToSelector:NSSelectorFromString(@"pushToChatViewController:userID:")]) {[vc performSelector:NSSelectorFromString(@"pushToChatViewController:userID:") withObject:groupID withObject:userID];}
Step 5: Statistics on push arrival rate
1. If you need to collect data on push delivery and click rates, you need to implement the
- 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).2. In the Notification Service Extension's
- 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 = kTIMPushAppGorupKey;__weak typeof(self) weakSelf = self;[TIMPushManager handleNotificationServiceRequest:request appGroupID:appGroupID callback:^(UNNotificationContent *content) {weakSelf.contentHandler = contentHandler;weakSelf.bestAttemptContent = [content mutableCopy];// Modify the notification content here...// self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];weakSelf.contentHandler(weakSelf.bestAttemptContent);}];}
Note:
To report push delivery data, enable the mutable-content switch to support iOS 10's extension feature.
Data details can be viewed on the Push Data Page. The Push Data Page can only be used after purchasing the Push Plugin.
About compliance
TIMPush will not perform any other operations before you actively call registerPush, in accordance with relevant regulations.
If you use TUILogin for login and logout, TIMPush will automatically call registerPush or unRegisterPush internally.
Congratulations on completing the integration of the Push Plugin. Please note: After the trial or purchase expiry of the Push Plugin, push services (including regular message offline push, all-staff push, etc.) will be automatically stopped. To avoid affecting the normal use of your business, please purchase/renew in advance.
Regarding All-staff/Tag Push
All-staff/Tag Push supports sending specific content, and also allows for the delivery of personalized content to specific user groups based on Tag, attribute, such as Membership Activities, Regional Notifications, etc. It aids in User Acquisition, Conversion, Activation Promotion, and other operational work phases, while also supporting Push Delivery Reports, Self-service Push Troubleshooting Tool. For more details, please see Effect Display.
Congratulations on completing the integration of the Push Plugin. Please note: After the trial or purchase expiry of the Push Plugin, push services (including regular message offline push, all-staff push, etc.) will be automatically stopped. To avoid affecting the normal use of your business, please purchase/renew in advance.
Note:
If you are unable to receive push notifications after integration, please first use the Troubleshooting Tool to check the specific reasons. Also, pay attention to the Vendor Message Classification Mechanism.
To view push indicator data, please use Statistics query.
For the All/Tag Push feature, please refer to: RESTful APIs - Initiate All/Tag Push.
- Step 1. Integrate the TIMPush component
- Step 2. Set push parameters
- Step 3. Set offline push parameters when sending messages (TUIChat has already added this by default when integrating with UI, you can skip this step)
- Step 4: Customize the tap-to-redirect logic for offline push
- Step 5: Statistics on push arrival rate
- About compliance
- Regarding All-staff/Tag Push