diff options
author | NicoleYarroch <nicole@livio.io> | 2020-05-13 10:17:22 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2020-05-13 10:17:22 -0400 |
commit | 89fb252858b50d6ed18c5eb66ab1b1de08f6fe05 (patch) | |
tree | 35e27f1f65884b9d5a5f96fa912806f3c3f2c13b /Example Apps/Example Swift | |
parent | dc8f3b11bcdc118db6be6ed79fa48b18d5b5bec1 (diff) | |
download | sdl_ios-89fb252858b50d6ed18c5eb66ab1b1de08f6fe05.tar.gz |
Updated `isDialNumberSupported` example
Diffstat (limited to 'Example Apps/Example Swift')
-rw-r--r-- | Example Apps/Example Swift/ProxyManager.swift | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Example Apps/Example Swift/ProxyManager.swift b/Example Apps/Example Swift/ProxyManager.swift index 4238251bf..e748043ba 100644 --- a/Example Apps/Example Swift/ProxyManager.swift +++ b/Example Apps/Example Swift/ProxyManager.swift @@ -301,3 +301,33 @@ private extension ProxyManager { return sdlManager.systemCapabilityManager.defaultMainWindowCapability?.imageFields?.first { $0.name == imageFieldName } != nil ? true : false } } + +extension ProxyManager { +func isDialNumberSupported(handler: @escaping (_ success: Bool, _ error: Error?) -> Void) { + // Check if the module has phone capabilities + guard (sdlManager.systemCapabilityManager.isCapabilitySupported(type: .phoneCall)) else { + return handler(false, nil) + } + + // Legacy modules (pre-RPC Spec v4.5) do not support checking capabilities, so for versions less than 4.5 we will assume `DialNumber` is supported + guard let sdlMsgVersion = sdlManager.registerResponse?.sdlMsgVersion, SDLVersion(sdlMsgVersion: sdlMsgVersion).isGreaterThanOrEqual(to: SDLVersion(major: 4, minor: 5, patch: 0)) else { + return handler(true, nil) + } + + // Check if the phone capability has already been retreived from the module + if let phoneCapability = sdlManager.systemCapabilityManager.phoneCapability { + // Check if the module supports the `DialNumber` request + return handler(phoneCapability.dialNumberEnabled?.boolValue ?? false, nil) + } + + // Retreive the phone capability from the module + sdlManager.systemCapabilityManager.updateCapabilityType(.phoneCall) { (error, systemCapabilityManager) in + if (error != nil) { + return handler(false, error) + } + + // Check if the module supports the `DialNumber` request + return handler(systemCapabilityManager.phoneCapability?.dialNumberEnabled?.boolValue ?? false, nil) + } +} +} |