项目作者: CAAPIM

项目描述 :
iOS Mobile SDK for CA Mobile API Gateway - MASConnecta Framework
高级语言: Objective-C
项目地址: git://github.com/CAAPIM/iOS-MAS-Connecta.git
创建时间: 2016-04-18T18:54:48Z
项目社区:https://github.com/CAAPIM/iOS-MAS-Connecta

开源协议:Other

下载


Maintenance

⚠️ Please note that this repo will be archived in the near future. Please do not submit any new changes as they are no longer being accepted. Please contact Broadcom support https://support.broadcom.com/ to report any defects or make a request for an update. Broadcom is continuing support for the SDK but will no longer maintain the public GitHub community.

MASConnecta is the core messaging framework of the iOS Mobile SDK, which is part of CA Mobile API Gateway. It gives developers the ability to create social collaborative apps where users can message and send data to each other.

Features

The MASConnecta framework comes with the following features:

  • Secure and reliable User to User messaging
  • MQTT client with built-in mutual SSL and OAuth support

Get Started

Communication

  • Have general questions or need help?, use Stack Overflow. (Tag ‘massdk’)
  • Find a bug?, open an issue with the steps to reproduce it.
  • Request a feature or have an idea?, open an issue.

How You Can Contribute

Contributions are welcome and much appreciated. To learn more, see the Contribution Guidelines.

Installation

MASConnecta supports multiple methods for installing the library in a project.

Cocoapods (Podfile) Install

To integrate MASConnecta into your Xcode project using CocoaPods, specify it in your Podfile:

  1. source 'https://github.com/CocoaPods/Specs.git'
  2. platform :ios, '9.0'
  3. pod 'MASConnecta'

Then, run the following command using the command prompt from the folder of your project:

  1. $ pod install

Manual Install

For manual install, you add the Mobile SDK to your Xcode project. Note that you must add the MASFoundation library. For complete MAS functionality, install all of the MAS libraries as shown.

  1. Open your project in Xcode.
  2. Drag the SDK library files, and drop them into your project in the left navigator panel in Xcode. Select the option, Copy items if needed.
  3. Select File->Add files to 'project name' and add the msso_config.json file from your project folder.
  4. In Xcode “Build Setting” of your Project Target, add -ObjC for Other Linker Flags.
  5. Import the following Mobile SDK library header file to the classes or to the .pch file if your project has one.
  1. #import <MASFoundation/MASFoundation.h>
  2. #import <MASConnecta/MASConnecta.h>

Usage

Messaging

After MASConnecta is added to a project, some objects from the MASFoundation library automatically displays messaging methods. This saves you development time and makes the code cleaner. You write just a few lines of code, and the library automatically handles all of the settings for the connection to the server.

Send messages

  1. //Authenticated users have the ability to send messages (Text, Data, Image) to a user
  2. MASUser *myUser = [MASUser currentUser];
  3. MASUser *userB = Some user retrieved from the server
  4. [myUser sendMessage:@"Hello World" toUser:userB completion:^(BOOL success, NSError * _Nullable error) {
  5. NSLog(@"Message Sent : %@\nerror : %@", success ? @"YES":@"NO", error);
  6. }];
  1. //Authenticated users can send messages (Text, Data, Image) to a user on a specific topic
  2. MASUser *myUser = [MASUser currentUser];
  3. MASUser *userB = Some user retrieved from the server
  4. //
  5. // Get image from App Bundle
  6. //
  7. NSString* filePath = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpg"];
  8. NSData *message = [NSData dataWithContentsOfFile:filePath];
  9. //
  10. // Create MASMessage object
  11. //
  12. MASMessage *messageImage = [[MASMessage alloc] initWithPayloadData:message contentType:@"image/jpeg"];
  13. //
  14. // Send Message to Recipient
  15. //
  16. [myUser sendMessage:messageImage toUser:userB onTopic:@"vacations" completion:^(BOOL success, NSError * _Nullable error) {
  17. NSLog(@"Message Sent : %@\nerror : %@", success ? @"YES":@"NO", error);
  18. }];

Start listening to messages

Start listening to my messages

  1. - (void)viewDidLoad
  2. {
  3. //
  4. //Get the current authenticated user
  5. //
  6. MASUser *myUser = [MASUser currentUser];
  7. //
  8. //Listen to Messages sent to my User
  9. //
  10. [myUser startListeningToMyMessages:^(BOOL success, NSError *error) {
  11. if (success) {
  12. NSLog(@"Success subscribing to myUser topic!");
  13. }
  14. else {
  15. NSLog(@"%@",error.localizedDescription);
  16. }
  17. }];
  18. }

Stop listening to messages

Stop listening to my messages

  1. - (void)viewDidLoad
  2. {
  3. //
  4. //Get the current authenticated user
  5. //
  6. MASUser *myUser = [MASUser currentUser];
  7. //
  8. //Stop Listening to Messages sent to my User
  9. //
  10. [myUser stoplisteningToMyMessages:nil];
  11. }

Handle incoming messages

Use notifications

  1. - (void)viewDidLoad
  2. {
  3. [[NSNotificationCenter defaultCenter] addObserver:self
  4. selector:@selector(didReceiveMessageNotification:)
  5. name:MASConnectaMessageReceivedNotification
  6. object:nil];
  7. }
  1. - (void)didReceiveMessageNotification:(NSNotification *)notification
  2. {
  3. //
  4. //Get the Message Object from the notification
  5. //
  6. __weak typeof(self) weakSelf = self;
  7. dispatch_async(dispatch_get_main_queue(), ^{
  8. MASMessage *myMessage = notification.userInfo[MASConnectaMessageKey];
  9. [weakSelf.profileImage setImage:myMessage.payloadTypeAsImage];
  10. [weakSelf.messagePayload setText:myMessage.payloadTypeAsString];
  11. });
  12. }

Pub/Sub

The MASConnecta library exposes objects that let you: 1) create your own MQTTClient object 2) optionally establish connection with a host using SSL/TLS, 3) set up login and password, and 4) subscribe or publish directly to a topic.

For example:

  1. - (void)viewDidLoad
  2. {
  3. [super viewDidLoad];
  4. //
  5. //Creating a new MQTT client
  6. //
  7. MASMQTTClient *client = [[MASMQTTClient alloc] initWithClientId:@"myClientID" cleanSession:YES];
  8. //
  9. //Connecting the mqtt client to a host
  10. //
  11. [client connectWithHost:@"mas.ca.com" withPort:8883 enableTLS:YES completionHandler:^(MQTTConnectionReturnCode code) {
  12. //Your code here
  13. }];
  14. //
  15. //Handling messages that arrive
  16. //
  17. [client setMessageHandler:^(MASMQTTMessage *message) {
  18. //Your code here
  19. }];
  20. //
  21. //Subscribing to a topic
  22. //
  23. [client subscribeToTopic:@"caTopic" withQos:ExactlyOnce completionHandler:^(NSArray *grantedQos) {
  24. //Your code here
  25. }];
  26. //
  27. //Publishing a message to a topic
  28. //
  29. [client publishString:@"Hello World" toTopic:@"caTopic" withQos:ExactlyOnce retain:YES completionHandler:^(int mid) {
  30. //Your code here
  31. }];
  32. }

License

Copyright (c) 2019 Broadcom. All Rights Reserved.
The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.

This software may be modified and distributed under the terms
of the MIT license. See the LICENSE file for details.