Skip to content

Commit 4b51675

Browse files
authored
Merge pull request #1 from hmvs/master
Updating SDK
2 parents 6ad8179 + ea000f2 commit 4b51675

File tree

16 files changed

+302
-69
lines changed

16 files changed

+302
-69
lines changed

Example/Example/AppDelegate.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1111
var window: UIWindow?
1212

1313
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
14+
15+
let settings = Settings()
16+
settings.sessionScreensView = 14
1417

1518
// Initialize UserReport SDK
1619
let user = User()
1720
user.email = "[email protected]"
18-
UserReport.configure(sakId: "ios-playground", mediaId: "df5be674-b6a8-4bb8-8f44-4c8229a01bc2", user: user)
21+
UserReport.configure(sakId: "ios-playground", mediaId: "df5be674-b6a8-4bb8-8f44-4c8229a01bc2", user: user, userSettings: settings)
22+
1923

2024
return true
2125
}

Example/Example/ViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ class ViewController: UserReportViewController {
9090
self.sessionScreensLabel.text = "\(session.screenView) screens"
9191
self.totalTimeLabel.text = session.totalSecondsInApp.stringTime()
9292
self.sessionTimeLabel.text = session.sessionSeconds.stringTime()
93-
self.quarantineTimeLabel.text = "\(session.localQuarantineDays) days"
93+
self.quarantineTimeLabel.text = Date().description
9494

9595
// Get current settings for appear survey
9696
guard let settings = session.settings else { return }
9797
self.expectedTotalScreensLabel.text = "\(settings.inviteAfterTotalScreensViewed) screens"
9898
self.expectedSessionScreensLabel.text = "\(settings.sessionScreensView) screens"
9999
self.expectedTotalTimeLabel.text = settings.inviteAfterNSecondsInApp.stringTime()
100100
self.expectedSessionTimeLabel.text = settings.sessionNSecondsLength.stringTime()
101-
self.expectedQuarantineTimeLabel.text = "\(settings.localQuarantineDays) days"
101+
self.expectedQuarantineTimeLabel.text = session.localQuarantineDate.description
102102
}
103103

104104
// MARK: Actions

Example_Objective-C/Example_Objective-C/AppDelegate.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
1717
// Initialize UserReport SDK
1818
User *user = [[User alloc] init];
1919
[user setEmail:@"[email protected]"];
20-
[UserReport configureWithSakId:@"ios-playground" mediaId:@"df5be674-b6a8-4bb8-8f44-4c8229a01bc2" user:user];
21-
20+
[UserReport configureWithSakId:@"ios-playground" mediaId:@"df5be674-b6a8-4bb8-8f44-4c8229a01bc2" user:user userSettings:nil];
2221
return YES;
2322
}
2423

Example_Objective-C/Example_Objective-C/ViewController.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,17 @@ - (void)setupNavigationBar {
6262
// MARK: Update
6363

6464
- (void)updateSessionInfo {
65+
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
66+
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
67+
6568
// Session information about the running time of the application and screen views
6669
Session *session = [[UserReport shared] session];
6770
if (session) {
6871
self.totalScreensLabel.text = [NSString stringWithFormat:@"%li screens", session.totalScreenView];
6972
self.sessionScreensLabel.text = [NSString stringWithFormat:@"%li screens", session.screenView];
7073
self.totalTimeLabel.text = [self stringFromTimeInterval:session.totalSecondsInApp];
7174
self.sessionTimeLabel.text = [self stringFromTimeInterval:session.sessionSeconds];
72-
self.quarantineTimeLabel.text = [NSString stringWithFormat:@"%li days", session.localQuarantineDays];
75+
self.quarantineTimeLabel.text = [dateFormatter stringFromDate:[NSDate date]];
7376
}
7477

7578
// Get current settings for appear survey
@@ -79,7 +82,7 @@ - (void)updateSessionInfo {
7982
self.expectedSessionScreensLabel.text = [NSString stringWithFormat:@"%li screens", settings.sessionScreensView];
8083
self.expectedTotalTimeLabel.text = [self stringFromTimeInterval:settings.inviteAfterNSecondsInApp];
8184
self.expectedSessionTimeLabel.text = [self stringFromTimeInterval:settings.sessionNSecondsLength];
82-
self.expectedQuarantineTimeLabel.text = [NSString stringWithFormat:@"%li days", settings.localQuarantineDays];
85+
self.expectedQuarantineTimeLabel.text = [dateFormatter stringFromDate:session.localQuarantineDate];
8386
}
8487
}
8588

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ user.emailSha256 = "SHA256_EMAIL_HASH"
5959
// Provide additional social network information
6060
user.facebookId = "FACEBOOK_ID"
6161
62+
//It is also possible to override default rules when survey will appear, though, userSettings parameter is optional
63+
let settings = Settings()
64+
settings.sessionScreensView = 5
65+
settings.inviteAfterNSecondsInApp = 20
66+
67+
UserReport.shared?.updateSettings(settings)
6268
// Configure
63-
UserReport.configure(sakId: "YOUR_SAK_ID", mediaId: "YOU_MEDIA_ID", user: user)
69+
UserReport.configure(sakId: "YOUR_SAK_ID", mediaId: "YOU_MEDIA_ID", user: user, userSetting: setting)
6470
6571
```
6672
### Screen tracking
@@ -101,7 +107,7 @@ UserReport.shared?.displayMode = .fullscreen
101107

102108
### Change settings
103109
To update the default rules for appear the survey use follow:
104-
110+
Though, it is recommended to pass `Settings` to configure method instead, use this method only when you want to change rules for already launched app
105111
```swift
106112
let settings = Settings()
107113
settings.sessionScreensView = 5
@@ -136,7 +142,7 @@ UserReport SDK stores the data on the count of screens viewed and the time the a
136142
- `totalScreenView` - number of screen viewed in all session
137143
- `sessionSeconds` - number of seconds spent in the application for current session
138144
- `totalSecondsInApp` - number of seconds spent in the application for all time
139-
- `localQuarantineDays` - number of days through which the survey will be appear again
145+
- `localQuarantineDate` - date until the survey will not appear again
140146
- `settings` - current settings for appear the survey
141147
142148

UserReport/UserReport.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
116BD1671F5814BF00D2386B /* UserReportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 116BD1611F58136100D2386B /* UserReportTests.swift */; };
3232
116BD16C1F5819D400D2386B /* Serialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 116BD16B1F5819D400D2386B /* Serialization.swift */; };
3333
11C71E9A1F6966040081D9B4 /* Session.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11C71E991F6966040081D9B4 /* Session.swift */; };
34+
8A4CF05A23D5D2860081C2D8 /* QuarantineRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A4CF05923D5D2860081C2D8 /* QuarantineRequest.swift */; };
35+
8A4CF05C23D5D2960081C2D8 /* QuarantineResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A4CF05B23D5D2960081C2D8 /* QuarantineResponse.swift */; };
3436
/* End PBXBuildFile section */
3537

