Skip to content

Commit a9e54f4

Browse files
author
Arief Nur Putranto
committed
- fix crash clearAllComment
- fix crash when call getRoomInfo - bump up version 1.14.1
1 parent 7f4bd15 commit a9e54f4

File tree

5 files changed

+48
-29
lines changed

5 files changed

+48
-29
lines changed

QiscusCore.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "QiscusCore"
3-
s.version = "1.14.0"
3+
s.version = "1.14.1"
44
s.summary = "Qiscus Core SDK for iOS"
55
s.description = <<-DESC
66
Qiscus SDK for iOS contains Qiscus public Model.

Source/QiscusCore/Database/QiscusDatabase/Model/Comment+CoreDataClass.swift

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,7 @@ extension Comment {
8585

8686
/// Clear all comment data
8787
static func clear() {
88-
QiscusDatabase.context.perform({
89-
let fetchRequest:NSFetchRequest<Comment> = Comment.fetchRequest()
90-
do {
91-
let delete = NSBatchDeleteRequest(fetchRequest: fetchRequest as! NSFetchRequest<NSFetchRequestResult>)
92-
try QiscusDatabase.context.execute(delete)
93-
} catch {
94-
// failed to clear data
95-
}
96-
97-
})
98-
99-
100-
// let fetchRequest:NSFetchRequest<Comment> = Comment.fetchRequest()
101-
// let delete = NSBatchDeleteRequest(fetchRequest: fetchRequest as! NSFetchRequest<NSFetchRequestResult>)
102-
// do {
103-
// try QiscusDatabase.context.execute(delete)
104-
// } catch {
105-
// // failed to clear data
106-
// }
88+
QiscusDatabase.clearALLComment()
10789
}
10890

10991
// non static

Source/QiscusCore/Database/QiscusDatabase/QiscusDatabase.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import Foundation
10+
import CoreData
1011

1112
class QiscusDatabase {
1213
class var bundle:Bundle{
@@ -25,4 +26,22 @@ class QiscusDatabase {
2526
static func clear() {
2627
PresistentStore.clear()
2728
}
29+
30+
static func clearALLComment(){
31+
if #available(iOS 10.0, *) {
32+
let backgroundContext = PresistentStore.persistentContainer.newBackgroundContext()
33+
backgroundContext.perform {
34+
let fetchRequest: NSFetchRequest<NSFetchRequestResult> = Comment.fetchRequest()
35+
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
36+
37+
do {
38+
try backgroundContext.execute(deleteRequest)
39+
try backgroundContext.save()
40+
} catch {
41+
QiscusLogger.errorPrint("❌ Failed to clear Comment data")
42+
QiscusLogger.errorPrint("\(error.localizedDescription)")
43+
}
44+
}
45+
}
46+
}
2847
}

Source/QiscusCore/QiscusCore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010
import UIKit
1111

1212
public class QiscusCore: NSObject {
13-
public static let qiscusCoreVersionNumber:String = "1.14.0"
13+
public static let qiscusCoreVersionNumber:String = "1.14.1"
1414
class var bundle:Bundle{
1515
get{
1616
let podBundle = Bundle(for: QiscusCore.self)

Source/QiscusCore/QiscusRoom.swift

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,12 @@ extension QiscusCore {
184184
QiscusCore.network.getRoomInfo(roomIds: ids, roomUniqueIds: nil, showParticipant: showParticipant, showRemoved: showRemoved){ (rooms, error) in
185185
if let data = rooms {
186186
// save room
187-
QiscusCore.database.room.save(data)
188-
onSuccess(data)
187+
DispatchQueue.global(qos: .background).async {
188+
QiscusCore.database.room.save(data)
189+
DispatchQueue.main.async {
190+
onSuccess(data)
191+
}
192+
}
189193
}else {
190194
onError(error ?? QError(message: "Unexpected error"))
191195
}
@@ -212,8 +216,12 @@ extension QiscusCore {
212216
QiscusCore.network.getRoomInfo(roomIds: roomIds, roomUniqueIds: nil, showParticipant: showParticipant, showRemoved: showRemoved){ (rooms, error) in
213217
if let data = rooms {
214218
// save room
215-
QiscusCore.database.room.save(data)
216-
onSuccess(data)
219+
DispatchQueue.global(qos: .background).async {
220+
QiscusCore.database.room.save(data)
221+
DispatchQueue.main.async {
222+
onSuccess(data)
223+
}
224+
}
217225
}else {
218226
onError(error ?? QError(message: "Unexpected error"))
219227
}
@@ -241,8 +249,13 @@ extension QiscusCore {
241249
QiscusCore.network.getRoomInfo(roomIds: nil, roomUniqueIds: ids, showParticipant: showParticipant, showRemoved: showRemoved){ (rooms, error) in
242250
if let data = rooms {
243251
// save room
244-
QiscusCore.database.room.save(data)
245-
onSuccess(data)
252+
253+
DispatchQueue.global(qos: .background).async {
254+
QiscusCore.database.room.save(data)
255+
DispatchQueue.main.async {
256+
onSuccess(data)
257+
}
258+
}
246259
}else {
247260
onError(error ?? QError(message: "Unexpected error"))
248261
}
@@ -268,8 +281,13 @@ extension QiscusCore {
268281
QiscusCore.network.getRoomInfo(roomIds: nil, roomUniqueIds: uniqueIds, showParticipant: showParticipant, showRemoved: showRemoved){ (rooms, error) in
269282
if let data = rooms {
270283
// save room
271-
QiscusCore.database.room.save(data)
272-
onSuccess(data)
284+
DispatchQueue.global(qos: .background).async {
285+
QiscusCore.database.room.save(data)
286+
DispatchQueue.main.async {
287+
onSuccess(data)
288+
}
289+
}
290+
273291
}else {
274292
onError(error ?? QError(message: "Unexpected error"))
275293
}

0 commit comments

Comments
 (0)