Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ios): add getConfig to CAPPlugin (#5495)
* feat(ios): add getConfig to CAPPlugin * rework to use class with helpers * Update project.pbxproj * Update ios/Capacitor/Capacitor/CAPPlugin.m Co-authored-by: jcesarmobile <jcesarmobile@gmail.com> * Update ios/Capacitor/Capacitor/CAPPlugin.h Co-authored-by: jcesarmobile <jcesarmobile@gmail.com> * adjust getArray and fmt Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
- Loading branch information
1 parent
1eaaa5f
commit 224a9d0
Showing
5 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import Foundation | ||
|
||
@objc public class PluginConfig: NSObject { | ||
|
||
// The object containing the plugin config values | ||
private var config: JSObject | ||
|
||
init(config: JSObject) { | ||
self.config = config | ||
} | ||
|
||
public func getString(configKey: String, defaultValue: String? = nil) -> String? { | ||
if let val = (self.config)[keyPath: KeyPath(configKey)] as? String { | ||
return val | ||
} | ||
return defaultValue | ||
} | ||
|
||
public func getBoolean(configKey: String, defaultValue: Bool) -> Bool { | ||
if let val = (self.config)[keyPath: KeyPath(configKey)] as? Bool { | ||
return val | ||
} | ||
return defaultValue | ||
} | ||
|
||
public func getInt(configKey: String, defaultValue: Int) -> Int { | ||
if let val = (self.config)[keyPath: KeyPath(configKey)] as? Int { | ||
return val | ||
} | ||
return defaultValue | ||
} | ||
|
||
public func getArray(configKey: String, defaultValue: JSArray? = nil) -> JSArray? { | ||
if let val = (self.config)[keyPath: KeyPath(configKey)] as? JSArray { | ||
return val | ||
} | ||
return defaultValue | ||
} | ||
|
||
public func getObject(configKey: String) -> JSObject? { | ||
return (self.config)[keyPath: KeyPath(configKey)] as? JSObject | ||
} | ||
|
||
public func isEmpty() -> Bool { | ||
return self.config.isEmpty | ||
} | ||
|
||
/** | ||
* Gets the JSObject containing the config of the the provided plugin ID. | ||
* | ||
* @return The config for that plugin | ||
*/ | ||
public func getConfigJSON() -> JSObject { | ||
return self.config | ||
} | ||
} |