许可证 | MIT |
发布最后发布 | 2019年10月 |
由Luis Sanches、Rob Weber、James Go、Britton Katnich、Yasmeen Taj、Syed Yusuf、Syed Yusuf 维护。
依赖项 | |
MASFoundation | = 2.0.00 |
MASIdentityManagement | = 2.0.00 |
MASConnecta 是 iOS 移动 SDK 的核心消息框架,它是 CA 移动 API 网关的一部分。它使开发者能够创建用户可以相互发送消息和数据的社交协作应用。
MASConnecta 框架提供以下功能
欢迎并感谢贡献。要了解更多信息,请查看 贡献指南。
MASConnecta 支持多种方法将库安装到项目中。
要使用 CocoaPods 将 MASConnecta 集成到 Xcode 项目中,请在您的 Podfile 中指定它:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
pod 'MASConnecta'
然后,使用您的项目文件夹的命令提示符运行以下命令:
$ pod install
手动安装时,您需要在 Xcode 项目中添加 Mobile SDK。注意,您必须添加 MASFoundation 库。为了完全启用 MAS 功能,安装所有MAS库,如所示。
如果需要则复制项
。文件->将文件添加到 '项目名称'
并将项目文件夹中的 msso_config.json 文件添加到项目中。-ObjC
添加为 其他链接器标志
的值。#import <MASFoundation/MASFoundation.h>
#import <MASConnecta/MASConnecta.h>
将 MASConnecta 添加到项目后,MASFoundation 库的一些对象将自动显示消息传递方法。这为您节省了开发时间,并使代码更加整洁。您只需编写几行代码,库就会自动处理与服务器连接的所有设置。
//Authenticated users have the ability to send messages (Text, Data, Image) to a user
MASUser *myUser = [MASUser currentUser];
MASUser *userB = Some user retrieved from the server
[myUser sendMessage:@"Hello World" toUser:userB completion:^(BOOL success, NSError * _Nullable error) {
NSLog(@"Message Sent : %@\nerror : %@", success ? @"YES":@"NO", error);
}];
//Authenticated users can send messages (Text, Data, Image) to a user on a specific topic
MASUser *myUser = [MASUser currentUser];
MASUser *userB = Some user retrieved from the server
//
// Get image from App Bundle
//
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpg"];
NSData *message = [NSData dataWithContentsOfFile:filePath];
//
// Create MASMessage object
//
MASMessage *messageImage = [[MASMessage alloc] initWithPayloadData:message contentType:@"image/jpeg"];
//
// Send Message to Recipient
//
[myUser sendMessage:messageImage toUser:userB onTopic:@"vacations" completion:^(BOOL success, NSError * _Nullable error) {
NSLog(@"Message Sent : %@\nerror : %@", success ? @"YES":@"NO", error);
}];
开始监听我的消息
- (void)viewDidLoad
{
//
//Get the current authenticated user
//
MASUser *myUser = [MASUser currentUser];
//
//Listen to Messages sent to my User
//
[myUser startListeningToMyMessages:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"Success subscribing to myUser topic!");
}
else {
NSLog(@"%@",error.localizedDescription);
}
}];
}
停止监听我的消息
- (void)viewDidLoad
{
//
//Get the current authenticated user
//
MASUser *myUser = [MASUser currentUser];
//
//Stop Listening to Messages sent to my User
//
[myUser stoplisteningToMyMessages:nil];
}
使用通知
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveMessageNotification:)
name:MASConnectaMessageReceivedNotification
object:nil];
}
- (void)didReceiveMessageNotification:(NSNotification *)notification
{
//
//Get the Message Object from the notification
//
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
MASMessage *myMessage = notification.userInfo[MASConnectaMessageKey];
[weakSelf.profileImage setImage:myMessage.payloadTypeAsImage];
[weakSelf.messagePayload setText:myMessage.payloadTypeAsString];
});
}
MASConnecta库公开了对象,允许您:
例如
- (void)viewDidLoad
{
[super viewDidLoad];
//
//Creating a new MQTT client
//
MASMQTTClient *client = [[MASMQTTClient alloc] initWithClientId:@"myClientID" cleanSession:YES];
//
//Connecting the mqtt client to a host
//
[client connectWithHost:@"mas.ca.com" withPort:8883 enableTLS:YES completionHandler:^(MQTTConnectionReturnCode code) {
//Your code here
}];
//
//Handling messages that arrive
//
[client setMessageHandler:^(MASMQTTMessage *message) {
//Your code here
}];
//
//Subscribing to a topic
//
[client subscribeToTopic:@"caTopic" withQos:ExactlyOnce completionHandler:^(NSArray *grantedQos) {
//Your code here
}];
//
//Publishing a message to a topic
//
[client publishString:@"Hello World" toTopic:@"caTopic" withQos:ExactlyOnce retain:YES completionHandler:^(int mid) {
//Your code here
}];
}
版权所有(C) 2016 CA。保留所有权利。
本软件可根据MIT许可证的条款进行修改和分发。
有关详情,请参阅LICENSE文件。