Logging on iOS

On iOS, you have the ability to enable logging and email the output to yourself and support@layer.com for further analysis. This requires installing the LayerKitDiagnostics pod and using it to launch a MFMailComposeViewController with the information attached. Our recommendation is to respond to a shake gesture within your AppDelegate and send the email from there. This will make it easier to include a relevant screenshot of any issues and not require you to add any new controls.

  1. Include pod 'LayerKitDiagnostics' in your app’s podfile and run pod install.

  2. Enable debugging on your Layer Client object as soon as it’s initialized.

    self.layerClient = [LYRClient clientWithAppID:layerAppID delegate:self options:clientOptions];
    
    [self.layerClient setDebuggingEnabled:YES];
    
  3. Import the LayerKitDiagnostics.h header file into your AppDelegate and make it a delegate of MFMailComposeViewController.

    #import <LayerKitDiagnostics/LayerKitDiagnostics.h>
    
    @interface AppDelegate () <MFMailComposeViewControllerDelegate>
    
  4. Add the following 3 methods and modify the recipients array to include whomever you’d like to Cc.

    - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
        [self sendLayerDiagnostics];
    }
    
    - (void)sendLayerDiagnostics
    {
        // Include recipients to be Cced on this email
        NSArray *recipients = [NSArray arrayWithObjects:@"recipient1@email.com", @"recipient2@email.com", nil];
        LYRDEmailDiagnosticsViewController *diagnosticsViewController = [[LYRDEmailDiagnosticsViewController alloc] initWithLayerClient:self.layerClient withCcRecipients:recipients];
        diagnosticsViewController.mailComposeDelegate = self;
        [diagnosticsViewController captureDiagnosticsWithCompletion:^(BOOL success, NSError * _Nonnull error) {
            if (success) {
                UIViewController *topViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
                while (topViewController.presentedViewController) {
                    topViewController = topViewController.presentedViewController;
                }
                
                [topViewController presentViewController:diagnosticsViewController animated:YES completion:nil];
            } else {
                NSLog(@"Diagnostics email could not be sent: %@", error);
            }
        }];
    }
    
    - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
    {
        [controller dismissViewControllerAnimated:NO completion:nil];
    }
    

    Note

    Due to limitations with the Simulator you can currently only use this on a physical device. Trying to send this in the Simulator will result in the view being immediately dismissed before it can be sent.

  5. When the method is called, a few things are captured and consolidated into a single Zip file:

    • All logs captured so far
    • A copy of the local Layer database
    • A screenshot of what is currently displayed
  6. The iOS email client will open up and attach the Zip file and populate the body with relevant device and app information. Please fill out the top sections as thoroughly as possible:

    • Description of the issue
    • Steps to reproduce
    • Related support ticket IDs
  7. Once sent, you will receive a confirmation email with a support ID. Please use that as reference in any further communication regarding this issue.

Changelog Checklist