Skip to content

Commit

Permalink
Update CALL SDK to 1.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
4taras4 committed Sep 3, 2020
2 parents 3d18f22 + e0e7829 commit c0251db
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 53 deletions.
16 changes: 6 additions & 10 deletions ButterflyMX Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
1A1C1316219ADC82003449F8 /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A1C1315219ADC82003449F8 /* Extension.swift */; };
1A1C1318219ADCEE003449F8 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A1C1317219ADCEE003449F8 /* LoginViewController.swift */; };
1A1E860A2254B9FB00189782 /* BMXCall.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A1E86092254B9FB00189782 /* BMXCall.framework */; };
1A1E860B2254B9FB00189782 /* BMXCall.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1A1E86092254B9FB00189782 /* BMXCall.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1A1E860D2254B9FB00189782 /* BMXCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A1E860C2254B9FB00189782 /* BMXCore.framework */; };
1A1E860E2254B9FB00189782 /* BMXCore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 1A1E860C2254B9FB00189782 /* BMXCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1A2CD59121F6310900515F51 /* AccountTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2CD59021F6310900515F51 /* AccountTableViewController.swift */; };
1A59B850234B514200E1E536 /* CallKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A59B84F234B514200E1E536 /* CallKit.framework */; };
1A59B851234B529300E1E536 /* CallKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A59B84F234B514200E1E536 /* CallKit.framework */; };
Expand Down Expand Up @@ -60,8 +58,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
1A1E860B2254B9FB00189782 /* BMXCall.framework in Embed Frameworks */,
1A1E860E2254B9FB00189782 /* BMXCore.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -537,8 +533,8 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "ButterflyMX Demo/ButterflyMX Demo.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = 72UNXQ9M6U;
ENABLE_BITCODE = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
Expand Down Expand Up @@ -571,7 +567,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "com.butterflymx.sdk.demo-internal";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
PROVISIONING_PROFILE_SPECIFIER = "Demo Internal AdHoc";
SWIFT_INCLUDE_PATHS = "$(inherited) $(PROJECT_DIR)/../../BMXCall/Dependencies/pjsip/include";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -666,8 +662,8 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "ButterflyMX Demo/ButterflyMX Demo.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = 72UNXQ9M6U;
ENABLE_BITCODE = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
Expand Down Expand Up @@ -700,7 +696,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "com.butterflymx.sdk.demo-internal";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
PROVISIONING_PROFILE_SPECIFIER = "Demo Internal AdHoc";
SWIFT_INCLUDE_PATHS = "$(inherited) $(PROJECT_DIR)/../../BMXCall/Dependencies/pjsip/include";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
18 changes: 13 additions & 5 deletions ButterflyMX Demo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let stb = UIStoryboard(name: "Main", bundle: nil)
if BMXCore.shared.isUserLoggedIn {
var env = BMXEnvironment(backendEnvironment: .development)
switch UserDefaults.standard.string(forKey: "environment") {
case "sandbox":
env = BMXEnvironment(backendEnvironment: .sandbox)
case "production":
env = BMXEnvironment(backendEnvironment: .production)
default:
break
}
BMXCore.shared.configure(withEnvironment: env)
let mainViewController = stb.instantiateViewController(withIdentifier: "MainTabController")
window!.rootViewController = mainViewController
} else {
let loginViewController = stb.instantiateViewController(withIdentifier: "LoginViewController")
window!.rootViewController = loginViewController
}
let env = BMXEnvironment(backendEnvironment: .development)
BMXCore.shared.configure(withEnvironment: env)

BMXCore.shared.delegate = self

CallsService.shared.setupVoipPush()
Expand Down Expand Up @@ -75,11 +84,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

extension AppDelegate: BMXCoreDelegate {

func didUpdate(accessToken: String, refreshToken: String) {
// handle update
print(accessToken, refreshToken)
}

func logging(_ data: String) {
print("BMXSDK Log: \(data)")
}
Expand Down
20 changes: 15 additions & 5 deletions ButterflyMX Demo/Controllers/AccountTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,21 @@ class AccountTableViewController: UITableViewController {
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 1 && indexPath.row == 0 {
SVProgressHUD.show()
BMXCore.shared.logoutUser()
let stb = UIStoryboard(name: "Main", bundle: nil)
let loginViewController = stb.instantiateViewController(withIdentifier: "LoginViewController")
SVProgressHUD.dismiss()
self.present(loginViewController, animated: true, completion: nil)
BMXCore.shared.logoutUser(completion: { result in
switch result {
case .success:
let stb = UIStoryboard(name: "Main", bundle: nil)
let loginViewController = stb.instantiateViewController(withIdentifier: "LoginViewController")
SVProgressHUD.dismiss()
loginViewController.modalPresentationStyle = .fullScreen
self.present(loginViewController, animated: true, completion: nil)
case .failure(let error):
print(error)
SVProgressHUD.dismiss()
self.alert(message: error.localizedDescription)
}
})

}
}

Expand Down
88 changes: 67 additions & 21 deletions ButterflyMX Demo/Controllers/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,88 @@ import SVProgressHUD
class LoginViewController: UITableViewController {

@IBOutlet weak var singInButton: UIButton!

@IBOutlet weak var environmentSegmentControll: UISegmentedControl!
private var environmentType: BMXBackendEnvironment = .development
private var authProvider: BMXAuthProvider!

@IBAction func environmentAction(_ sender: Any) {
switch environmentSegmentControll.selectedSegmentIndex {
case 0:
UserDefaults.standard.set("development", forKey: "environment")
environmentType = .development
case 1:
UserDefaults.standard.set("sandbox", forKey: "environment")
environmentType = .sandbox
case 2:
UserDefaults.standard.set("production", forKey: "environment")
environmentType = .production
default:
fatalError("No environment")
}
authProvider = getBMXAuthProvider(for: environmentType)
}

@IBAction func singInAction(_ sender: Any) {
SVProgressHUD.show()
let auth = BMXAuthProvider(secret: Bundle.main.object(forInfoDictionaryKey: "butterflymx-SECRET") as? String ?? "N/a",
clientID: Bundle.main.object(forInfoDictionaryKey: "butterflymx-CLIENTID") as? String ?? "N/a")
BMXCore.shared.authorize(withAuthProvider: auth, callbackURL: URL(string: "demoapp:https://test")!, viewController: self) { result in
switch result {
case .success:
let stb = UIStoryboard(name: "Main", bundle: nil)
let mainViewController = stb.instantiateViewController(withIdentifier: "MainTabController")
mainViewController.modalPresentationStyle = .overFullScreen
SVProgressHUD.dismiss()
self.present(mainViewController, animated: true, completion: {
guard let pushToken = CallsService.shared.pushkitToken else { return }
BMXCore.shared.registerPushKitToken(pushToken, apnsSandbox: true)
})
case .error(let error):
print(error)
SVProgressHUD.showError(withStatus: error.localizedDescription)
}
let env = BMXEnvironment(backendEnvironment: environmentType)
BMXCore.shared.configure(withEnvironment: env)
BMXCore.shared.authorize(withAuthProvider: authProvider, callbackURL: URL(string: "demoapp:https://test")!, viewController: self) { result in
switch result {
case .success:
let stb = UIStoryboard(name: "Main", bundle: nil)
let mainViewController = stb.instantiateViewController(withIdentifier: "MainTabController")
mainViewController.modalPresentationStyle = .overFullScreen
SVProgressHUD.dismiss()
self.present(mainViewController, animated: true, completion: {
guard let pushToken = CallsService.shared.pushkitToken else { return }
let token = pushToken.map { String(format: "%02.2hhx", $0) }.joined()
BMXCore.shared.registerDevice(with: .voip(token: token), apnsSandbox: false) { result in
switch result {
case .success:
print("Success")
case .failure(let error):
print(error.localizedDescription)
}
}
})
case .failure(let error):
print(error)
SVProgressHUD.showError(withStatus: error.localizedDescription)
}
}
}

override func viewDidLoad() {
super.viewDidLoad()
UserDefaults.standard.set("development", forKey: "environment")
BMXCore.shared.delegate = self
authProvider = getBMXAuthProvider(for: environmentType)
SVProgressHUD.setDefaultStyle(.light)
}

private func getBMXAuthProvider(for environment: BMXBackendEnvironment) -> BMXAuthProvider {
var secret = ""
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"
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"
}
return BMXAuthProvider(secret: secret, clientID: clientId)
}
}

extension LoginViewController: BMXCoreDelegate {

func didUpdate(accessToken: String, refreshToken: String) {
// handle update
print(accessToken, refreshToken)
}

func logging(_ data: String) {
print("BMXSDK Log: \(data)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ extension DoorsTableViewController {
let cell = tableView.cellForRow(at: indexPath) as! DoorTableViewCell
cell.isUserInteractionEnabled = false
cell.pleaseWait()
BMXDoor.shared.openDoor(panel: panel[indexPath.row], tenant: tenant, completion: { data in
switch data {
BMXDoor.shared.openDoor(panel: panel[indexPath.row], tenant: tenant, completion: { result in
switch result {
case .success():
cell.completeWith("Success!", color: Colors.lightGreen)
tableView.deselectRow(at: indexPath, animated: true)
case .error(let error):
case .failure(let error):
cell.completeWith("Error", color: Colors.lightGray)
tableView.deselectRow(at: indexPath, animated: true)
print("Error: \(error)")
Expand Down
12 changes: 10 additions & 2 deletions ButterflyMX Demo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,17 @@
</array>
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>butterflymx-CLIENTID</key>
<key>butterflymxClientId</key>
<string></string>
<key>butterflymx-SECRET</key>
<key>butterflymxSecret</key>
<string></string>
<key>butterflymxClientIdSandbox</key>
<string></string>
<key>butterflymxSecretSandbox</key>
<string></string>
<key>butterflymxClientIdProd</key>
<string></string>
<key>butterflymxSecretProd</key>
<string></string>
</dict>
</plist>
15 changes: 12 additions & 3 deletions ButterflyMX Demo/Logic/CallsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,17 @@ extension CallsService: PKPushRegistryDelegate, CXProviderDelegate {
}

func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
pushkitToken = pushCredentials.token
if BMXCore.shared.isUserLoggedIn {
pushkitToken = pushCredentials.token
BMXCore.shared.registerPushKitToken(pushCredentials.token, apnsSandbox: true)
let token = pushCredentials.token.map { String(format: "%02.2hhx", $0) }.joined()
BMXCore.shared.registerDevice(with: .voip(token: token), apnsSandbox: false) { result in
switch result {
case .success(let data):
print(data)
case .failure(let error):
print(error.localizedDescription)
}
}
}
}

Expand Down Expand Up @@ -138,7 +146,8 @@ extension CallsService: PKPushRegistryDelegate, CXProviderDelegate {
topViewController.present(vc, animated: true)
}
}
case .error(_):
case .failure(let error):
print(error.localizedDescription)
self.reportFailedCall(reason: .failed)
}

Expand Down
22 changes: 18 additions & 4 deletions ButterflyMX Demo/Resources/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="bMj-ld-ss8">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="bMj-ld-ss8">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<capability name="Stack View standard spacing" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -98,7 +98,7 @@
</constraints>
</view>
<view key="tableFooterView" contentMode="scaleToFill" id="k8b-sc-GSJ">
<rect key="frame" x="0.0" y="210" width="375" height="137"/>
<rect key="frame" x="0.0" y="210" width="375" height="281"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="vch-CJ-T3z">
Expand All @@ -121,11 +121,24 @@
<action selector="singInAction:" destination="Y2U-sj-rV7" eventType="touchUpInside" id="kNh-ty-ZX3"/>
</connections>
</button>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="2YN-rW-7CQ">
<rect key="frame" x="57.5" y="230" width="260" height="32"/>
<segments>
<segment title="Test"/>
<segment title="Sandbox"/>
<segment title="Production"/>
</segments>
<connections>
<action selector="environmentAction:" destination="Y2U-sj-rV7" eventType="valueChanged" id="yPx-PQ-RcB"/>
</connections>
</segmentedControl>
</subviews>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="vch-CJ-T3z" secondAttribute="trailing" constant="15" id="FAK-0v-GXv"/>
<constraint firstItem="vch-CJ-T3z" firstAttribute="leading" secondItem="k8b-sc-GSJ" secondAttribute="leading" constant="15" id="UY2-D1-93i"/>
<constraint firstAttribute="bottom" secondItem="2YN-rW-7CQ" secondAttribute="bottom" constant="20" id="bBC-OF-A7s"/>
<constraint firstItem="2YN-rW-7CQ" firstAttribute="centerX" secondItem="k8b-sc-GSJ" secondAttribute="centerX" id="fHr-Sw-b73"/>
<constraint firstItem="vch-CJ-T3z" firstAttribute="top" secondItem="k8b-sc-GSJ" secondAttribute="top" constant="20" id="pxV-A5-eYv"/>
</constraints>
</view>
Expand All @@ -140,12 +153,13 @@
</connections>
</tableView>
<connections>
<outlet property="environmentSegmentControll" destination="2YN-rW-7CQ" id="zzB-CK-R1I"/>
<outlet property="singInButton" destination="vch-CJ-T3z" id="xQE-4v-4bT"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="6xH-YB-987" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1044" y="-648"/>
<point key="canvasLocation" x="1044" y="-648.12593703148434"/>
</scene>
<!--Table View Controller-->
<scene sceneID="JVF-L9-IW5">
Expand Down

0 comments on commit c0251db

Please sign in to comment.