@@ -47,6 +47,10 @@ - (instancetype)init {
4747
4848@end
4949
50+ @implementation LCIMClientOption
51+
52+ @end
53+
5054@implementation LCIMClient {
5155 LCIMClientStatus _status;
5256}
@@ -75,48 +79,72 @@ - (instancetype)init
7579- (instancetype )initWithClientId : (NSString *)clientId
7680 error : (NSError *__autoreleasing _Nullable *)error
7781{
78- return [self initWithClientId: clientId
79- tag: nil
80- error: error];
82+ return [self initWithClientId: clientId tag: nil error: error];
83+ }
84+
85+ - (instancetype )initWithClientId : (NSString *)clientId
86+ option : (LCIMClientOption *)option
87+ error : (NSError *__autoreleasing _Nullable *)error
88+ {
89+ return [self initWithClientId: clientId tag: nil option: option error: error];
90+ }
91+
92+ - (instancetype )initWithClientId : (NSString *)clientId
93+ tag : (NSString *)tag
94+ error : (NSError *__autoreleasing _Nullable *)error
95+ {
96+ return [self initWithClientId: clientId tag: tag option: nil error: error];
8197}
8298
8399- (instancetype )initWithClientId : (NSString *)clientId
84100 tag : (NSString *)tag
101+ option : (LCIMClientOption *)option
85102 error : (NSError *__autoreleasing _Nullable *)error
86103{
87- return [self initWithClientId: clientId
88- tag: tag
89- installation: [LCInstallation defaultInstallation ]
90- error: error];
104+ LCInstallation *installation = [LCInstallation defaultInstallation ];
105+ return [self initWithClientId: clientId tag: tag option: option installation: installation error: error];
91106}
92107
93108- (instancetype )initWithUser : (LCUser *)user
94109 error : (NSError *__autoreleasing _Nullable *)error
95110{
96- return [self initWithUser: user
97- tag: nil
98- error: error];
111+ return [self initWithUser: user tag: nil error: error];
112+ }
113+
114+ - (instancetype )initWithUser : (LCUser *)user
115+ option : (LCIMClientOption *)option
116+ error : (NSError *__autoreleasing _Nullable *)error
117+ {
118+ return [self initWithUser: user tag: nil option: option error: error];
99119}
100120
101121- (instancetype )initWithUser : (LCUser *)user
102122 tag : (NSString *)tag
103123 error : (NSError *__autoreleasing _Nullable *)error
104124{
105- return [self initWithUser: user
106- tag: tag
107- installation: [LCInstallation defaultInstallation ]
108- error: error];
125+ return [self initWithUser: user tag: tag option: nil error: error];
126+ }
127+
128+ - (instancetype )initWithUser : (LCUser *)user
129+ tag : (NSString *)tag
130+ option : (LCIMClientOption *)option
131+ error : (NSError *__autoreleasing _Nullable *)error
132+ {
133+ LCInstallation *installation = [LCInstallation defaultInstallation ];
134+ return [self initWithUser: user tag: tag option: option installation: installation error: error];
109135}
110136
111137- (instancetype )initWithClientId : (NSString *)clientId
112138 tag : (NSString *)tag
139+ option : (LCIMClientOption *)option
113140 installation : (LCInstallation *)installation
114141 error : (NSError *__autoreleasing _Nullable *)error
115142{
116143 self = [super init ];
117144 if (self) {
118145 NSError *err = [self doInitializationWithClientId: clientId
119146 tag: tag
147+ option: option
120148 installation: installation];
121149 if (err) {
122150 if (error) {
@@ -130,6 +158,7 @@ - (instancetype)initWithClientId:(NSString *)clientId
130158
131159- (instancetype )initWithUser : (LCUser *)user
132160 tag : (NSString *)tag
161+ option : (LCIMClientOption *)option
133162 installation : (LCInstallation *)installation
134163 error : (NSError *__autoreleasing _Nullable *)error
135164{
@@ -138,6 +167,7 @@ - (instancetype)initWithUser:(LCUser *)user
138167 _user = user;
139168 NSError *err = [self doInitializationWithClientId: user.objectId
140169 tag: tag
170+ option: option
141171 installation: installation];
142172 if (err) {
143173 if (error) {
@@ -151,6 +181,7 @@ - (instancetype)initWithUser:(LCUser *)user
151181
152182- (NSError *)doInitializationWithClientId : (NSString *)clientId
153183 tag : (NSString *)tag
184+ option : (LCIMClientOption *)option
154185 installation : (LCInstallation *)installation
155186{
156187 if (!clientId ||
@@ -212,14 +243,17 @@ - (NSError *)doInitializationWithClientId:(NSString *)clientId
212243 delegate: self
213244 queue: _internalSerialQueue];
214245 _conversationManager = [[LCIMClientInternalConversationManager alloc ] initWithClient: self ];
215- _installation = installation;
216- _currentDeviceToken = installation.deviceToken ;
217- [installation addObserver: self
218- forKeyPath: keyPath (installation, deviceToken)
219- options: (NSKeyValueObservingOptionNew |
220- NSKeyValueObservingOptionOld |
221- NSKeyValueObservingOptionInitial)
222- context: (__bridge void *)(self )];
246+ BOOL isAutoBindingInstallationEnabled = (option ? !option.isAutoBindingInstallationDisabled : true );
247+ if (isAutoBindingInstallationEnabled) {
248+ _installation = installation;
249+ _currentDeviceToken = installation.deviceToken ;
250+ [installation addObserver: self
251+ forKeyPath: keyPath (installation, deviceToken)
252+ options: (NSKeyValueObservingOptionNew |
253+ NSKeyValueObservingOptionOld |
254+ NSKeyValueObservingOptionInitial)
255+ context: (__bridge void *)(self )];
256+ }
223257 _conversationCache = ({
224258 LCIMConversationCache *cache = [[LCIMConversationCache alloc ] initWithClientId: _clientId];
225259 cache.client = self;
@@ -1815,7 +1849,8 @@ - (void)removeAllConversationsInMemoryWith:(void (^)(void))callback
18151849- (void )observeValueForKeyPath : (NSString *)keyPath ofObject : (id )object change : (NSDictionary *)change context : (void *)context
18161850{
18171851 if (context == (__bridge void *)(self)) {
1818- if ([keyPath isEqualToString: keyPath (self .installation, deviceToken)] &&
1852+ if (self.installation &&
1853+ [keyPath isEqualToString: keyPath (self .installation, deviceToken)] &&
18191854 object == self.installation ) {
18201855 NSString *oldToken = [NSString _lc_decoding: change key: NSKeyValueChangeOldKey ];
18211856 NSString *newToken = [NSString _lc_decoding: change key: NSKeyValueChangeNewKey ];
0 commit comments