creepymonster / libre-direct-client-swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build

This guide will help you integrating JohanDegraeve's xdripswift (https://github.com/JohanDegraeve/xdripswift) into Loop.

Here are the steps we're going to take:

  • Update Cartfile dependencies
  • Carthage update
  • Add xDrip as a CGM source to Loop in Xcode
  • Add the xDrip frameworks
  • Link binaries
  • Build and launch
  • Troubleshoot

Update Cartfile dependencies

Loop and almost all its elements are constituted of many different projects. These projects lay down the proper foundation for Loop to build successfully. For example, the project LoopKit is fundamental in Loop's inner-workings. Elements such as RileyLink, the Dexcom share client, and the xDrip client rely upon it, depend upon it, in order to function properly. These dependencies are declared in what's called the Cartfile. Here we tell Carthage, the dependency manager, where to go on GitHub to find these constituting elements of Loop. Carthage then fetches that information from GitHub, clones it onto your computer, and then builds it. The result of this is also logged into the Cartfile.resolved. Those very long numbers you see at the end of each declared dependency are what we call a SHA-1. It's like a fingerprint - each one is unique, and is attributed to the version of the dependency you told Carthage to go get. This can help us make sure that we've gone and gotten the right version when we want to be vigilant, but don't worry about that for now.

Because we want Loop to also depend upon the xDrip client, we have to edit the Cartfile and tell Carthage where to go get it so it can import the xDrip client. NOTE: To continue this guide I assume you have a recent version of Loop, which is up and running! If you open Loop's Cartfile, you'll notice it has multiple dependencies but is missing the xDrip client. So we want to tell Loop to use the xDrip client. We can tell Loop to use the client by adding this line of text at the end of the Cartfile: gitHub "julian-groen/xdrip-client-swift" "master". Copy that into Loop's Cartfile, then save and exit. Do the same for the Cartfile.resolved.

Note that you may have to right click on the Cartfile or the Cartfile.resolved in order to open it with TextEdit. TextEdit is usually the default editor for the Cartfile, but often the default editor for the Cartfile.resolved is Xcode. Try and be consistent with the editor you use when appending the Cartfiles.

Carthage update

Time to tell Carthage to do its thing. In Terminal, type :

cd ~/LOCATION_OF_LOOP_FOLDER && carthage update

If you get any errors, type rm -rf ~/Library/Caches/org.carthage.CarthageKit and then rm -rf ~/Library/Developer/Xcode/DerivedData. Terminal should not tell you anything after you type these out. If you still get an error, Carthage should tell you what went wrong, but often much too vaguely to do anything about it. At the end of its message, it'll tell you that you can "check the log" at /var/folders/.... Highlight this with your curser and copy it with command+c, then type open, paste the file path with command+v, and hit enter. You'll get a detailed log as to what's happening and where to fix it.

Add xDrip as a CGM source to Loop in Xcode

Open up your Loop folder and open the Loop project. In the project manager pane on the lefthand side of your screen, navigate into Loop > Managers > CGMManager.swift.

At the top of the file, you'll see a bunch of frameworks being imported via the declaration import LoopKit, or import ShareClient. We also want to import something : the xDrip client. Click at the end of the last framework being imported, hit enter, and type import LibreDirectClient.

A little further down you'll notice the constant allCGMManagers being declared, with the required syntax being CGMManager.Type. Add xDrip to the list by typing : LibreDirectClientManager.self.

Add the xDrip frameworks

Time to use the xDrip frameworks that Carthage went and got for us.

At the top of the project manager pane you'll see "Loop" with the app icon symbol next to it, under TARGETS. Click on that. Along the top of the screen, right under the name of the project, you'll see a range of tabs listed horizontally, such as "General", "Capabilities", "Resource tags"... Find "Build Phases" and click on it. You'll see a list of options appear. Near the bottom you'll see "Copy Frameworks with Carthage". Click on that.

Under "Input Files", you'll see a bunch of things that start with $(BUILT_PRODUCTS_DIR). All of those files are the frameworks that we asked Carthage to get. We're going to add the xDrip client and its UI onto the list, so that Loop can access the files while it's building and running.

Click on the + and type :

$(BUILT_PRODUCTS_DIR)/LibreDirectClient.framework/LibreDirectClient
$(BUILT_PRODUCTS_DIR)/LibreDirectClientUI.framework/LibreDirectClientUI

Now do the same under "Output Files", click on the + and type :

$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/LibreDirectClient.framework
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/LibreDirectClientUI.framework

Link binaries

We've added a reference into the CGM manager, added a reference to the frameworks, now all we have left is to link the files themselves into Loop.

Under that same "Build Phases" tab you'll also see "Link Binary With Libraries". Click on that, and scroll down to the + button. You'll be asked to select the files. We're looking for that same LibreDirectClient.framework and LibreDirectClientUI.framework we just referenced in the last step.

Click Add other... and navigate into your Loop folder. Go into Carthage > Build > iOS and scroll all the way down until you find the LibreDirectClient.framework and the LibreDirectClientUI.framework. Select the .framework, not the .framework.dSYM. We want the one whose icon kind of looks like a Lego.

Build and launch

Yes, finally build and launch! Assign all your targets, select your phone in the active scheme, make sure your screen is left on, and hit play.

Troubleshoot

Loop not getting xDrip data? Try some of these fixes.

  • Make sure Loop and xDrip are using the same App Group it should be something like this : group.com.YOUR_TEAM_ID.loopkit.LoopGroup
  • Make sure xDrip is calibrated and is recieving bloodsugar readings.
  • Make sure both Loop and xDrip are still running in the background else they won't be able to process data

I am aware most of these fixes require a technical background. So, if you are still not able to fix this issue, feel free to contact me.

About

License:MIT License


Languages

Language:Swift 96.5%Language:Objective-C 3.5%