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 frameworks
use_frameworks!
use_modular_headers!
# Pods for Example
pod 'TXIMSDK_Plus_iOS_XCFramework'
# The version number "VERSION" can be obtained from the Update Log. pod 'TIMPush', 'VERSION'
end
2. Run the following command to install the TIMPush component.
pod install
pod repo update
Step 2. Set push parameters
1. After you upload a certificate to the Chat console, the Chat 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 {
int kBusinessID = 0;
return kBusinessID;
}
- (NSString *)applicationGroupID {
return kTIMPushAppGroupKey;
}
- (BOOL)onRemoteNotificationReceived:(NSString *)notice {
return NO;
}
#pragma mark - TIMPush
@objc func businessID() -> Int32 {
return 0
}
@objc func applicationGroupID() -> String {
return "group.com.yourcompony.pushkey"
}
@objc func onRemoteNotificationReceived(_ notice: String?) -> Bool {
return false
}
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) {
}];
let sdkAppId: Int = 0
let appKey: String = "Client Key"
TIMPushManager.registerPush(Int32(sdkAppId), appKey: appKey, succ: { deviceToken in
}, fail: { code, desc in
})
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:
Custom click redirect implementation
Custom click redirect implementation (old solution)
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 {
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
TIMPushManager.addPushListener(listener: self)
return true
}
@objc func onNotificationClicked(_ ext: String) {
}
@objc func onRecvPushMessage(_ message: TIMPushMessage) {
}
@objc func onRevokePushMessage(_ messageID: String) {
}
You need to implement the - onRemoteNotificationReceived
method in the AppDelegate.m file.
#pragma mark - TIMPush
- (BOOL)onRemoteNotificationReceived:(NSString *)notice {
return NO;
}
@objc func onRemoteNotificationReceived(_ notice: String) -> Bool {
return false
}
Step 6: Push Arrival Rate Statistics
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 {
NSString * appGroupID = kTIMPushAppGroupKey;
__weak typeof(self) weakSelf = self;
[TIMPushManager handleNotificationServiceRequest:request appGroupID:appGroupID callback:^(UNNotificationContent *content) {
weakSelf.bestAttemptContent = [content mutableCopy];
weakSelf.contentHandler(weakSelf.bestAttemptContent);
}];
}
@end
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
TIMPushManager.handleNotificationServiceRequest(request: request, appGroupID: "appGroupID") {
[weak self] content in
if let bestAttemptContent = self?.bestAttemptContent {
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
contentHandler(bestAttemptContent)
}
}
}
Note:
1. To report push delivery data, enable the mutable-content switch to support iOS 10's extension feature.
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.