@@ -114,8 +114,11 @@ private var sharedInstance: UserReport?
114
114
/**
115
115
* Tracking screen view
116
116
*/
117
- @objc public func trackScreenView( ) {
118
-
117
+ @objc public class func trackScreenView( ) {
118
+ UserReport . shared? . trackScreenView ( )
119
+ }
120
+
121
+ @objc private func trackScreenView( ) {
119
122
// Track audience every screen view instead first screen view because we already tracked audience when initialize SDK
120
123
if self . session. screenView != 0 {
121
124
self . sendTrackScreenView ( )
@@ -128,7 +131,11 @@ private var sharedInstance: UserReport?
128
131
/**
129
132
* Tracking section screen view
130
133
*/
131
- @objc public func trackSectionScreenView( _ sectionId: String ) {
134
+ @objc public class func trackSectionScreenView( _ sectionId: String ) {
135
+ UserReport . shared? . trackSectionScreenView ( sectionId)
136
+ }
137
+
138
+ @objc private func trackSectionScreenView( _ sectionId: String ) {
132
139
self . sendTrackSectionScreenView ( sectionId)
133
140
134
141
// Update session `screenView` and `totalScreenView` values
@@ -139,7 +146,11 @@ private var sharedInstance: UserReport?
139
146
* Force show survey on screen.
140
147
* Will send invitation request to backend. Depending on response will invite to take survey or not.
141
148
*/
142
- @objc public func tryInvite( ) {
149
+ @objc public class func tryInvite( ) {
150
+ UserReport . shared? . tryInvite ( )
151
+ }
152
+
153
+ @objc private func tryInvite( ) {
143
154
self . tryInvite ( force: true )
144
155
}
145
156
@@ -225,7 +236,7 @@ private var sharedInstance: UserReport?
225
236
* This method sends visit request to backend and user for sure will not be invited to take survey.
226
237
*/
227
238
private func logVisit( ) {
228
- self . network. visit ( info: self . info) { ( result) in
239
+ self . network. visit ( info: self . info) { [ unowned self ] ( result) in
229
240
switch ( result) {
230
241
case . success:
231
242
self . logger. log ( " Log visit " , level: . info)
@@ -243,7 +254,7 @@ private var sharedInstance: UserReport?
243
254
return
244
255
}
245
256
246
- self . network. trackScreenView ( info: self . info, tCode: tCode) { ( result) in
257
+ self . network. trackScreenView ( info: self . info, tCode: tCode) { [ unowned self ] ( result) in
247
258
switch ( result) {
248
259
case . success:
249
260
self . logger. log ( " Viewed screen " , level: . info)
@@ -302,9 +313,9 @@ private var sharedInstance: UserReport?
302
313
self . surveyStatus = . requestInvite
303
314
304
315
/// Set local quarantine for reason some internal troubles
305
- self . session . updateLocalQuarantineDate ( self . getLocalQuarantineDate ( ) )
316
+ self . getLocalQuarantineDate ( ) . map ( self . session . updateLocalQuarantineDate )
306
317
307
- self . network. invitation ( info: self . info) { ( result) in
318
+ self . network. invitation ( info: self . info) { [ unowned self ] ( result) in
308
319
switch ( result) {
309
320
case . success:
310
321
/// Get userId and invitationId from API response
@@ -341,12 +352,12 @@ private var sharedInstance: UserReport?
341
352
/**
342
353
* Adds local quarantine days from settings to currebnt date.
343
354
*/
344
- private func getLocalQuarantineDate( ) -> Date {
355
+ private func getLocalQuarantineDate( ) -> Date ? {
345
356
let currentDate = Date ( )
346
357
var dateComponent = DateComponents ( )
347
358
dateComponent. day = self . session. settings? . localQuarantineDays
348
359
349
- return Calendar . current. date ( byAdding: dateComponent, to: currentDate) !
360
+ return Calendar . current. date ( byAdding: dateComponent, to: currentDate)
350
361
}
351
362
352
363
/**
@@ -362,9 +373,9 @@ private var sharedInstance: UserReport?
362
373
surveyVC. modalTransitionStyle = . crossDissolve
363
374
surveyVC. modalPresentationStyle = . overCurrentContext
364
375
surveyVC. load ( )
365
- surveyVC. loadDidFinish = {
376
+ surveyVC. loadDidFinish = { [ unowned surveyVC ] in
366
377
self . surveyStatus = . surveyShown
367
- UIApplication . shared. keyWindow? . rootViewController? . present ( surveyVC, animated: true , completion : nil )
378
+ UIApplication . shared. keyWindow? . rootViewController? . present ( surveyVC, animated: true )
368
379
}
369
380
surveyVC. loadDidFail = { ( error) in
370
381
self . surveyStatus = . none
@@ -378,20 +389,23 @@ private var sharedInstance: UserReport?
378
389
}
379
390
380
391
/// Handle survey close native 'X' button
381
- surveyVC. handlerCloseButton = {
392
+ surveyVC. handlerCloseButton = { [ unowned surveyVC ] in
382
393
self . surveyStatus = . none
383
- surveyVC. dismiss ( animated: true , completion : nil )
394
+ surveyVC. dismiss ( animated: true )
384
395
385
396
/// Send 'close' quarantine reason to API
386
- self . network. setQuarantine ( reason: " Close " , mediaId: self . info. media. mediaId, invitationId: self . invitationId, userId: self . userId) { ( result) in }
397
+ self . network. setQuarantine ( reason: " Close " ,
398
+ mediaId: self . info. media. mediaId,
399
+ invitationId: self . invitationId,
400
+ userId: self . userId) { ( result) in }
387
401
388
402
self . scheduleActualizeLocalQuarantine ( )
389
403
}
390
404
391
405
/// Handle survey close event by 'No' / 'Close' button
392
- surveyVC. handlerSurveyClosedEvent = {
406
+ surveyVC. handlerSurveyClosedEvent = { [ unowned surveyVC ] in
393
407
self . surveyStatus = . none
394
- surveyVC. dismiss ( animated: true , completion : nil )
408
+ surveyVC. dismiss ( animated: true )
395
409
396
410
self . scheduleActualizeLocalQuarantine ( )
397
411
}
@@ -402,26 +416,30 @@ private var sharedInstance: UserReport?
402
416
* Schedule is needed to avoid race of close event and getting quarantine API call
403
417
*/
404
418
@objc private func scheduleActualizeLocalQuarantine( ) {
405
- Timer . scheduledTimer ( timeInterval: 3 , target: self , selector: #selector( self . actualizeLocalQuarantine) , userInfo: nil , repeats: false )
419
+ Timer . scheduledTimer ( timeInterval: 3 ,
420
+ target: self ,
421
+ selector: #selector( self . actualizeLocalQuarantine) ,
422
+ userInfo: nil , repeats: false )
406
423
}
407
424
408
425
/**
409
426
* Set correct local quarantine accoding to user behevior
410
427
*/
411
428
@objc private func actualizeLocalQuarantine( ) -> Void {
412
429
/// Get current local quarantine from API
413
- self . network. getQuarantineInfo ( userId: self . userId, mediaId: self . info. media. mediaId) { ( result) in
430
+ self . network. getQuarantineInfo ( userId: self . userId,
431
+ mediaId: self . info. media. mediaId) { [ unowned self] ( result) in
414
432
415
433
switch ( result) {
416
434
case . success:
417
435
if ( result. value? . isInLocal) ! {
418
436
let localQuarantineDate = result. value? . inLocalTill
419
437
let dateFormatter = DateFormatter ( )
420
- dateFormatter. timeZone = TimeZone . init ( identifier: " UTC " )
438
+ dateFormatter. timeZone = TimeZone ( identifier: " UTC " )
421
439
dateFormatter. dateFormat = " yyyy'-'MM'-'dd'T'HH':'mm':'ss "
422
- let date = dateFormatter. date ( from : localQuarantineDate! )
440
+ let date = localQuarantineDate . flatMap ( dateFormatter. date)
423
441
424
- self . session. updateLocalQuarantineDate ( date! )
442
+ date . map ( self . session. updateLocalQuarantineDate)
425
443
}
426
444
427
445
case . failure( let error) :
0 commit comments