RLMSyncManager.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import <Foundation/Foundation.h>
  19. #import "RLMSyncUtil.h"
  20. @class RLMSyncSession;
  21. /// An enum representing different levels of sync-related logging that can be configured.
  22. typedef NS_ENUM(NSUInteger, RLMSyncLogLevel) {
  23. /// Nothing will ever be logged.
  24. RLMSyncLogLevelOff,
  25. /// Only fatal errors will be logged.
  26. RLMSyncLogLevelFatal,
  27. /// Only errors will be logged.
  28. RLMSyncLogLevelError,
  29. /// Warnings and errors will be logged.
  30. RLMSyncLogLevelWarn,
  31. /// Information about sync events will be logged. Fewer events will be logged in order to avoid overhead.
  32. RLMSyncLogLevelInfo,
  33. /// Information about sync events will be logged. More events will be logged than with `RLMSyncLogLevelInfo`.
  34. RLMSyncLogLevelDetail,
  35. /// Log information that can aid in debugging.
  36. ///
  37. /// - warning: Will incur a measurable performance impact.
  38. RLMSyncLogLevelDebug,
  39. /// Log information that can aid in debugging. More events will be logged than with `RLMSyncLogLevelDebug`.
  40. ///
  41. /// - warning: Will incur a measurable performance impact.
  42. RLMSyncLogLevelTrace,
  43. /// Log information that can aid in debugging. More events will be logged than with `RLMSyncLogLevelTrace`.
  44. ///
  45. /// - warning: Will incur a measurable performance impact.
  46. RLMSyncLogLevelAll
  47. };
  48. NS_ASSUME_NONNULL_BEGIN
  49. /// A block type representing a block which can be used to report a sync-related error to the application. If the error
  50. /// pertains to a specific session, that session will also be passed into the block.
  51. typedef void(^RLMSyncErrorReportingBlock)(NSError *, RLMSyncSession * _Nullable);
  52. /**
  53. A singleton manager which serves as a central point for sync-related configuration.
  54. */
  55. @interface RLMSyncManager : NSObject
  56. /**
  57. A block which can optionally be set to report sync-related errors to your application.
  58. Any error reported through this block will be of the `RLMSyncError` type, and marked
  59. with the `RLMSyncErrorDomain` domain.
  60. Errors reported through this mechanism are fatal, with several exceptions. Please consult
  61. `RLMSyncError` for information about the types of errors that can be reported through
  62. the block, and for for suggestions on handling recoverable error codes.
  63. @see `RLMSyncError`
  64. */
  65. @property (nullable, nonatomic, copy) RLMSyncErrorReportingBlock errorHandler;
  66. /**
  67. A reverse-DNS string uniquely identifying this application. In most cases this is automatically set by the SDK, and
  68. does not have to be explicitly configured.
  69. */
  70. @property (nonatomic, copy) NSString *appID;
  71. /**
  72. The logging threshold which newly opened synced Realms will use. Defaults to
  73. `RLMSyncLogLevelInfo`.
  74. Logging strings are output to Apple System Logger.
  75. @warning This property must be set before any synced Realms are opened. Setting it after
  76. opening any synced Realm will do nothing.
  77. */
  78. @property (nonatomic) RLMSyncLogLevel logLevel;
  79. /**
  80. The name of the HTTP header to send authorization data in when making requests to a Realm Object Server which has
  81. been configured to expect a custom authorization header.
  82. */
  83. @property (nullable, nonatomic, copy) NSString *authorizationHeaderName;
  84. /**
  85. Extra HTTP headers to append to every request to a Realm Object Server.
  86. */
  87. @property (nullable, nonatomic, copy) NSDictionary<NSString *, NSString *> *customRequestHeaders;
  88. /**
  89. A map of hostname to file URL for pinned certificates to use for HTTPS requests.
  90. When initiating a HTTPS connection to a server, if this dictionary contains an
  91. entry for the server's hostname, only the certificates stored in the file (or
  92. any certificates signed by it, if the file contains a CA cert) will be accepted
  93. when initiating a connection to a server. This prevents certain certain kinds
  94. of man-in-the-middle (MITM) attacks, and can also be used to trust a self-signed
  95. certificate which would otherwise be untrusted.
  96. On macOS, the certificate files may be in any of the formats supported by
  97. SecItemImport(), including PEM and .cer (see SecExternalFormat for a complete
  98. list of possible formats). On iOS and other platforms, only DER .cer files are
  99. supported.
  100. For example, to pin example.com to a .cer file included in your bundle:
  101. <pre>
  102. RLMSyncManager.sharedManager.pinnedCertificatePaths = @{
  103. @"example.com": [NSBundle.mainBundle pathForResource:@"example.com" ofType:@"cer"]
  104. };
  105. </pre>
  106. */
  107. @property (nullable, nonatomic, copy) NSDictionary<NSString *, NSURL *> *pinnedCertificatePaths;
  108. /// The sole instance of the singleton.
  109. + (instancetype)sharedManager NS_REFINED_FOR_SWIFT;
  110. /// :nodoc:
  111. - (instancetype)init __attribute__((unavailable("RLMSyncManager cannot be created directly")));
  112. /// :nodoc:
  113. + (instancetype)new __attribute__((unavailable("RLMSyncManager cannot be created directly")));
  114. NS_ASSUME_NONNULL_END
  115. @end