1
wei
2021-01-21 62d098cb78296feaa6f786a20748921338db838c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
//
// TuyaSmartUser.h
// TuyaSmartBaseKit
//
// Copyright (c) 2014-2021 Tuya Inc. (https://developer.tuya.com)
 
#ifndef TuyaSmart_TuyaSmartUser
#define TuyaSmart_TuyaSmartUser
 
#import <UIKit/UIKit.h>
#import <TuyaSmartUtil/TuyaSmartUtil.h>
 
NS_ASSUME_NONNULL_BEGIN
 
/// Notification will be sent when user session is invalid.
extern NSString *const TuyaSmartUserNotificationUserSessionInvalid;
 
/// User register type.
typedef NS_ENUM(NSInteger, TYRegType) {
    /// Register from email.
    TYRegEmailType,
    /// Register from mobile phone.
    TYRegPhoneType,
    /// Register from other.
    TYRegOtherType,
    /// Register from QQ.
    TYRegQQType,
    /// Register from Weibo.
    TYRegWeiboType,
    /// Register from Facebook.
    TYRegFacebookType,
    /// Register from Twitter.
    TYRegTwitterType,
    /// Register from WeChat.
    TYRegWechatType,
    /// Register from Apple.
    TYRegAppleIdType,
    /// Register from google.
    TYRegGoogleType,
};
 
/// User-related functions.
@interface TuyaSmartUser : NSObject
 
/// Returns the singleton of the class.
+ (instancetype)sharedInstance;
 
/// Session ID.
@property (nonatomic, strong, readonly) NSString *sid;
 
/// User ID.
@property (nonatomic, strong, readonly) NSString *uid;
 
/// Head icon.
@property (nonatomic, strong, readonly) NSString *headIconUrl;
 
/// Nick name.
@property (nonatomic, strong, readonly) NSString *nickname;
 
/// Username. If account is mobile phone, this is mobile phone. If account is email, this is email.
@property (nonatomic, strong, readonly) NSString *userName;
 
/// Mobile phone.
@property (nonatomic, strong, readonly) NSString *phoneNumber;
 
/// Email.
@property (nonatomic, strong, readonly) NSString *email;
 
/// Country code. `86` for China, `1` for America.
@property (nonatomic, strong, readonly) NSString *countryCode;
 
/// Login status.
@property (nonatomic, assign, readonly) BOOL isLogin;
 
/// The region code of current account. `AY` for China, `AZ` for America, `EU` for Europe.
@property (nonatomic, strong, readonly) NSString *regionCode;
 
/// The api domains of current account region.
@property (nonatomic, strong, readonly) NSDictionary *domain;
 
/// Timezone ID. e.g. `Asia/Shanghai`.
@property (nonatomic, strong, readonly) NSString *timezoneId;
 
@property (nonatomic, strong, readonly) NSString *partnerIdentity;
 
/// MQTT host.
@property (nonatomic, strong, readonly) NSString *mbHost;
 
@property (nonatomic, strong, readonly) NSString *gwHost;
 
/// MQTT port.
@property (nonatomic, assign, readonly) NSInteger port;
 
/// Whether to enable SSL.
@property (nonatomic, assign, readonly) BOOL useSSL;
 
/// QUIC host.
@property (nonatomic, strong, readonly) NSString *quicHost;
 
/// QUIC port.
@property (nonatomic, assign, readonly) NSInteger quicPort;
 
/// Whether to enable QUIC.
@property (nonatomic, assign, readonly) BOOL useQUIC;
 
/// Temperature unit. 1 for `°C`, 2 for `°F`.
@property (nonatomic, assign) NSInteger tempUnit;
 
/// User register type.
@property (nonatomic, assign, readonly) TYRegType regFrom;
 
/// Nickname of SNS account.
@property (nonatomic, strong, readonly) NSString *snsNickname;
 
@property (nonatomic, strong, readonly) NSString *ecode;
 
/// User type.
@property (nonatomic, assign, readonly) NSInteger userType;
 
/// Extra parameters.
@property (nonatomic, strong, readonly) NSDictionary *extras;
 
 
#pragma mark - Mobile phone verification code login
 
/// Send verification code. Used for mobile phone verification code login, register, password reset.
/// @param countryCode Country code.
/// @param phoneNumber Mobile phone number.
/// @param type  0: mobile phone verification code login, 1: mobile phone verification code register, 2: mobile phone password reset.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)sendVerifyCode:(NSString *)countryCode
           phoneNumber:(NSString *)phoneNumber
                  type:(NSInteger)type
               success:(nullable TYSuccessHandler)success
               failure:(nullable TYFailureError)failure;
 
