LogDumpViewController.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "LogDumpViewController.h"
  17. #import "AppDelegate.h"
  18. #import "FIRIAMRuntimeManager.h"
  19. @interface LogDumpViewController ()
  20. @property(weak, nonatomic) IBOutlet UITextView *logTextView;
  21. @end
  22. @implementation LogDumpViewController
  23. - (IBAction)dumpImpressList:(id)sender {
  24. NSArray *impressions = [[FIRIAMRuntimeManager getSDKRuntimeInstance].bookKeeper getImpressions];
  25. NSString *text = [NSString stringWithFormat:@"Message Impression History are :\n%@",
  26. [impressions componentsJoinedByString:@"\n"]];
  27. self.logTextView.text = text;
  28. }
  29. - (IBAction)dumActivityLogs:(id)sender {
  30. NSArray<FIRIAMActivityRecord *> *records =
  31. [[FIRIAMRuntimeManager getSDKRuntimeInstance].activityLogger readRecords];
  32. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  33. dateFormatter.dateStyle = NSDateFormatterShortStyle;
  34. dateFormatter.timeStyle = NSDateFormatterMediumStyle;
  35. static NSString *appBuildVersion = nil;
  36. static dispatch_once_t onceToken;
  37. dispatch_once(&onceToken, ^{
  38. appBuildVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
  39. });
  40. NSMutableString *dumpContent = [[NSString
  41. stringWithFormat:@"App Build Version -- %@\n\n"
  42. "SDK Settings -- %@\n\n"
  43. "Activity Logs: %lu records\n\n",
  44. appBuildVersion, [FIRIAMRuntimeManager getSDKRuntimeInstance].currentSetting,
  45. (unsigned long)records.count] mutableCopy];
  46. for (FIRIAMActivityRecord *next in records) {
  47. NSString *nextRecordLog = [NSString
  48. stringWithFormat:@"%@, %@, %@, %@\n", [dateFormatter stringFromDate:next.timestamp],
  49. [next displayStringForActivityType], next.success ? @"Success" : @"Failed",
  50. next.detail];
  51. [dumpContent appendString:nextRecordLog];
  52. }
  53. self.logTextView.text = dumpContent;
  54. }
  55. - (void)viewDidLoad {
  56. [super viewDidLoad];
  57. // Do any additional setup after loading the view.
  58. }
  59. - (void)didReceiveMemoryWarning {
  60. [super didReceiveMemoryWarning];
  61. // Dispose of any resources that can be recreated.
  62. }
  63. @end