3638
/* Begin PBXContainerItemProxy section */
@@ -72,6 +74,8 @@
7274
116BD1651F5814A800D2386B /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/iPhoneOS.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
7375
116BD16B1F5819D400D2386B /* Serialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Serialization.swift; sourceTree = "<group>"; };
7476
11C71E991F6966040081D9B4 /* Session.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Session.swift; sourceTree = "<group>"; };
77+
8A4CF05923D5D2860081C2D8 /* QuarantineRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuarantineRequest.swift; sourceTree = "<group>"; };
78+
8A4CF05B23D5D2960081C2D8 /* QuarantineResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuarantineResponse.swift; sourceTree = "<group>"; };
7579
/* End PBXFileReference section */
7680

7781
/* Begin PBXFrameworksBuildPhase section */
@@ -168,6 +172,8 @@
168172
116BD16B1F5819D400D2386B /* Serialization.swift */,
169173
1141EF3F1F6173D70011D10F /* Settings.swift */,
170174
110747471F4AF99B00150955 /* User.swift */,
175+
8A4CF05923D5D2860081C2D8 /* QuarantineRequest.swift */,
176+
8A4CF05B23D5D2960081C2D8 /* QuarantineResponse.swift */,
171177
);
172178
path = Models;
173179
sourceTree = "<group>";
@@ -326,6 +332,7 @@
326332
1107473B1F46FA6800150955 /* Result.swift in Sources */,
327333
110747411F46FD1900150955 /* Logger.swift in Sources */,
328334
110747541F4C766E00150955 /* Invitation.swift in Sources */,
335+
8A4CF05A23D5D2860081C2D8 /* QuarantineRequest.swift in Sources */,
329336
11666F331F6C0739007729A7 /* Store.swift in Sources */,
330337
1107473C1F46FA6800150955 /* SurveyViewController.swift in Sources */,
331338
116BD16C1F5819D400D2386B /* Serialization.swift in Sources */,
@@ -334,6 +341,7 @@
334341
11C71E9A1F6966040081D9B4 /* Session.swift in Sources */,
335342
110747431F471F0F00150955 /* UserReportViewController.swift in Sources */,
336343
110747481F4AF99B00150955 /* User.swift in Sources */,
344+
8A4CF05C23D5D2960081C2D8 /* QuarantineResponse.swift in Sources */,
337345
1107473A1F46FA6800150955 /* Network.swift in Sources */,
338346
110747281F44953000150955 /* UserReport.swift in Sources */,
339347
110747561F4C76B200150955 /* URError.swift in Sources */,

UserReport/UserReport/Models/Invitation.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ internal struct Invitation {
1515
/// Url with survey which need to be loaded
1616
var invitationUrl: String?
1717

18+
/// ID of user
19+
var userId: String?
20+
21+
/// ID of invitation
22+
var invitationId: String?
1823
}
1924

