iOS
Note:
If you need to use products like Chat, CallKit, RoomKit, LiveKit simultaneously, please refer to IM Quick Integration Solution.
Step 1. Integrate TIMPush
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 'TXIMSDK_Plus_iOS_XCFramework'pod '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 a certificate to the IM console, the IM console will assign a certificate ID to 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 {// Certificate ID provided by the back console, e.g., 1234567int kBusinessID = 1234567;return kBusinessID;}- (NSString *)applicationGroupID {//AppGroup IDreturn kTIMPushAppGroupKey;}- (BOOL)onRemoteNotificationReceived:(NSString *)notice {// custom navigatereturn NO;}
Step 3: Register for Push
After the push registration is successful through the API call, offline push notifications can be received.
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) {}];
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 can receive remote push notifications when the app is moved to the background or the process is killed.
Step 4: Send push notifications
Step 5: Click Custom Redirect after 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}
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;}
Step 6: Push Arrival Rate Statistics
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 = 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
Note:
1. To report push delivery data, enable the mutable-content switch to support iOS 10's extension feature.
2. Data details can be viewed on the Push Data Page. The Push Data Page can only be used after purchasing the Push Plugin.
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.