logout
API is called to log out proactively or you are forced to log out due to multi-device login, you cannot receive offline push messages even though IM offline push is enabled.Push Notification
service to your existing AppID.Bundle ID
cannot contain the wildcard *
. Otherwise, you will be unable to use the remote push service.Bundle ID
and other information. Click Continue.Certificate Signing Request (CSR)
is required.*.certSigningRequest
file.Apple Developer
page shown in step 3 and click Choose File to upload the *.certSigningRequest
file.Development SSL Certificate
locally.Sandbox
and Production
merged certificate that applies to both the development and production environments.Apple Development IOS Push Service
) and production environment (Apple Push Services
).// Request deviceToken from the Apple backend- (void)registNotification{if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)categories:nil]];[[UIApplication sharedApplication] registerForRemoteNotifications];}else{[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];}}// The callback of AppDelegate returns deviceToken, which needs to be reported to the Tencent Cloud backend after login.-(void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{// Note the deviceToken returned by Apple._deviceToken = deviceToken;}
- (void)push_registerIfLogined:(NSString *)userID{NSLog(@"[PUSH] %s, %@", __func__, userID);BOOL supportTPNS = NO;if ([self respondsToSelector:@selector(supportTPNS:)]) {supportTPNS = [self supportTPNS:userID];}if (self.deviceToken) {V2TIMAPNSConfig *confg = [[V2TIMAPNSConfig alloc] init];/* Users need to register a developer certificate with Apple, download and generate the certificate (P12 file) in their developer accounts, and upload the generated P12 file to the Tencent certificate console. The console will automatically generate a certificate ID and pass it to the `businessID` parameter.*/// Push certificate IDconfg.businessID = sdkBusiId;confg.token = self.deviceToken;[[V2TIMManager sharedInstance] setAPNS:confg succ:^{NSLog(@"%s, succ, %@", __func__, supportTPNS ? @"TPNS": @"APNS");} fail:^(int code, NSString *msg) {NSLog(@"%s, fail, %d, %@", __func__, code, msg);}];}// ...}
Nickname
indicates the sender's nickname. If no nickname is specified, only content is displayed.Nickname: Content
Name
is: sender's Group name card
> Group nickname
. If neither is available, no name is displayed.Name (group name): Content
Elem
in the message body. The display of different Elem
in offline messages is shown in the following table.Parameter | Description |
Text Elem | Directly display the content |
Audio Elem | Display [audio] |
File Elem | Display [file] |
Image Elem | Display [image] |
Custom Elem |
SDKAppID
to the same value for the apps.// 1. Configure listening- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Listen for push messages[V2TIMManager.sharedInstance setAPNSListener:self];// Listen for the unread message counts of conversations[[V2TIMManager sharedInstance] setConversationListener:self];return YES;}// 2. When the unread message count changes, save the new unread message count- (void)onTotalUnreadMessageCountChanged:(UInt64)totalUnreadCount {self.unreadNumber = totalUnreadCount;}// 3. The app goes to the background and reports the custom unread message count/** After the app goes to the background, customize the unread message count of the app. If you do not customize the unread message count, the sum of the unread message counts of all conversations is used as the unread message count of the app.* <pre>** - (uint32_t)onSetAPPUnreadCount {* return 100; // Custom unread message count* }** </pre>*/- (uint32_t)onSetAPPUnreadCount {// 1. Get the custom badge numberuint32_t customBadgeNumber = ...// 2. Add the unread message count of IMcustomBadgeNumber += self.unreadNumber;// 3. Use the IM SDK to report to the IM serverreturn customBadgeNumber;}
iOSSound
field in offlinePushInfo to the name of the audio file.iOSSound
is kIOSOfflinePushNoSound
, no sound is played when a push message is received. iOSSound
is kIOSOfflinePushDefaultSound
, the system alert sound is played when a push message is received. iOSSound
, link the audio file to the Xcode project and set iOSSound
to the audio filename (with the extension name).V2TIMOfflinePushInfo *pushInfo = [[V2TIMOfflinePushInfo alloc] init];pushInfo.title = @"push title";pushInfo.iOSSound = @"phone_ringing.mp3"; // Name of your audio file[[V2TIMManager sharedInstance] sendMessage:msg receiver:receiver groupID:groupID priority:V2TIM_PRIORITY_DEFAULT onlineUserOnly:NO offlinePushInfo:pushInfo progress:nil succ:^{} fail:^(int code, NSString *msg) {}];
AndroidSound
field in offlinePushInfo to the name of the audio file.AndroidSound
, you need to place the audio file to the raw
directory of the Android project and set the audio file name (without the file extension) as the value of AndroidSound
.V2TIMOfflinePushInfo *pushInfo = [[V2TIMOfflinePushInfo alloc] init];pushInfo.title = @"push title";pushInfo.AndroidSound = @"phone_ringing"; // your voice file's name[[V2TIMManager sharedInstance] sendMessage:msg receiver:receiver groupID:groupID priority:V2TIM_PRIORITY_DEFAULT onlineUserOnly:NO offlinePushInfo:pushInfo progress:nil succ:^{} fail:^(int code, NSString *msg) {}];
title
and desc
fields of offlinePushInfo when calling sendMessage to send messages. Once set, the title
content will be added to the default push content and desc
will be displayed as the push content.V2TIMOfflinePushInfo *info = [[V2TIMOfflinePushInfo alloc] init];info.title = @"Harvy"; // Offline push display titleinfo.desc = @"You have a call invitation."; // Offline push display content// `receiver` and `groupID` cannot empty at the same time, and only one of them can be set.[[V2TIMManager sharedInstance] sendMessage:msg receiver:receiver groupID:groupID priority:V2TIM_PRIORITY_DEFAULT onlineUserOnly:NO offlinePushInfo:pushInfo progress:nil succ:^{} fail:^(int code, NSString *msg) {}];
multable-content
field of APNs and NSNotification Service Extension
to customize the display content. If you have any questions or feedback, feel free to contact us.ext
field in V2TIMOfflinePushInfo. When the user receives an offline push message and starts the app, the ext
field can be obtained from the AppDelegate -> didReceiveRemoteNotification
system callback, and the user is redirected to the UI as specified by ext
. ext
before sending a message.// Denny sets `offlinePushInfo` and specifies `ext` before sending a messageV2TIMMessage *msg = [[V2TIMManager sharedInstance] createTextMessage:@"Text message"];V2TIMOfflinePushInfo *info = [[V2TIMOfflinePushInfo alloc] init];info.ext = @"jump to denny";[[V2TIMManager sharedInstance] sendMessage:msg receiver:@"vinson" groupID:nil priority:V2TIM_PRIORITY_DEFAULTonlineUserOnly:NO offlinePushInfo:info progress:^(uint32_t progress) {} succ:^{} fail:^(int code, NSString *msg) {}];
// Vinson receives the following callback when the app is started.- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfofetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {// Resolve the extension field `desc`.if ([userInfo[@"ext"] isEqualToString:@"jump to denny"]) {// Go to the chat window with Denny.}}
deviceToken
from Apple might fail. Please switch to the production environment to solve the problem.desc
field in offlinePushInfo during sendMessage, and the desc
information will be displayed by default during push.config
parameter of the setAPNS API to nil
. This feature is supported from v5.6.1200.deviceToken
is related to the current compilation environment. If the certificate ID used to upload deviceToken to Tencent Cloud after logging in to IM SDK is inconsistent with the environment token, the error will be reported.Release
, - application:didRegisterForRemoteNotificationsWithDeviceToken:
calls back the release environment token, businessID
must be set to the certificate ID of the production environment.Debug
, - application:didRegisterForRemoteNotificationsWithDeviceToken:
calls back the development environment token, businessID
must be set to the certificate ID of the development environment.V2TIMAPNSConfig *confg = [[V2TIMAPNSConfig alloc] init];/* Users need to register a developer certificate with Apple, download and generate the certificate (P12 file) in their developer accounts, and upload the generated P12 file to the Tencent certificate console. The console will automatically generate a certificate ID and pass it to the `businessID` parameter.*/// Push certificate IDconfg.businessID = sdkBusiId;confg.token = self.deviceToken;[[V2TIMManager sharedInstance] setAPNS:confg succ:^{NSLog(@"%s, succ, %@", __func__, supportTPNS ? @"TPNS": @"APNS");} fail:^(int code, NSString *msg) {NSLog(@"%s, fail, %d, %@", __func__, code, msg);}];
deviceToken
is not returned for registration occasionally or APNs' request for token fails in the iOS development environment?
Was this page helpful?