You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.8 KiB

6 years ago
  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 "NSDictionary+FIRMessaging.h"
  17. @implementation NSDictionary (FIRMessaging)
  18. - (NSString *)fcm_string {
  19. NSMutableString *dictAsString = [NSMutableString string];
  20. NSString *separator = @"|";
  21. for (id key in self) {
  22. id value = self[key];
  23. if ([key isKindOfClass:[NSString class]] && [value isKindOfClass:[NSString class]]) {
  24. [dictAsString appendFormat:@"%@:%@%@", key, value, separator];
  25. }
  26. }
  27. // remove the last separator
  28. if ([dictAsString length]) {
  29. [dictAsString deleteCharactersInRange:NSMakeRange(dictAsString.length - 1, 1)];
  30. }
  31. return [dictAsString copy];
  32. }
  33. - (BOOL)fcm_hasNonStringKeysOrValues {
  34. for (id key in self) {
  35. id value = self[key];
  36. if (![key isKindOfClass:[NSString class]] || ![value isKindOfClass:[NSString class]]) {
  37. return YES;
  38. }
  39. }
  40. return NO;
  41. }
  42. - (NSDictionary *)fcm_trimNonStringValues {
  43. NSMutableDictionary *trimDictionary =
  44. [NSMutableDictionary dictionaryWithCapacity:self.count];
  45. for (id key in self) {
  46. id value = self[key];
  47. if ([key isKindOfClass:[NSString class]] && [value isKindOfClass:[NSString class]]) {
  48. trimDictionary[(NSString *)key] = value;
  49. }
  50. }
  51. return trimDictionary;
  52. }
  53. @end