• The app Instance object is a local representation of an app instance downloaded and installed in a user device.
  • The instance object is automatically managed by MOCA.
var theInstance = MOCA.currentInstance()
MOCAInstance * theInstance = [MOCA currentInstance];
  • The instance object holds a collection of properties. Property-value pairs can be set and retrieved and are persisted between app sessions.
/**
 * Sets the value for the given property name.
 * 
 * @param value Value to be set. It must belong to one of the accepted classes.
 * @param prop Property name.
 */
 func setValue(_ value: Any!, forProperty property: String!)
 /**
 * Gets the value for the given property.
 *
 * @param prop Property name.
 * @return Value associated with the property or <code>nil</code> if none.
 */
  func value(forProperty property: String!) -> Any
 
 /**
 * Returns a new array containing all existing property names.
 *
 * @return A new array containing all existing property names.
 */
 func allProperties() -> [Any]
/**
 * Sets the value for the given property name.
 * 
 * @param value Value to be set. It must belong to one of the accepted classes.
 * @param prop Property name.
 */
- (void) setValue:(id)value forProperty:(NSString*)prop;

/**
 * Gets the value for the given property.
 *
 * @param prop Property name.
 * @return Value associated with the property or <code>nil</code> if none.
 */
- (id) valueForProperty:(NSString*)prop;

/**
 * Returns a new array containing all existing property names.
 *
 * @return A new array containing all existing property names.
 */
- (NSArray*) allProperties;
  • Each instance object is persisted both locally and in the cloud. The instance is automatically uploaded to the cloud each time the app starts.
  • The instance can be saved manually to the cloud. All saves are asynchronous.
  • It is recommended to perform as many sets as desired and then just invoke a single save operation.
let theInstance = MOCA.currentInstance()
theInstance?.setValue("red", forProperty: "favorite-color")
theInstance?.setValue("women-cloth", forProperty: "last-search")
// Asynchronously save the instance to the cloud.
theInstance?.save({
  (_ instance: MOCAInstance?, _ error: Error?) -> Void in
  if (error != nil)  {
    print("Save instance failed: (%@)", error ?? "Error not available")
  }
})
#import <AdSupport/ASIdentifierManager.h>

MOCAInstance * theInstance = [MOCA currentInstance];    
if (theInstance)
{
    // Only track Advertising Identifier, if you app uses explicit Ad banners. 
    NSString * adId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]; 
    [theInstance setValue:adId forProperty:@”_ad_id"];
    [theInstance setValue:@"red" forProperty:@"favorite-color"];
    [theInstance setValue:@"women-cloth" forKey:@"last-search"];    // Asynchronously save the instance to the cloud.
    [theInstance saveWithBlock:^(MOCAInstance *instance, NSError *error)
        {
          if (error) NSLog(@"Save instance failed: %@", error);
        }
    ];
}