极光 IM ( JMessage ) = 极光推送 ( JPush ) + IM,本篇只论述其中的 IM 部分,为大家快速集成 IM 功能提供一个简明的范例。
我们先来看一下 IM 的基本功能与本文内容的对应关系:
#import <JMessage/JMessage.h>
JMessage 核心头文件。这是唯一需要导入到你的项目里的头文件,它引用了内部需要用到的头文件。
[JMessage addDelegate:self withConversation:nil];
[JMessage setupJMessage:launchOptions
appKey:@"your appkey"
channel:@"channel name"
apsForProduction:NO
category:nil];
application:didFinishLaunchingWithOptions:
[JMSGUser registerWithUsername:@"username"
password:@"password"
completionHandler:^(id resultObject, NSError *error) {
}];
Parameters:
[JMSGUser loginWithUsername:@"username"
password:@"password"
completionHandler:^(id resultObject, NSError *error) {
}];
[JMSGConversation createSingleConversationWithUsername:@"username"
completionHandler:^(id resultObject, NSError *error) {
}];
[(JMSGConversation*)resultObject sendTextMessage:@"text"];
- (void)onReceiveMessage:(JMSGMessage *)message error:(NSError *)error{
if (message.content == kJMSGContentTypeText) {
NSString *text = ((JMSGTextContent *)message.content).text;
}
}
message.contentType
判断消息类型message.content
为文本内容并获取文本 text
以展示 UI
NSArray *messages = [(JMSGConversation*)resultObject messageArrayFromNewestWithOffset:nil limit:nil];
resultObject
转型后获取
JMSGConversation *conversation = [JMSGConversation singleConversationWithUsername:username];
[conversation clearUnreadCount];
[JMSGConversation allConversations:^(id resultObject, NSError *error) {
}];
BOOL success = [JMSGConversation deleteSingleConversationWithUsername:username];
[JMSGUser userInfoArrayWithUsernameArray:nameArr completionHandler:^(id resultObject, NSError *error) {
}];
[JMSGGroup createGroupWithName:name desc:desc memberArray:members completionHandler:^(id resultObject, NSError *error) {
}];
[JMSGUser logout:^(id resultObject, NSError *error) {
}];
下载说明
☉本站所有源码和资源均由站长亲自测试-绝对保证都可以架设,运营!
☉如源码和资源有损坏或所有链接均不能下载,请告知管理员,
☉本站软件和源码大部分为站长独资,资源购买和收集,放心下载!
☉唯一站长QQ:1004003180 [人格担保-本站注重诚信!]
☉购买建议E-mail:1004003180@qq.com 源码收购 E-mail:1004003180@qq.com
☉本站文件解压密码 【文章内都自带解压密码,每个密码不同!】