/// Mobile phone verification code login.
/// @param mobile Mobile phone number.
/// @param countryCode Country code.
/// @param code Verification code.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)loginWithMobile:(NSString *)mobile
            countryCode:(NSString *)countryCode
                   code:(NSString *)code
                success:(TYSuccessHandler)success
                failure:(TYFailureError)failure;
 
 
#pragma mark - Mobile phone binding
 
/// Send verification code. Used for mobile phone bind, mobile phone change.
/// @param countryCode Country code.
/// @param phoneNumber Mobile phone number.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)sendBindVerifyCode:(NSString *)countryCode
               phoneNumber:(NSString *)phoneNumber
                   success:(nullable TYSuccessHandler)success
                   failure:(nullable TYFailureError)failure;
 
/// Mobile phone bind.
/// @param countryCode Country code.
/// @param phoneNumber Mobile phone number.
/// @param code Verification code.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)mobileBinding:(NSString *)countryCode
          phoneNumber:(NSString *)phoneNumber
                 code:(NSString *)code
              success:(nullable TYSuccessHandler)success
              failure:(nullable TYFailureError)failure;
 
#pragma mark - Mobile phone password login
 
/// Mobile phone register.
/// @param countryCode Country code.
/// @param phoneNumber Mobile phone number.
/// @param password Password.
/// @param code Verification code.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)registerByPhone:(NSString *)countryCode
            phoneNumber:(NSString *)phoneNumber
               password:(NSString *)password
                   code:(NSString *)code
                success:(nullable TYSuccessHandler)success
                failure:(nullable TYFailureError)failure;
 
/// Mobile phone password login.
/// @param countryCode Country code.
/// @param phoneNumber Mobile phone number.
/// @param password Password.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)loginByPhone:(NSString *)countryCode
         phoneNumber:(NSString *)phoneNumber
            password:(NSString *)password
             success:(nullable TYSuccessHandler)success
             failure:(nullable TYFailureError)failure;
 
/// Mobile phone password reset.
/// @param countryCode  Country code.
/// @param phoneNumber Mobile phone number.
/// @param newPassword New password.
/// @param code Verification code.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)resetPasswordByPhone:(NSString *)countryCode
                 phoneNumber:(NSString *)phoneNumber
                 newPassword:(NSString *)newPassword
                        code:(NSString *)code
                     success:(nullable TYSuccessHandler)success
                     failure:(nullable TYFailureError)failure;
 
#pragma mark - Email login
 
/// Email login.
/// @param countryCode Country code.
/// @param email Email.
/// @param password Password.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)loginByEmail:(NSString *)countryCode
               email:(NSString *)email
            password:(NSString *)password
             success:(nullable TYSuccessHandler)success
             failure:(nullable TYFailureError)failure;
 
/// Send verification code, used for email password reset.
/// @param countryCode Country code.
/// @param email Email.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)sendVerifyCodeByEmail:(NSString *)countryCode
                        email:(NSString *)email
                      success:(nullable TYSuccessHandler)success
                      failure:(nullable TYFailureError)failure;
 
/// Email password reset.
/// @param countryCode Country code.
/// @param email Email.
/// @param newPassword New password.
/// @param code Verification code.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)resetPasswordByEmail:(NSString *)countryCode
                       email:(NSString *)email
                 newPassword:(NSString *)newPassword
                        code:(NSString *)code
                     success:(nullable TYSuccessHandler)success
                     failure:(nullable TYFailureError)failure;
 
 
#pragma mark - Email register 2.0
 
/// Send verification code, used for email password register.
/// @param countryCode Country code.
/// @param email Email.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)sendVerifyCodeByRegisterEmail:(NSString *)countryCode
                                email:(NSString *)email
                              success:(nullable TYSuccessHandler)success
                              failure:(nullable TYFailureError)failure;
 
/// Email register 2.0.
/// @param countryCode Country code.
/// @param email Email.
/// @param password Password.
/// @param code Verification code.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)registerByEmail:(NSString *)countryCode
                  email:(NSString *)email
               password:(NSString *)password
                   code:(NSString *)code
                success:(nullable TYSuccessHandler)success
                failure:(nullable TYFailureError)failure;
 
#pragma mark - Email verification code login
 
/// Email verification code login.
/// @param email Email.
/// @param countryCode Country code.
/// @param code Verification code.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)loginWithEmail:(NSString *)email countryCode:(NSString *)countryCode code:(NSString *)code success:(TYSuccessHandler)success failure:(TYFailureError)failure;
 
#pragma mark - Email bind
 
