Skip to content

Commit

Permalink
fix: hide the spinner after closing brower authorization (#23)
Browse files Browse the repository at this point in the history
* feat: register/unregister webhooks for tenants

add swtich for each unit to register/unrigister webhooks for tenants
remove APIClient

* chore: set ngrok id as a separate const

add @unknown default: to remove a warning

* fix: hide the spinner after closing brower authorization

rename butterflymxClientId to butterflymxClientIdTest and butterflymxSecret to butterflymxSecretTest to reflect actual environment

remove unnecessary BMXCoreDelegate in AppDelegate
remove didUpdate in LoginViewController

* fix: set authorizationWebViewDelegate

set LoginViewController as the authorizationWebViewDelegate of BMXCoreKit
  • Loading branch information
yingtao-butterflymx committed Jun 22, 2021
1 parent d81dcaa commit f76d55b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
12 changes: 0 additions & 12 deletions ButterflyMX Demo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
window!.rootViewController = loginViewController
}

BMXCoreKit.shared.delegate = self

CallsService.shared.setupVoipPush()
requestAccessMicCamera(callback: { status in
print("User media permission status \(status.rawValue)")
Expand Down Expand Up @@ -82,13 +80,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
}

extension AppDelegate: BMXCoreDelegate {
func didUpdate(accessToken: String, refreshToken: String) {
print(accessToken, refreshToken)
}

func logging(_ data: String) {
print("BMXSDK Log: \(data)")
}
}
21 changes: 14 additions & 7 deletions ButterflyMX Demo/Controllers/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import UIKit
import BMXCore
import SVProgressHUD
import SafariServices

class LoginViewController: UITableViewController {

@IBOutlet weak var singInButton: UIButton!
Expand Down Expand Up @@ -62,6 +64,7 @@ class LoginViewController: UITableViewController {
super.viewDidLoad()
UserDefaults.standard.set("development", forKey: "environment")
BMXCoreKit.shared.delegate = self
BMXCoreKit.shared.authorizationWebViewDelegate = self
authProvider = getBMXAuthProvider(for: environmentType)
SVProgressHUD.setDefaultStyle(.light)
}
Expand All @@ -71,25 +74,29 @@ class LoginViewController: UITableViewController {
var clientId = ""
switch environment {
case .development:
secret = Bundle.main.object(forInfoDictionaryKey: "butterflymxSecret") as? String ?? "N/a"
clientId = Bundle.main.object(forInfoDictionaryKey: "butterflymxClientId") as? String ?? "N/a"
secret = Bundle.main.object(forInfoDictionaryKey: "butterflymxSecretTest") as? String ?? "N/a"
clientId = Bundle.main.object(forInfoDictionaryKey: "butterflymxClientIdTest") as? String ?? "N/a"
case .sandbox:
secret = Bundle.main.object(forInfoDictionaryKey: "butterflymxSecretSandbox") as? String ?? "N/a"
clientId = Bundle.main.object(forInfoDictionaryKey: "butterflymxClientIdSandbox") as? String ?? "N/a"
case .production:
secret = Bundle.main.object(forInfoDictionaryKey: "butterflymxSecretProd") as? String ?? "N/a"
clientId = Bundle.main.object(forInfoDictionaryKey: "butterflymxClientIdProd") as? String ?? "N/a"
@unknown default:
fatalError()
}
return BMXAuthProvider(secret: secret, clientID: clientId)
}
}

extension LoginViewController: BMXCoreDelegate {
func didUpdate(accessToken: String, refreshToken: String) {
print(accessToken, refreshToken)
}

extension LoginViewController: BMXCoreDelegate {
func logging(_ data: String) {
print("BMXSDK Log: \(data)")
}
}

extension LoginViewController: SFSafariViewControllerDelegate {
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
SVProgressHUD.dismiss()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ class UnitTableViewCell: UITableViewCell {
return
}

let webhookBaseUrl = "https://a98fb4c79b25.ngrok.io/webhook/"
let webhookUrl = "\(webhookBaseUrl)?token=\(deviceToken)&platform=ios&type=voip"

let ngrokId = "6036eb46088a"
let webhookUrl = "http:https://\(ngrokId).ngrok.io/webhook/?token=\(deviceToken)&type=voip"
SVProgressHUD.show()

BMXCoreKit.shared.registerWebhook(withTenantId: tenantModel.id, urlString: webhookUrl) { [weak self] result in
switch result {
case .success(let webhookId):
Expand Down
4 changes: 2 additions & 2 deletions ButterflyMX Demo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
</array>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>butterflymxClientId</key>
<key>butterflymxClientIdTest</key>
<string></string>
<key>butterflymxSecret</key>
<key>butterflymxSecretTest</key>
<string></string>
<key>butterflymxClientIdSandbox</key>
<string></string>
Expand Down

0 comments on commit f76d55b

Please sign in to comment.