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. |
---|
MASStorage is the data peristence framework of the iOS Mobile SDK, which is part of CA Mobile API Gateway. It stores, manages, and accesses data in a private local and cloud.
The MASStorage framework comes with the following features:
- Encrypted data storage on device
- Secure acceess to private cloud data storage
- Stores data based on various permissions for users and apps.
- Check out our documentation for sample code, video tutorials, and more.
- Download MASStorage
- 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.
Contributions are welcome and much appreciated. To learn more, see the Contribution Guidelines.
MASStorage supports multiple methods for installing the library in a project.
To integrate MASStorage into your Xcode project using CocoaPods, specify it in your Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '14.0'
pod 'MASStorage'
Then, run the following command using the command prompt from the folder of your project:
$ pod 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.
- Open your project in Xcode.
- 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
. - Select
File->Add files to 'project name'
and add the msso_config.json file from your project folder. - In Xcode "Build Setting” of your Project Target, add
-ObjC
forOther Linker Flags
. - Import the following Mobile SDK library header file to the classes or to the .pch file if your project has one.
#import <MASFoundation/MASFoundation.h>
#import <MASStorage/MASStorage.h>
Store/Retrieve local data is done using different permission types. You control permissions using the following enumeration values for the MASLocalStorageSegment:
-
MASLocalStorageSegmentApplication This segment is used to store data pertinent only to the Application. For example, you can store the application configuration. Data stored here is shared across users within the app.
-
MASLocalStorageSegmentApplicationForUser This segment is used to store data pertinent to a specific user within the app. For example, in a game app, you can store the user game score or user game state.
To start using local storage in your app, the SDK needs to enable it. The following process creates the LocalStorage DB with a predefined schema.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//
// Enable Local Storage in the App
//
[MAS enableLocalStorage];
//
// Start the SDK
//
[MAS start:nil];
return YES;
}
Any object conforming to NSData
or NSString
can be saved into the local storage.
- (void)saveObjectMethod
{
NSString *myObject = @"someString";
NSString *key = @"someKey";
NSString *type = @"objectType";
//
// Save object to Local Storage
//
[MASLocalStorage saveObject:myObject withKey:key type:type mode:MASLocalStorageSegmentApplication completion:^(BOOL success, NSError *error) {
//Your code here
}];
}
Using encryption, saves any object conforming to NSData
or NSString
. It uses a password, that is set by parameter in the method, to encrypt the object before saving it in the local storage.
- (void)saveEncryptedObjectMethod
{
NSString *myObject = @"someString";
NSString *key = @"someKey";
NSString *type = @"objectType";
//
// Save object to Local Storage
//
[MASLocalStorage saveObject:myObject withKey:key type:type mode:MASLocalStorageSegmentApplication password:@"S0m3Pwd!" completion:^(BOOL success, NSError *error) {
//Your code here
}];
}
- (void)findObjectMethod
{
//
// Find Local Storage Data
//
[MASLocalStorage findObjectUsingKey:key mode:MASLocalStorageSegmentApplication completion:(void (^)(MASObject *object, NSError *error))completion; {
//Your code here
}];
}
- (void)deleteObjectMethod
{
//
// Delete object from local storage
//
[MASLocalStorage deleteObjectUsingKey:key mode:MASLocalStorageSegmentApplication completion:^(BOOL success, NSError *error) {
//Your code here
}];
}
- (void)findObjectsMethod
{
//
// Find all Local Storage Data by Mode
//
[MASLocalStorage findObjectsUsingMode:MASLocalStorageSegmentApplication completion:^(NSArray *objects, NSError *error) {
//Your code here
}];
}
- (void)viewDidLoad
{
[super viewDidLoad];
//Add Observer for Notifications from the Mobile SDK
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didSaveToLocalStorageNotification:)
name:MASStorageOperationDidSaveToLocalStorageNotification
object:nil];
}
Store/Retrieve cloud data is done using different permission types. You control permissions using the following enumeration values for the MASLocalStorageSegment:
-
MASCloudStorageSegmentUser This segment is used to store data pertinent only to a specific user. For example, if you want to extend the SCIM user profile. Data stored using this segment can be accessed by the same user via different apps.
-
MASCloudStorageSegmentApplication This segment is used to store data pertinent only to the Application. For example, you can store the application configuration. Data stored here is shared across users within the app.
-
MASCloudStorageSegmentApplicationForUser This segment is used to store data pertinent to a specific user within the app. For example, in a game app, you can store the user game score or user game state.
Any object conforming to NSDate
or NSString
can be saved into the cloud storage.
- (void)saveObjectMethod
{
NSString *myObject = @"someString";
NSString *key = @"someKey";
NSString *type = @"objectType";
//
// Save object to Cloud Storage
//
[MASCloudStorage saveObject:myObject withKey:key type:type mode:MASCloudStorageSegmentApplication completion:^(BOOL success, NSError *error) {
//Your code here
}];
}
- (void)findObjectMethod
{
//
// Find Cloud Storage Data
//
[MASCloudStorage findObjectUsingKey:key mode:MASCloudStorageSegmentApplication completion:(void (^)(MASObject *object, NSError *error))completion; {
//Your code here
}];
}
- (void)deleteObjectMethod
{
//
// Delete object from Cloud Storage
//
[MASCloudStorage deleteObjectUsingKey:key mode:MASCloudStorageSegmentApplication completion:^(BOOL success, NSError *error) {
//Your code here
}];
}
- (void)findObjectsMethod
{
//
// Find all Cloud Storage Data by Mode
//
[MASCloudStorage findObjectsUsingMode:MASCloudStorageSegmentApplication completion:^(NSArray *objects, NSError *error) {
//Your code here
}];
}
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.