Push Notification
的 Service
。Bundle ID
不能使用通配符 *
,否则将无法使用远程推送服务。Bundle ID
等其他信息,单击【Continue】进行下一步。SSL Certificate
,分别用于开发环境(Development
)和生产环境(Production
)的远程推送证书,如下图所示:Development
)的【Create Certificate】,系统将提示我们需要一个 Certificate Signing Request(CSR)
。Keychain Access - Certificate Assistant - Request a Certificate From a Certificate Authority
)。*.certSigningRequest
文件。Apple Developer
网站刚才的页面,单击【Choose File】上传生成的*.certSigningRequest
文件。Development SSL Certificate
到本地。
Production SSL Certificate
下载到本地。SSL Certificate
,系统会将其导入钥匙串中。Apple Development IOS Push Service
)和生产环境(Apple Push Services
)的 P12
文件。P12
文件时,请务必要为其设置密码。// 向苹果后台请求 DeviceToken- (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)];}}//在 AppDelegate 的回调中会返回 deviceToken,需要在登录后上报给腾讯云后台-(void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{//记录下 Apple 返回的 deviceToken_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];/* 用户自己到苹果注册开发者证书,在开发者帐号中下载并生成证书(p12 文件),将生成的 p12 文件传到腾讯证书管理控制台,控制台会自动生成一个证书 ID,将证书 ID 传入以下 busiId 参数中。*///推送证书 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);}];}// ...}
昵称:内容
群名片
>昵称
,如果都没有,则不展示。名称(群名):内容
Elem
内容组成,不同 Elem
的离线消息展示效果如下表所示。参数 | 说明 |
文本 Elem | 直接显示内容 |
语音 Elem | 显示 [语音] |
文件 Elem | 显示 [文件] |
图片 Elem | 显示 [图片] |
自定义 Elem |
SDKAppID
设置为相同值。// 1. 设置监听- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// 监听推送[V2TIMManager.sharedInstance setAPNSListener:self];// 监听会话的未读数[[V2TIMManager sharedInstance] setConversationListener:self];return YES;}// 2. 未读数发生变化后保存未读数- (void)onTotalUnreadMessageCountChanged:(UInt64)totalUnreadCount {self.unreadNumber = totalUnreadCount;}// 3. App 推到后台后上报自定义未读数/** 程序进后台后,自定义 App 的未读数,如果不处理,App 未读数默认为所有会话未读数之和* <pre>** - (uint32_t)onSetAPPUnreadCount {* return 100; // 自定义未读数* }** </pre>*/- (uint32_t)onSetAPPUnreadCount {// 1. 获取自定义的角标uint32_t customBadgeNumber = ...// 2. 加上 IM 的消息未读数customBadgeNumber += self.unreadNumber;// 3. 通过 IMSDK 上报给 IM 服务器return customBadgeNumber;}
V2TIMOfflinePushInfo *pushInfo = [[V2TIMOfflinePushInfo alloc] init];pushInfo.title = @"push title";pushInfo.iOSSound = @"phone_ringing.mp3"; // 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) {}];
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
和 desc
字段,其中 title
设置后,会在默认的推送内容上多展示 title
内容,desc
设置后,推送内容会变成 desc
内容。V2TIMOfflinePushInfo *info = [[V2TIMOfflinePushInfo alloc] init];info.title = @"Harvy"; // 离线推送展示的标题。info.desc = @"You hava a call invitation."; // 离线推送展示的内容// receiver 和 groupID 不能同时为空,且同时只能有一个存在[[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
字段,结合 NSNotification Service Extension
来自定义显示内容。欢迎加入 QQ 群进行技术交流和反馈问题,QQ 群:592465424。ext
字段,当用户收到离线推送启动 App 的时候,可以在 AppDelegate -> didReceiveRemoteNotification
系统回调获取到 ext
字段,然后根据 ext
字段内容跳转到指定的 UI 界面。ext
:// denny在发送消息时设置 offlinePushInfo,并指定 ext 字段V2TIMMessage *msg = [[V2TIMManager sharedInstance] createTextMessage:@"文本消息"];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 启动 APP 后会收到以下回调- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfofetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {// 解析推送扩展字段 descif ([userInfo[@"ext"] isEqualToString:@"jump to denny"]) {//跳转到和 denny 的聊天界面}}
deviceToken
可能会失败,生产环境暂时没有发现这个问题,请切换到生产环境测试。desc
字段,推送的时候会默认展示 desc
信息。- application:didRegisterForRemoteNotificationsWithDeviceToken:
回调返回的是发布环境的 token,此时 businessID 需要设置生产环境的证书ID。- application:didRegisterForRemoteNotificationsWithDeviceToken:
回调返回的是开发环境的 token,此时 businessID 需要设置开发环境的证书ID。V2TIMAPNSConfig *confg = [[V2TIMAPNSConfig alloc] init];/* 用户自己到苹果注册开发者证书,在开发者帐号中下载并生成证书(p12 文件),将生成的 p12 文件传到腾讯证书管理控制台,控制台会自动生成一个证书 ID,将证书 ID 传入以下 busiId 参数中。*///推送证书 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);}];
本页内容是否解决了您的问题?