pEpObjCAdapter/NSDictionary+Debug.m
author Dirk Zimmermann <dz@pep.security>
Wed, 20 Mar 2019 16:40:35 +0100
branchIOS-1480
changeset 902 32760267cd59
parent 851 e62e76f93075
permissions -rw-r--r--
IOS-1480 Avoid framework imports.
     1 //
     2 //  NSDictionary+Debug.m
     3 //  pEpObjCAdapter
     4 //
     5 //  Created by Dirk Zimmermann on 07.06.18.
     6 //  Copyright © 2018 p≡p. All rights reserved.
     7 //
     8 
     9 #import "NSDictionary+Debug.h"
    10 
    11 #import "PEPConstants.h"
    12 
    13 #import "PEPMessageUtil.h"
    14 
    15 @implementation NSDictionary (Debug)
    16 
    17 - (void)debugSaveToFilePath:(NSString * _Nonnull)filePath
    18 {
    19     NSFileManager *fileManager = [NSFileManager defaultManager];
    20     NSURL *parentPath = [[fileManager
    21                           URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask]
    22                          firstObject];
    23 
    24     NSDate *now = [NSDate date];
    25     NSString *nowDesc = [now description];
    26     NSString *fileName = [NSString stringWithFormat:@"%@_%@.%@",
    27                           filePath, nowDesc, @"plist"];
    28 
    29     NSURL *writeURL = [NSURL fileURLWithPath:fileName relativeToURL:parentPath];
    30     NSLog(@"debugSaveToFilePath: writing %@", writeURL);
    31     [self writeToURL:writeURL atomically:YES];
    32 }
    33 
    34 - (void)dumpReferences
    35 {
    36     NSString *messageID = [self valueForKey:kPepID];
    37     if (messageID == nil) {
    38         messageID = @"unknown";
    39     }
    40     NSArray *references = [self valueForKey:kPepReferences];
    41     if (references.count > 0) {
    42         for (NSString *ref in references) {
    43             NSLog(@"messageID %@ -> ref %@\n", messageID, ref);
    44         }
    45     } else {
    46         NSLog(@"messageID %@ -> no refs\n", messageID);
    47     }
    48 }
    49 
    50 @end