Skip to content

Commit

Permalink
refactor to configureParse
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 committed May 1, 2023
1 parent 7d16328 commit 566f68e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ A sample app, [CareKitSample-ParseCareKit](https://github.com/netreconlab/CareKi
<img src="https://user-images.githubusercontent.com/8621344/99022137-1ec7ca80-2530-11eb-897c-ace7c70536f2.png" width="300"> <img src="https://user-images.githubusercontent.com/8621344/99022190-3bfc9900-2530-11eb-8ad1-c1e8ba2e7f55.png" width="300">

### ParseCareKit.plist with server connection information
ParseCareKit comes with a helper method, [PCKUtility.setupServer()](https://github.com/netreconlab/ParseCareKit/blob/4912bf7677511d148b52d03146c31cc428a83454/ParseCareKit/PCKUtility.swift#L14) that easily helps apps connect to your parse-server. To leverage the helper method, copy the [ParseCareKit.plist](https://github.com/netreconlab/CareKitSample-ParseCareKit/blob/main/OCKSample/Supporting%20Files/ParseCareKit.plist) file your "Supporting Files" folder in your Xcode project. Be sure to change `ApplicationID` and `Server` to the correct values for your server. Simply add the following inside `didFinishLaunchingWithOptions` in `AppDelegate.swift`:
ParseCareKit comes with a helper method, [PCKUtility.configureParse()](https://github.com/netreconlab/ParseCareKit/blob/4912bf7677511d148b52d03146c31cc428a83454/ParseCareKit/PCKUtility.swift#L14) that easily helps apps connect to your parse-server. To leverage the helper method, copy the [ParseCareKit.plist](https://github.com/netreconlab/CareKitSample-ParseCareKit/blob/main/OCKSample/Supporting%20Files/ParseCareKit.plist) file your "Supporting Files" folder in your Xcode project. Be sure to change `ApplicationID` and `Server` to the correct values for your server. Simply add the following inside `didFinishLaunchingWithOptions` in `AppDelegate.swift`:

```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

//Pulls from ParseCareKit.plist to connect to server
PCKUtility.setupServer()
PCKUtility.configureParse()

//If you need certificate pinning:
PCKUtility.setupServer { (challenge, completionHandler) in
PCKUtility.configureParse { (challenge, completionHandler) in
//Return how you want to handle the challenge. See docs for more information.
completionHandler(.performDefaultHandling, nil)
}
Expand Down
18 changes: 9 additions & 9 deletions Sources/ParseCareKit/PCKUtility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PCKUtility {
var propertyListFormat = PropertyListSerialization.PropertyListFormat.xml
guard let path = Bundle.main.path(forResource: fileName, ofType: "plist"),
let xml = FileManager.default.contents(atPath: path) else {
fatalError("Error in ParseCareKit.setupServer(). Cannot find ParseCareKit.plist in this project")
fatalError("Error in ParseCareKit.configureParse(). Cannot find ParseCareKit.plist in this project")
}

return try PropertyListSerialization.propertyList(from: xml,
Expand All @@ -29,7 +29,7 @@ public class PCKUtility {
}

/**
Setup a connection to Parse Server based on a ParseCareKit.plist file.
Configure the client to connect to a Parse Server based on a ParseCareKit.plist file.
The key/values supported in the file are a dictionary named `ParseClientConfiguration`:
- Server - (String) The server URL to connect to Parse Server.
Expand All @@ -45,10 +45,10 @@ public class PCKUtility {
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
*/
public class func setupServer(fileName: String = "ParseCareKit",
authentication: ((URLAuthenticationChallenge,
(URLSession.AuthChallengeDisposition,
URLCredential?) -> Void) -> Void)? = nil) async throws {
public class func configureParse(fileName: String = "ParseCareKit",
authentication: ((URLAuthenticationChallenge,
(URLSession.AuthChallengeDisposition,
URLCredential?) -> Void) -> Void)? = nil) async throws {
var plistConfiguration: [String: AnyObject]
var clientKey: String?
var liveQueryURL: URL?
Expand All @@ -57,13 +57,13 @@ public class PCKUtility {
do {
plistConfiguration = try Self.getPlistConfiguration(fileName: fileName)
} catch {
fatalError("Error in ParseCareKit.setupServer(). Could not serialize plist. \(error)")
fatalError("Error in ParseCareKit.configureParse(). Could not serialize plist. \(error)")
}

guard let appID = plistConfiguration["ApplicationID"] as? String,
let server = plistConfiguration["Server"] as? String,
let serverURL = URL(string: server) else {
fatalError("Error in ParseCareKit.setupServer(). Missing keys in \(plistConfiguration)")
fatalError("Error in ParseCareKit.configureParse(). Missing keys in \(plistConfiguration)")
}

if let client = plistConfiguration["ClientKey"] as? String {
Expand Down Expand Up @@ -109,7 +109,7 @@ public class PCKUtility {
do {
plistConfiguration = try Self.getPlistConfiguration(fileName: fileName)
} catch {
fatalError("Error in ParseCareKit.setupServer(). Could not serialize plist. \(error)")
fatalError("Error in ParseCareKit.configureParse(). Could not serialize plist. \(error)")
}

if let keychainAccessGroup = plistConfiguration["AccessGroup"] as? String {
Expand Down
4 changes: 2 additions & 2 deletions Tests/ParseCareKitTests/UtilityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class UtilityTests: XCTestCase {
PCKUtility.removeCache()
}

func testSetupServer() async throws {
try await PCKUtility.setupServer { (_, completionHandler) in
func testConfigureParse() async throws {
try await PCKUtility.configureParse { (_, completionHandler) in
completionHandler(.performDefaultHandling, nil)
}
XCTAssertEqual(ParseSwift.configuration.applicationId, "3B5FD9DA-C278-4582-90DC-101C08E7FC98")
Expand Down

0 comments on commit 566f68e

Please sign in to comment.