1、M800SDK使用手册: 1.导入M800SDK 2. Add path to project Library Search Path添加SDK路径 3. Add libraries to project • libc++.dylib • libresolv.dylib • libstdc++.6.0.9.dylib • libxml2.dylib • libz.dylib • libm800sdk-2.2.0.a 4.配置info.plist . 1 M800DeveloperKey : your develop
2、er key (supplied by M800) . 2 M800ApplicationKey : your application key (supplied by M800) . 3 M800ApplicationIdentifier : your application identifier (supplied by M800) . 4 M800ApplicationVersion : 1.0.0 (default value) . 5 M800Capabilities : incoming, outgoing (default value) .
3、6 M800Expiration : 36000 (in second)
. 7 M800CarrierName : your carrier name (supplied by M800)
. 设置应用信息提供商:
. +(void)setApplicationInformationProvider:(id
4、ovider; 生产数字签名的例子: //Generating Signature + (NSString*)genCapSigWithCapabilities:(NSString*)cap expires:(NSString*)expires applicationSecret:(NSString*)applicationSecret { NSString * content = [NSString stringWithFormat:@"%@%@", cap, expires]; const char *cKey = [applicationSecret
5、cStringUsingEncoding:NSUTF8StringEncoding]; const char *cData = [content cStringUsingEncoding:NSUTF8StringEncoding]; unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH]; CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC); NSMutableString *output = [NSMutableString
6、 stringWithCapacity:CC_SHA256_DIGEST_LENGTH];
for (int i=0; i 7、ourceNetworkId:jid displayName:displayName
language:M800LanguageEnglish
completeBlock:^(BOOL isSuccess, NSError *error) {
if (isSuccess)
{
//Success
} else {
//Error
}];
}
服务器返回以下内容
[[M800SDK sharedInstance] bareJid];
[[M800SDK sharedInstance] prefixOfJid];
[ 8、[M800SDK sharedInstance] carrierName];
[[M800SDK sharedInstance] username];
得到它们。
用以下代码和服务器建立链接
[[M800SDK sharedInstance] connectWithCompleteBlock:^(BOOL isSuccess, NSError *error)
{ if (isSuccess){
} //TODO do some things after successful connection.
else if ([[M800SDK s 9、haredInstance] needKickUserWithError:error]){
} //TODO Must kick current user out of app.
else {
//TODO do something when failed to connect.
}}];
检查是否需要踢出用户(是否在新设备登录或者验证失败):
[[M800SDK sharedInstance] needKickUserWithError:^(NSError* error) {
//error handling
}];
验证,添 10、加,移除身份信息:
// Validate a phone number if needs
[[M800SDK sharedInstance] validateNumber:@"12345678" country:@"hk" language:@"zh"
validType:@"SMS" complete:^(NSString *validateCode) {
_validateCode = validateCode;
} error:^(NSError *error) {
}];
// Signup a phone num 11、ber as additional identity with/without verification
[[M800SDK sharedInstance] signupAdditionIdentityWithNumber:@"12345678"
country:@"hk"
validateCode:_validateCode
12、 smsCode:smsCodeReceived
nonVerifiedMode:NO
passiveValidation:NO
completeBlock:nil];
// Remove an existing additional iden 13、tity
[[M800SDK sharedInstance] removeAdditionIdentityWithNumber:@"12345678" country:@"hk"
completeBlock:nil];
文本功能在M800SDK+ IM.h中
发送内容给JID:
[[M800SDK sharedInstance] sendMessage:@"Content" to:@"JID"];
消息发送成功回调:
- (void) didMessageSend:(NSString*) msgId;
没发送成功(消息发送失败)
- (void) didMessag 14、eSendingFailed:(NSString*) msgId;
客户端收到消息:
- (void) didServerReceived:(NSString *) msgId;
服务器收到该消息,并返回信息,回调以下方法:
- (void)didClientReceived:(NSString *) msgId;
创建群聊天室:
-(void) createRoom:(NSArray*)jids
subject:(NSString*)subject
complete:(void(^)(M800Room*))completeBlock
error: 15、void(^)(NSError
*))errorBlock;
聊天室添加人员:
-(void) inviteParticipants:(NSArray*) jids
toRoom:(M800Room *)room
complete:(void (^)(M800Room *))completeBlock
error:(void(^)(NSError *))errorBlock;
参与者离开聊天室:
- (void)leaveRoom:(M800Room *) room
complete:(void (^)(void))comple 16、teBlock
error:(void(^)(NSError *))errorBlock;
踢出参与者:
- (void)kickParticipant:(NSString*)jid fromRoom:(M800Room *)room complete:(void (^)(M800Room
*))completeBlock
error:(void (^)(NSError *))errorBlock;
下载群聊的聊天室列表:
-(void)queryMembershipAndCreateRoomsWithCompleteBlock:(void ( 17、^)(BOOL))completeBlock
error:(void(^)(NSError *))errorBlock;
更新聊天室成员:
- (void)queryMembershipForSingleRoom:(NSString *) roomId
completeBlock:(void (^)(BOOL))completeBlock
error:(void (^)(NSError *))errorBlock;
如果要在列表视图中显示所有的聊天室列表需要获得NSFetchedResultsController
-(NS 18、FetchedResultsController*)roomsFetchedResultsController;
使用代理方法处理消息:
- (void) incomingMessage:(M800Message *) message inRoom:(M800Room *) room;
图片共享:
发送图片到聊天室:
UIImage * image = [UIImage imageNamed:@"M800.jpg"];
CLLocationCoordinate2D location;
M800Room * room = [[M800SDK
sharedInstance 19、] roomWithBareJid:@"+-"];
[[M800SDK sharedInstance] sendImage:image
room:room tags:nil location:location];
你可以发送一个只出现几秒的图片?:
- (void)sendEphemeralImage:(UIImage*)image
room:(M800Room*)room
tags:(NSString*)tags
location:(CLLocationCoordinate2D)location;
语音发送:
NSURL * url = [NSURL
URLWit 20、hString:@""];
CLLocationCoordinate2D location;
M800Room* room = [[M800SDK sharedInstance]
roomWithBareJid:@"+-"];
[[M800SDK sharedInstance]
sendAudioWithFileURL:url room:room tags:tags location:location];
视频信息:
NSURL * url = [NSURL
URLWithString:@"
V"];
CLLocationCoordinate2D location;
21、M800Room * room = [[M800SDK sharedInstance]
roomWithBareJid:@"+-"];
[[M800SDK sharedInstance]
sendVideoWithFileURL:url room:room tags:tags location:location];
广播消息:M800SDK+IM_Broadcast.h
CLLocationCoordinate2D location;
[[M800SDK sharedInstance] sendMessage:@"text"
22、 destUsers:@[@"user1",@"user2"]
tags:nil
withGeoLocation:location];
位置信息分享:M800SDK+IM.h & M800SDK+IM_Broadcast.h
- (void)shareLocation:(CLLocationCoordinate2D)location
message:(NSString*)message
room:(M800Room*)room
tags:(NSStri 23、ng*)tags;
添加语音功能:
id 24、rInfo;
打电话:
1. 生成一个唯一的呼叫ID
NSString * callID = [NSString stringWithFormat:@"m800demo-onnet-%d", (int)[NSDate
timeIntervalSinceReferenceDate]];
. 2.创建一个呼叫会话
id 25、play:@"display name"
. carrier:@"" userInfo:nil callID:callID enableICE:YES];
.
. 3.呼叫(拨出电话)
[call dial];
[call addCallDelegate:delegate];
.
. 拨出后处理呼叫事件
. -(void)callDial:(id 26、l>)call status:(NSNumber *)code; -(void)callBeginTalking:(id 27、ionsWithDeviceToken:(NSData *)deviceToken
{
//This code will upload the deviceToken to the M800 server for sending push call
notifications.
[[M800SDK sharedInstance] application:application
didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
当接收远程推送通知时,使用下面的代码来捕获
- (void 28、)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// Processing call notification
id 29、ustomized answer call screen.
//Note: Now can add M800CallDelegate to receive call events.
[call addCallDelegate:delegate];
}
使用调用对象(id 30、oid)callBeginTalking:(id 31、 the following events from the delegate:
- (void)callTerminated:(id 32、eSpace:(NSString )nameSpace info:(NSDictionary *)info;
推送:
重写以下方法appdelegate.m中的
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary*)userInfo
{
[[M800SDK sharedInstance] application:application didReceiveRemoteNotification:userInfo];
}
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
{
[[M800SDK sharedInstance] application:application
didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
dome使用
14 / 14






