forked from robbywh/react-native-zendesk-messaging
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ZendeskMessaging.swift
61 lines (56 loc) · 1.77 KB
/
ZendeskMessaging.swift
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
import ZendeskSDKMessaging
import ZendeskSDK
@objc(ZendeskMessaging)
class ZendeskMessaging: NSObject {
@objc
static func requiresMainQueueSetup() -> Bool {
return true
}
@objc
func initialize(_ channelKey:String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
Zendesk.initialize(withChannelKey: channelKey,
messagingFactory: DefaultMessagingFactory()) { result in
if case let .failure(error) = result {
reject("error","\(error)",nil)
print("Messaging did not initialize.\nError: \(error.localizedDescription)")
} else {
resolve("success")
}
}
}
@objc
func showMessaging() {
DispatchQueue.main.async {
guard let zendeskController = Zendesk.instance?.messaging?.messagingViewController() else {
return }
let viewController = RCTPresentedViewController();
viewController?.present(zendeskController, animated: true) {
print("Messaging have shown")
}
}
}
@objc
func loginUser(_ token:String, resolver resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
Zendesk.instance?.loginUser(with: token) { result in
switch result {
case .success(let user):
print(user)
resolve(user)
case .failure(let error):
reject("error","\(error)",nil)
}
}
}
@objc
func logoutUser(_ resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
Zendesk.instance?.logoutUser { result in
switch result {
case .success:
resolve("success")
case .failure(let error):
reject("error","\(error)",nil)
}
}
}
}