/// Get email binding verification code.
/// @param email E-mail.
/// @param countryCode Country Code.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)sendBindingVerificationCodeWithEmail:(NSString *)email
                                 countryCode:(NSString *)countryCode
                                     success:(nullable TYSuccessHandler)success
                                     failure:(nullable TYFailureError)failure;
 
/// Binding email.
/// @param email E-mail.
/// @param countryCode Country Code.
/// @param code Verification Code.
/// @param sId User session ID.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)bindEmail:(NSString *)email
  withCountryCode:(NSString *)countryCode
             code:(NSString *)code
              sId:(NSString *)sId
          success:(nullable TYSuccessHandler)success
          failure:(nullable TYFailureError)failure;
 
#pragma mark - uid login
 
/// User ID. login/register. The account will be registered at first login.
/// @param countryCode Country code.
/// @param uid User ID.
/// @param password Password.
/// @param createHome Create default home.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)loginOrRegisterWithCountryCode:(NSString *)countryCode
                                   uid:(NSString *)uid
                              password:(NSString *)password
                            createHome:(BOOL)createHome
                               success:(nullable TYSuccessID)success
                               failure:(nullable TYFailureError)failure;
 
#pragma mark - Social login
 
/// QQ login.
/// @param countryCode Country code.
/// @param userId UserId from QQ authorization login.
/// @param accessToken AccessToken from QQ authorization login.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)loginByQQ:(NSString *)countryCode
           userId:(NSString *)userId
      accessToken:(NSString *)accessToken
          success:(nullable TYSuccessHandler)success
          failure:(nullable TYFailureError)failure;
 
/// WeChat login.
/// @param countryCode Country code.
/// @param code Code from WeChat authorization login.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)loginByWechat:(NSString *)countryCode
                 code:(NSString *)code
              success:(nullable TYSuccessHandler)success
              failure:(nullable TYFailureError)failure;
 
/// Facebook Login.
/// @param countryCode Country code.
/// @param token Token from Facebook authorization login
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)loginByFacebook:(NSString *)countryCode
                  token:(NSString *)token
                success:(nullable TYSuccessHandler)success
                failure:(nullable TYFailureError)failure;
 
/// Twitter login.
/// @param countryCode Country code.
/// @param key Key from Twitter authorization login.
/// @param secret Secret from Twitter authorization login.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)loginByTwitter:(NSString *)countryCode
                   key:(NSString *)key
                secret:(NSString *)secret
               success:(nullable TYSuccessHandler)success
               failure:(nullable TYFailureError)failure;
 
/// Third login.
/// @param type Login type(ap for "login with apple").
/// @param countryCode Country code.
/// @param accessToken  Token from third authorization login.
/// @param extraInfo Extra params.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)loginByAuth2WithType:(NSString *)type
                 countryCode:(NSString *)countryCode
                 accessToken:(NSString *)accessToken
                   extraInfo:(NSDictionary *)extraInfo
                     success:(nullable TYSuccessHandler)success
                     failure:(nullable TYFailureError)failure;
 
#pragma mark -
 
/// Logout.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)loginOut:(nullable TYSuccessHandler)success
         failure:(nullable TYFailureError)failure;
 
/// Edit nick name.
/// @param nickName Nick name.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)updateNickname:(NSString *)nickName
               success:(nullable TYSuccessHandler)success
               failure:(nullable TYFailureError)failure;
 
/// Edit head icon.
/// @param headIcon Head icon.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)updateHeadIcon:(UIImage *)headIcon
               success:(nullable TYSuccessHandler)success
               failure:(nullable TYFailureError)failure;
 
/// Update user information.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)updateUserInfo:(nullable TYSuccessHandler)success
               failure:(nullable TYFailureError)failure;
 
/// Edit user timezone information.
/// @param timeZoneId TimeZone ID. e.g. `Asia/Shanghai`.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)updateTimeZoneWithTimeZoneId:(NSString *)timeZoneId
                             success:(nullable TYSuccessHandler)success
                             failure:(nullable TYFailureError)failure;
 
/// Edit user temperature unit.
/// @param tempUnit Temperature unit. 1 for `°C`, 2 for `°F`.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)updateTempUnitWithTempUnit:(NSInteger)tempUnit
                           success:(nullable TYSuccessHandler)success
                           failure:(nullable TYFailureError)failure;
 
/// Destroy account. One week after, all of the account information will be removed from server forever. If you login before removed, the destroy request will be canceled.
/// @param success Called when the task finishes successfully.
/// @param failure Called when the task is interrupted by an error.
- (void)cancelAccount:(nullable TYSuccessHandler)success
              failure:(nullable TYFailureError)failure;
 
 
#pragma mark -
 
/// Cancel network request.
- (void)cancelRequest;
 
@end
 
#endif
 
NS_ASSUME_NONNULL_END