2025
/**
@@ -35,6 +40,14 @@ extension Invitation: Serialization {
3540
if let invitationUrl = dict["invitationUrl"] as? String {
3641
self.invitationUrl = invitationUrl
3742
}
43+
44+
if let userId = dict["userId"] as? String {
45+
self.userId = userId
46+
}
47+
48+
if let invitationId = dict["invitationId"] as? String {
49+
self.invitationId = invitationId
50+
}
3851
}
3952

4053
}

UserReport/UserReport/Models/MediaSettings.swift

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,29 @@ extension MediaSettings: Serialization {
3232
}
3333
self.companyId = companyId
3434

35-
guard let kitTcode = dict["kitTcode"] as? String else {
36-
throw URError.responseDataNotFoundKey("kitTcode")
35+
if let kitTcode = dict["kitTcode"] as? String {
36+
self.kitTcode = kitTcode
3737
}
38-
self.kitTcode = kitTcode
39-
40-
guard let localQuarantineDays = dict["localQuarantineDays"] as? Int else {
41-
throw URError.responseDataNotFoundKey("localQuarantineDays")
38+
39+
if let localQuarantineDays = dict["localQuarantineDays"] as? Int {
40+
self.settings.localQuarantineDays = localQuarantineDays
4241
}
43-
self.settings.localQuarantineDays = localQuarantineDays
4442

45-
guard let inviteAfterNSecondsInApp = dict["inviteAfterNSecondsInApp"] as? TimeInterval else {
46-
throw URError.responseDataNotFoundKey("inviteAfterNSecondsInApp")
43+
if let inviteAfterNSecondsInApp = dict["inviteAfterNSecondsInApp"] as? TimeInterval {
44+
self.settings.inviteAfterNSecondsInApp = inviteAfterNSecondsInApp
4745
}
48-
self.settings.inviteAfterNSecondsInApp = inviteAfterNSecondsInApp
4946

50-
guard let inviteAfterTotalScreensViewed = dict["inviteAfterTotalScreensViewed"] as? Int else {
51-
throw URError.responseDataNotFoundKey("inviteAfterTotalScreensViewed")
47+
if let inviteAfterTotalScreensViewed = dict["inviteAfterTotalScreensViewed"] as? Int {
48+
self.settings.inviteAfterTotalScreensViewed = inviteAfterTotalScreensViewed
5249
}
53-
self.settings.inviteAfterTotalScreensViewed = inviteAfterTotalScreensViewed
54-
55-
guard let sessionScreensView = dict["sessionScreensView"] as? Int else {
56-
throw URError.responseDataNotFoundKey("sessionScreensView")
50+
51+
if let sessionScreensView = dict["sessionScreensView"] as? Int {
52+
self.settings.sessionScreensView = sessionScreensView
5753
}
58-
self.settings.sessionScreensView = sessionScreensView
5954

60-
guard let sessionNSecondsLength = dict["sessionNSecondsLength"] as? TimeInterval else {
61-
throw URError.responseDataNotFoundKey("sessionNSecondsLength")
55+
if let sessionNSecondsLength = dict["sessionNSecondsLength"] as? TimeInterval {
56+
self.settings.sessionNSecondsLength = sessionNSecondsLength
6257
}
63-
self.settings.sessionNSecondsLength = sessionNSecondsLength
6458
}
6559

6660
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// QuarantineRequest.swift
3+
// UserReport
4+
//
5+
// Created by Maksym Binkovskyi on 20.01.2020.
6+
// Copyright © 2020 UserReport. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
internal struct QuarantineRequest {
12+
13+
var userId: String!
14+
15+
var mediaId: String!
16+
17+
init(userId: String, mediaId: String) {
18+
self.userId = userId
19+
self.mediaId = mediaId
20+
}
21+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// QuarantineResponse.swift
3+
// UserReport
4+
//
5+
// Created by Maksym Binkovskyi on 20.01.2020.
6+
// Copyright © 2020 UserReport. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
/**
12+
* Quarantine response from the server
13+
*/
14+
internal struct QuarantineResponse {
15+
16+
var inGlobalTill: String
17+
18+
var inLocalTill: String?
19+
20+
var isInGlobal: Bool!
21+
22+
var isInLocal: Bool!
23+
}
24+
25+
extension QuarantineResponse: Serialization {
26+
27+
init(dict: [String: Any?]) throws {
28+
29+
guard let inGlobalTill = dict["inGlobalTill"] as? String else {
30+
throw URError.responseDataNotFoundKey("inGlobalTill")
31+
}
32+
self.inGlobalTill = inGlobalTill
33+
34+
if let isInGlobal = dict["isInGlobal"] as? Bool {
35+
self.isInGlobal = isInGlobal
36+
}
37+
38+
if let isInLocal = dict["isInLocal"] as? Bool {
39+
self.isInLocal = isInLocal
40+
41+
if isInLocal {
42+
self.inLocalTill = dict["inLocalTill"] as? String
43+
}
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)