tencent cloud

Feedback

Last updated: 2024-08-07 15:59:19
    If you want to access the TIMPush component as simply as possible, you need to use the TUILogin login/logout interface for IM account sign-in/sign-out operations. The TIMPush component can automatically detect sign-in/sign-out 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 frameworks
    use_frameworks!
    use_modular_headers!
    # Pods for Example
    pod 'TIMPush', '8.0.6897'
    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 the 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 will allocate a Certificate ID for you, as shown below:
    
    
    
    2. You need to implement the - offlinePushCertificateID protocol method in AppDelegate to return the Certificate ID.
    #pragma mark - TIMPush
    
    - (int)offlinePushCertificateID {
    return kAPNSBusiId;
    }
    
    - (NSString *)applicationGroupID {
    return kTIMPushAppGorupKey;
    }
    
    - (void)navigateToBuiltInChatViewController:(NSString *)userID groupID:(NSString *)groupID {
    // custom navigate
    }
    Thus, you have completed the basic integration of the push notification feature.
    Note:
    1. When you log in and see the 'APNs configuration success' log printed on the console, it indicates a successful integration.
    2. If your App has already obtained push permissions, you can receive remote push notifications when the app is sent to the background or the process is killed.
    3. If you have not integrated the TUICore component, do not need to use TUILogin's log in/out, but still want to implement offline push notifications, you only need to:
    Call [TIMPush disableAutoRegisterPush].
    After completing log in to your App/IM, actively call the registerPush method to register for push notifications.
    When exiting log in to, actively call the unRegisterPush method to unregister push notifications.

    Step 3: Set offline push parameters when sending messages (this step can be skipped if integrated with UI, as TUIChat has already added this by default)

    When calling sendMessage to send messages, you can use V2TIMOfflinePushInfo to set offline push parameters. Use ext in V2TIMOfflinePushInfo to set custom Definition ext data, so when users receive an offline push and start the App, they can retrieve the ext field in the callback of the click notification, and then navigate to the specified UI interface based on the content of the ext field. For more information, see the sendMessage: method in 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 for Android compatibility and need to be filled in
    pushInfo.AndroidOPPOChannelID = @"tuikit";
    pushInfo.AndroidSound = TUIConfig.defaultConfig.enableCustomRing ? @"private_ring" : nil;
    pushInfo.AndroidHuaWeiCategory = @"IM";
    pushInfo.AndroidVIVOCategory = @"IM";

    Step 4: Customize the redirect after clicking an offline push

    1. If you need to customize the parsing of the received remote push, you need to implement the - onRemoteNotificationReceived method in the AppDelegate.m file.
    #pragma mark - TIMPush
    - (BOOL)onRemoteNotificationReceived:(NSString *)notice {
    //- If you return YES, TIMPush will not execute the built-in TUIKit offline push parsing logic, leaving it entirely up to you;
    //NSString *ext = notice;
    //OfflinePushExtInfo *info = [OfflinePushExtInfo createWithExtString:ext];
    //return YES;
    //- If you return NO, TIMPush will continue to execute the built-in TUIKit offline push parsing logic and will callback the - navigateToBuiltInChatViewController:groupID: method.
    return NO;
    }
    2. If you want to use the built-in TUIChat push parsing logic and redirect 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 Push Arrival Rate

    1. If you need to collect data on the arrival and clicks of push notifications, you should implement the - applicationGroupID method in the AppDelegate.m file, returning the App Group ID (For the generation method, see Manufacturer Configuration-Generate App GroupID).
    2. Call the Push Arrival Rate Statistics Function in the Notification Service Extension's -didReceiveNotificationRequest:withContentHandler: method:
    @implementation NotificationService
    
    - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
    //appGroup identifies the APP Group shared between the main APP and Extension, which needs to be configured in the main APP's Capability under App Groups.
    //The format is group + [Main Bundle ID] + key
    //For example, group.com.tencent.im.pushkey
    NSString * appGroupID = kTIMPushAppGorupKey;
    __weak typeof(self) weakSelf = self;
    [TIMPush 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);
    }];
    }
    Note:
    1. To report push reach data, you need to enable the mutable-content switch to support the Extension feature of iOS 10.
    
    
    
    2. Data details can be viewed on the Push Data Page, which is exclusively available after purchasing the Push Plugin.

    About Compliance

    TIMPush will not perform any operations before you actively call registerPush, complying with relevant regulations.
    If you use TUILogin to log in and log out, TIMPush will internally automatically call registerPush or unRegisterPush.
    Congratulations on integrating the push plugin. Please note: after the trial or purchase of the message push plugin expires, the push service will automatically cease (including ordinary message offline push, pushing to all users, etc.). To avoid affecting your business's normal use, please purchase/renew in advance.

    About All-staff/Tag Push

    All-staff/Tag Push supports sending specific content and can also send personalized content to specific user groups based on Tags and attributes, for example, membership activities, regional notifications, etc. This helps in user acquisition, conversion, activation promotion, and other operational phases, while also supporting push delivery reports and self-service push troubleshooting tools.
    For more detailed content, it is recommended to consult All-staff/Tag Push
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support