MAF Utility Components

MAF provides several utility libraries, such as the UI Helper, ZIP Helper and MAF Logger.

UI Helper

This UIHelper library contains an extended UIAlertView that can handle callbacks via completion blocks. This code contains a UIAlertView and MAFUIHelper interface:
typedef void (^AlertViewResultBlockType)(int buttonIndex);

/**
 Helper categrory to ease the usage of UIAlertView.
 */
@interface UIAlertView (MAFUIHelper)

/**
 Creates a new instance of a UIAlertView and shows it. The UIAlertViewDelegate is implemented inside the category and the resultBlock parameter is called back with the pressed button index.
 @param title: The string that appears in the receiver’s title bar
 @param message: Descriptive text that provides more details than the title
 @param block: the result block which will be called when the user presses one of the buttons
 @param cancelButtonTitle: The title of the cancel button or nil if there is no cancel button
 @param otherButtonTitles: Titles of additional buttons to add to the receiver, terminated with nil
 */
+ (id)alertViewWithTitle:(NSString *)title message:(NSString *)message resultBlock:(AlertViewResultBlockType)block cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;

@end

AlertViewResultBlockType is a completion block; that is, an iOS-provided artifact that can contain almost any valid Objective-C code, with the purpose of referencing Objective-C code blocks to be executed when the called function finishes the execution. MAF calls this block when the user taps a button.

Zip Helper

Zip helper is a small utility library that helps unzip SAP Mobile Platform configuration bundles. To unzip the Style.xml from an SAP Mobile Platform configuration bundle, use:
#import "MAFZipFileDescriptor.h"
...
// write out temporary because the zipmodule works only on disk files
    NSString *tmpFilePath = [[NSTemporaryDirectory() stringByExpandingTildeInPath] 
					stringByAppendingPathComponent:@"zippedBundle.zip"];
    [customResourceData writeToFile:tmpFilePath atomically:YES];
    MAFZipFileDescriptor *zipFileDesc = [[MAFZipFileDescriptor alloc] 
								initWithFileAtPath:tmpFilePath];
    NSData* welterData = [zipFileDesc uncompressedEmbeddedFileContentNamed:@"style/Styles.xml"];
    [welterData retain];

After unzipping the Styles.xml file, you can parse it with MAFStyleParser. See MAF Skinning on how to parse and load this extracted style file.

MAF Logger

MAF mainly builds on the SDM logger provided by SAP Mobile Platform client libraries. MAF includes a wrapper class that allows MAF components to use any logger implementation. MAFLogger currently supports these loggers:
  • MAFLoggerSDM – provided by SAP Mobile Platform client libraries.
  • MAFLoggerConsole – logs to the console.
  • MAFLoggerFile – logs to file.
These loggers all implement the MAFLogging protocol, so you can use its methods to turn logging on and off, or to query the status of the particular logger. To use MAFLogger, get a shared instance of it:
#import "MAFLogger.h"
…
[[MAFLogger sharedInstance] setUsedLoggers:MAFLoggerSDM|MAFLoggerConsole|MAFLoggerFile];
…
MafLogonLog(MAFInfoLoggingLevel, @"Upload start with URL: %@", fullBtxPath);
MAFLogger does not include a log viewer. Your application must provide the UI to change the logging level, or to turn logging on and off. Use these MAFLogging interface methods to change logging behavior:
#pragma mark -
#pragma mark Enable / disable logging

/**
 * Enables logging for non-critical levels, like warning, notice, info, debug.
 */
-(void) enableNonCriticalLogging;

/**
 * Disables logging of non-critical messages, like warning, notice, info, debug.
 */
-(void) disableNonCriticalLogging;


#pragma mark -
#pragma mark Logging status
/**
 * Returns whether non-critical logs are currently enabled
 */
-(BOOL) isNonCriticalLoggingEnabled;