环信的推送
来源:互联网 发布:jamp软件 编辑:程序博客网 时间:2024/05/03 20:46
今天花了一天的时间,终于将推送给弄出来了,最悲催的是,做完后,才发现真的很容易,步骤如下
1.先创建一个apns证书,链接如下
http://developer.easemob.com/docs/emchat/ios/push/certificate.html
创建完证书后,将证书弄成p12文件,然后上传到环信后台
2.再创建真机调试证书,和描述文件,保证能进行真机调试。并且appid要又推送功能
3.绑定环信证书和appkey
//注册 APNS文件的名字,需要与后台上传证书时的名字一一对应
NSString *apnsCertName = @"chatdemo";
[[EaseMobsharedInstance] registerSDKWithAppKey:@“4545521”apnsCertName:apnsCertName];
[[EaseMobsharedInstance] enableBackgroundReceiveMessage];
[[EaseMobsharedInstance] application:applicationdidFinishLaunchingWithOptions:launchOptions];
4.然后实现环信的几个方法
// 收到消息回调
-(void)didReceiveMessage:(EMMessage *)message{
#if !TARGET_IPHONE_SIMULATOR
[selfplaySoundAndVibration];
BOOL isAppActivity = [[UIApplicationsharedApplication] applicationState] ==UIApplicationStateActive;
if (!isAppActivity) {
[selfshowNotificationWithMessage:message];
}
#endif
}
- (void)playSoundAndVibration{
//如果距离上次响铃和震动时间太短,则跳过响铃
NSLog(@"%@, %@", [NSDatedate], self.lastPlaySoundDate);
NSTimeInterval timeInterval = [[NSDatedate]
timeIntervalSinceDate:self.lastPlaySoundDate];
if (timeInterval <kDefaultPlaySoundInterval) {
return;
}
//保存最后一次响铃时间
self.lastPlaySoundDate = [NSDatedate];
// 收到消息时,播放音频
[[EaseMobsharedInstance].deviceManagerasyncPlayNewMessageSound];
// 收到消息时,震动
[[EaseMobsharedInstance].deviceManagerasyncPlayVibration];
}
- (void)showNotificationWithMessage:(EMMessage *)message{
id<IEMMessageBody> messageBody = [message.messageBodiesfirstObject];
NSString *messageStr = nil;
switch (messageBody.messageBodyType) {
caseeMessageBodyType_Text:
{
messageStr = ((EMTextMessageBody *)messageBody).text;
}
break;
caseeMessageBodyType_Image:
{
messageStr = @"[图片]";
}
break;
caseeMessageBodyType_Location:
{
messageStr = @"[位置]";
}
break;
caseeMessageBodyType_Voice:
{
messageStr = @"[音频]";
}
break;
caseeMessageBodyType_Video:{
messageStr = @"[视频]";
}
break;
default:
break;
}
//发送本地推送
UILocalNotification *notification = [[UILocalNotificationalloc] init];
notification.fireDate = [NSDatedate]; //触发通知的时间
NSString *title = message.from;
if (message.isGroup) {
NSArray *groupArray = [[EaseMobsharedInstance].chatManager groupList];
for (EMGroup *groupin groupArray) {
if ([group.groupIdisEqualToString:message.conversation.chatter]) {
title = [NSString stringWithFormat:@"%@(%@)", message.groupSenderName, group.groupSubject];
break;
}
}
}
notification.alertBody = [NSStringstringWithFormat:@"%@:%@", title, messageStr];
notification.alertAction = @"打开";
notification.timeZone = [NSTimeZonedefaultTimeZone];
notification.soundName =UILocalNotificationDefaultSoundName;
//发送通知
[[UIApplicationsharedApplication] scheduleLocalNotification:notification];
UIApplication *application = [UIApplicationsharedApplication];
application.applicationIconBadgeNumber +=1;
}
这样就可以进行消息推送了- 环信的推送
- 环信app的推送功能实现
- 环信推送
- 环信推送详解
- 接收微信的推送
- 接收微信的推送
- 环信接收消息本地推送的实现
- 微信的模板消息推送
- 环信 获取通知栏推送消息
- 微信消息推送
- 微信模板推送
- 微信推送
- 企业微信推送
- 抓取微信公共号的推送内容
- 微信推送模板消息的PHP代码整理
- 微信公众平台开发——企业网站与微信的信息推送
- iOS集成环信推送,最详细流程(证书创建、环信集成、测试)
- iOS集成环信推送,最详细流程(证书创建、环信集成、测试)
- Redis集群常用操作方式
- 隐藏NavigationBar
- Struts2 无后缀action请求
- Asterisk G729编码支持
- JAVA Web项目中用到Redis的代码调试
- 环信的推送
- Asterisk 并发量到100后就出现拨打电话挂机问题
- poj 1036 Gangsters (DP:滚动数组)
- xml数据解析
- Loadrunner登录脚本
- js闭包
- Shell String Fuzzy Comparison
- iOS 和 Android 的后台推送原理各是什么?有什么区别?
- Ubuntu安装JDK6和JDK5