Skip to content

Commit

Permalink
Merge pull request #1367 from QuickBlox/Release-UIKit-Sample-1.1.1
Browse files Browse the repository at this point in the history
Release UIKit Sample 1.1.0
  • Loading branch information
VladimirNybozhinsky authored Oct 30, 2023
2 parents 05e50e8 + 3d686bf commit f2e0008
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 106 deletions.
2 changes: 2 additions & 0 deletions sample-ui-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Quickblox.initWithApplicationId(92,

# QBAIAnswerAssistant

[Video tutorial](https://youtu.be/1HaTipnH2VY)

QBAIAnswerAssistant is a Swift package that helps generate answers in a chat based on the history.

Installation
Expand Down
8 changes: 4 additions & 4 deletions sample-ui-kit/UIKitSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@
"$(inherited)",
"$(SRCROOT)/../ios-ui-kit-private/Sources/QuickBloxUIKit/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../ios-ui-kit-private/Sources/QuickBloxUIKit/**",
Expand Down Expand Up @@ -551,7 +551,7 @@
"$(inherited)",
"$(SRCROOT)/../ios-ui-kit-private/Sources/QuickBloxUIKit/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/../ios-ui-kit-private/Sources/QuickBloxUIKit/**",
Expand Down Expand Up @@ -595,7 +595,7 @@
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -643,7 +643,7 @@
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/QuickBlox/ios-ui-kit.git",
"state" : {
"revision" : "8e2dc71ee9fe53fcdc65b7c4b0a7215fec41f0e6",
"version" : "0.3.0"
"revision" : "a59acec737b49b2a0c069016179644703b3374f1",
"version" : "0.3.1"
}
}
],
Expand Down
56 changes: 27 additions & 29 deletions sample-ui-kit/UIKitSample/Connect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import SwiftUI
import Combine
import Quickblox

enum ConnectState {
Expand All @@ -19,16 +20,22 @@ enum ConnectState {

enum AuthState {
case authorized
case authorization
case unAuthorized
}

class Connect: ObservableObject {
@Published var authState: AuthState = .unAuthorized
@Published var state: ConnectState = .waiting

public let objectWillChange = PassthroughSubject<AuthState, Never>()

@Published var authState: AuthState = .unAuthorized {
didSet {
objectWillChange.send(authState)
}
}
@Published var isConnected: Bool = false

init(state: ConnectState = .disconnected) {
self.state = state

Quickblox.initWithApplicationId(0,
authKey: "",
Expand All @@ -40,32 +47,35 @@ class Connect: ObservableObject {
}

func login(withLogin login: String, password: String) {
state = .waiting
authState = .authorization
QBRequest.logIn(withUserLogin: login.trimmingCharacters(in: .whitespacesAndNewlines),
password: password.trimmingCharacters(in: .whitespacesAndNewlines)) { [weak self] response, user in
guard QBSession.current.sessionDetails?.token != nil else {
print("Login Error: \(response)")
self?.state = .disconnected
self?.authState = .unAuthorized
DispatchQueue.main.async {
self?.authState = .unAuthorized
}
return
}
self?.authState = .authorized
DispatchQueue.main.async {
self?.authState = .authorized
}
} errorBlock: { [weak self] response in
if response.status == QBResponseStatusCode.unAuthorized {
// The user with existent login was created earlier
self?.state = .unAuthorized
self?.authState = .unAuthorized
return
}
print("Login Error: \(response)")
self?.authState = .unAuthorized
self?.state = .disconnected
DispatchQueue.main.async {
self?.authState = .unAuthorized
}
return
}
}

func signUp(withLogin login: String, displayName: String, password: String) {
state = .waiting
authState = .authorization
let newUser = QBUUser()
newUser.login = login.trimmingCharacters(in: .whitespacesAndNewlines)
newUser.fullName = displayName
Expand All @@ -76,35 +86,23 @@ class Connect: ObservableObject {
if response.status == QBResponseStatusCode.validationFailed {
// The user with existent login was created earlier
self?.login(withLogin: login, password: password)
self?.state = .waiting
return
}
print("Login Error: \(response)")
self?.state = .disconnected
DispatchQueue.main.async {
self?.authState = .unAuthorized
}
return
})
}

func connect(withUserID userId: UInt) {
state = .waiting
guard let token = QBSession.current.sessionDetails?.token else {
self.state = .disconnected
return
}
QBChat.instance.connect(withUserID: userId, password: token) { [weak self] _ in
self?.isConnected = true
self?.state = .connected
print("Success connect")
}
}

func disconnect() {
state = .waiting
QBChat.instance.disconnect() {_ in
self.isConnected = false
self.state = .disconnected
QBRequest.logOut { [weak self] response in
self?.authState = .unAuthorized
DispatchQueue.main.async {
self?.authState = .unAuthorized
}
print("Success disconnect")
}
}
Expand Down
Loading

0 comments on commit f2e0008

Please sign in to comment.