iOS SDK Advanced Configuration Options

iOS SDK Advanced Configuration Options

Changing Settings

You can specify several settings that control how Applause will behave within your app. The settings must be set before starting the actual session (before the startNewSessionWithApplicationKey: method is called) – changing them afterwards will have no effect.

The following settings are modifiable by simple calls to the Applause library:

Mode

The Applause SDK you can work in two modes:

  • QA Mode (APLModeQA): Use this mode to fully activate the Mobile SDK for your testing. When testers start your app, they will be presented with a login screen so that the Applause SDK can associate their bugs with their Applause SDK accounts. Full details about the app and device state are sent with logs, sessions, bug reports, and crash reports. This mode is the default, and in most cases, you should choose this mode
  • Market Mode (APLModeMarket): This mode hides the Applause SDK from the user. They will not be able to login to the Applause SDK server or report bugs from the app.

Default value of mode is APLModeQA or APLMode.QA for Swift.

Objective-C

[[APLLogger settings] setMode:APLModeQA];

Swift

APLLogger.settings().mode = APLMode.QA

Report On Shake

Default is YES. Specifies whether to report bugs by shaking the device.

Objective-C

[[APLLogger settings] setReportOnShakeEnabled:YES];

Swift

APLLogger.settings().reportOnShakeEnabled = true

Gallery Mode

This method was deprecated. By default the SDK supports adding images from the gallery.

Default User

The default value is nil. When a default user email is provided, there will be no login screen and all sessions will be linked to this user. An APLAnonymousUser constant value can be used to link all sessions to the anonymous user.

Objective-C

[[APLLogger settings] setDefaultUser:@"johnsmith@sample.mail"];

Swift

APLLogger.settings().defaultUser = "johnsmith@sample.mail"

Applause Integration

The default value is YES. Activate Applause’s integration with uTest. Set this to NO if you are not an Applause customer and you’re not using Applause SDK with the Applause community. NOTE: This also enables/disables the Feedbackbutton in the SDK UI. If you want to collect user feedback in addition to bugs, this flag should be set to NO. Feedback will be available within the SDK platform’s control panel ([sdk.applause.com]).

Objective-C

[[APLLogger settings] setWithUTest:YES];

Swift

APLLogger.settings().withUTest = true

Mach Exceptions

The default value is nil which means that Applause is using the BSD signal handler. Trap fatal signals via a Mach exception server.

NOTE! The Mach exception handler executes in-process, and will interfere with debuggers. It should not be used with debugging set on!

Objective-C

[[APLLogger settings] setMachExceptionEnabled:YES];

Swift

APLLogger.settings().machExceptionEnabled = true

Server URL

The default server is https://sdk.applause.com. If you are using the SDK in conjunction with an on premise installation then you will have to override this to ensure your applause traffic goes to the right server.

Objective-C

[[APLLogger settings] setServerURL:@”https://your-domain.com”];

Swift

APLLogger.settings().serverURL = "https://your-domain.com"

Send All NSLog To Applause

The default value is NO. Enable it when you want to send all NSLog (NSLogv also) calls to Applause Server.

NOTE! This function uses private API so it may not work on all system versions.

Objective-C

[[APLLogger settings] setSendAllNSLogToApplause:YES];

Swift

APLLogger.settings().sendAllNSLogToApplause = true

Sample code for using advanced configuration

Objective-C

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
    [[APLLogger settings] setReportOnShakeEnabled:YES];
    [[APLLogger settings] setScreenShotsFromGallery:YES];
    [[APLLogger settings] setDefaultUser:@"johnsmith@sample.mail"];
    [[APLLogger settings] setWithUTest:YES];
    [[APLLogger settings] setMachExceptionEnabled:NO];
    [[APLLogger settings] setServerURL:@”sdk.applause.com”];
    [APLLogger startNewSessionWithApplicationKey:@"Applause-Application-Key "];
    ...
    return YES;
 }

Swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
   APLLogger.settings().reportOnShakeEnabled = true
   APLLogger.settings().screenShotsFromGallery = true
   APLLogger.settings().defaultUser = "johnsmith@sample.mail"
   APLLogger.settings().withUTest = true
   APLLogger.settings().machExceptionEnabled = false
   APLLogger.settings().serverURL = "sdk.applause.com"
   APLLogger.startNewSessionWithApplicationKey("1g60119f909abd70e5929acb5df9ba924d3a71e690g0g2g35290d29")
   ...
   return true
}

Custom Uncaught Exception Handler (Objective-C only)

If you want to set your own exception handler with NSSetUncaughtExceptionHandler(), please call:

externvoid APLUncaughtExceptionHandler(NSException* exception);

from your method, to send unhanded exceptions to Applause:

void MyCustomUncaughtExceptionHandler(NSException* exception) {
...
APLUncaughtExceptionHandler(exception);
}

Triggering Bug Reports Programmatically

You can also invoke the bug reporting screen from inside your own application code. This is useful if you want to add your own UI for bug reporting.

Simply use the following method in your app to trigger the mechanism:

Objective-C

[APLLogger showReportScreen];

Swift

APLLogger.showReportScreen()

You can bind this call to any UI action such as tapping an on-screen button or choosing an option from a menu.

Advanced Logging Methods

Objective-C

In addition to APLLog, for more granular logging, you can use the APLExtendedLog method. This method works just likeAPLLog, however it also allows you to manually tag the log and add a log level. The tag and log level allows you to categorize the logged activity within Applause.

void APLExtendedLog(APLLogLevel level, NSString nsstring_tag, NSString nsstring_format, ...)

The parameters are:

  • level – an enum with one of the following log levels:
    • APLLogLevelFatal
    • APLLogLevelError
    • APLLogLevelWarning
    • APLLogLevelInfo
    • APLLogLevelVerbose
  • nsstring_tag – a string for including a tag
  • nsstring_format – a format containing the log message itself, where “…” is the argument list for the format string

Swift

Swift does not support macros, hence APLLog does not work. That’s why we’ve introduced the following category onAPLLogger to expose logging methods in Swift:

@interface APLLogger (APLSwiftLoggingSupport)
+ (void)log:(NSString *)message; //default info log
+ (void)log:(NSString *)message withLevel:(APLLogLevel)logLevel;
@end

Examples

Objective-C

APLExtendedLog(APLLogLevelWarning, nil, @"APLExtendedLog with a warning log level", nil);
NSString *const tag = @"example_tag";
APLExtendedLog(APLLogLevelVerbose, tag, @"APLExtendedLog with a verbose log level and with tag: %@", tag);

Swift

APLLogger.log("This is a default info log with object (object)")
APLLogger.log("This is a warning log with object (object)", withLevel: APLLogLevelWarning)