Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.3'
use_frameworks!

target 'xDripG5_Example' do
Expand Down
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: ../

SPEC CHECKSUMS:
xDripG5: 8779a4f495fd8eb81a3d75457afe9b95fb52f61d
xDripG5: 95e385a36ebcf3f42e44dae73fb6490dc5b79904

PODFILE CHECKSUM: 6b30cba971694d5258509315fb52eb645c9bc5e3
PODFILE CHECKSUM: c62f3fcb344335d79abdcccea268615000e8801b

COCOAPODS: 1.1.0.rc.2
COCOAPODS: 1.3.1
14 changes: 11 additions & 3 deletions Example/xDripG5.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,16 @@
files = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-xDripG5_Example-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
2FC4228A9369221D367ED688 /* [CP] Copy Pods Resources */ = {
Expand All @@ -232,9 +235,12 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-xDripG5_Example/Pods-xDripG5_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/xDripG5/xDripG5.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/xDripG5.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -381,8 +387,9 @@
isa = XCBuildConfiguration;
baseConfigurationReference = F3147B948B4F90A741304461 /* Pods-xDripG5_Example.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = xDripG5/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
Expand All @@ -397,8 +404,9 @@
isa = XCBuildConfiguration;
baseConfigurationReference = CFBD776BFE02F42998A8820B /* Pods-xDripG5_Example.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = xDripG5/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
Expand Down
14 changes: 7 additions & 7 deletions Example/xDripG5/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

transmitter = Transmitter(
ID: UserDefaults.standard.transmitterID,
id: UserDefaults.standard.transmitterID,
passiveModeEnabled: UserDefaults.standard.passiveModeEnabled
)
transmitter?.stayConnected = UserDefaults.standard.stayConnected
Expand Down Expand Up @@ -73,24 +73,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate, TransmitterDelegate {
}()

func transmitter(_ transmitter: Transmitter, didError error: Error) {
if let vc = window?.rootViewController as? TransmitterDelegate {
DispatchQueue.main.async {
DispatchQueue.main.async {
if let vc = self.window?.rootViewController as? TransmitterDelegate {
vc.transmitter(transmitter, didError: error)
}
}
}

func transmitter(_ transmitter: Transmitter, didRead glucose: Glucose) {
if let vc = window?.rootViewController as? TransmitterDelegate {
DispatchQueue.main.async {
DispatchQueue.main.async {
if let vc = self.window?.rootViewController as? TransmitterDelegate {
vc.transmitter(transmitter, didRead: glucose)
}
}
}

func transmitter(_ transmitter: Transmitter, didReadUnknownData data: Data) {
if let vc = window?.rootViewController as? TransmitterDelegate {
DispatchQueue.main.async {
DispatchQueue.main.async {
if let vc = self.window?.rootViewController as? TransmitterDelegate {
vc.transmitter(transmitter, didReadUnknownData: data)
}
}
Expand Down
10 changes: 5 additions & 5 deletions Example/xDripG5/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class ViewController: UIViewController, TransmitterDelegate, UITextFieldDelegate
if let text = textField.text {
let newString = text.replacingCharacters(in: range.rangeOfString(text), with: string)

if newString.characters.count > 6 {
if newString.count > 6 {
return false
} else if newString.characters.count == 6 {
} else if newString.count == 6 {
AppDelegate.sharedDelegate.transmitter?.ID = newString
UserDefaults.standard.transmitterID = newString

Expand All @@ -86,7 +86,7 @@ class ViewController: UIViewController, TransmitterDelegate, UITextFieldDelegate
}

func textFieldDidEndEditing(_ textField: UITextField) {
if textField.text?.characters.count != 6 {
if textField.text?.count != 6 {
textField.text = UserDefaults.standard.transmitterID
}
}
Expand Down Expand Up @@ -129,8 +129,8 @@ class ViewController: UIViewController, TransmitterDelegate, UITextFieldDelegate

private extension NSRange {
func rangeOfString(_ string: String) -> Range<String.Index> {
let startIndex = string.characters.index(string.startIndex, offsetBy: location)
let endIndex = string.characters.index(startIndex, offsetBy: length)
let startIndex = string.index(string.startIndex, offsetBy: location)
let endIndex = string.index(startIndex, offsetBy: length)
return startIndex..<endIndex
}
}
Expand Down
2 changes: 1 addition & 1 deletion xDripG5.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Please note this project is neither created nor backed by Dexcom, Inc. Use of th
s.author = { "Nathan Racklyeft" => "loudnate@gmail.com" }
s.source = { :git => "https://github.com/LoopKit/xDripG5.git", :tag => s.version.to_s }

s.platform = :ios, '9.3'
s.platform = :ios, '10.3'
s.requires_arc = true

s.source_files = ['xDripG5/**/*.swift', 'xDripG5/AESCrypt.{h,m}', 'Pod/*.h']
Expand Down
7 changes: 6 additions & 1 deletion xDripG5/Transmitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public final class Transmitter: BluetoothManagerDelegate {

/// The ID of the transmitter to connect to
public var ID: String {
return id.id
get {
return id.id
}
set(newID) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a public setter to Transmitter.id isn’t the right solution, since additional state on Transmitter like activationDate need to be reset. I think it’s cleaner for clients to recreate Transmitter when the ID changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ps2, will do, much cleaner. I have changed the client code to recreate Transmitter; it just doesn't always start scanning reliably after a change to the transmitter ID. Once I've chased that down I'll push the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything I need to do in the client to tear down the old transmitter and replace it with a new one? When I try this, and change the ID in the client, the CBCentralManager state is sometimes .poweredOn, which is all good, but sometimes .unsupported, in which case we can't scan. Does the central manager need to be a singleton or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we store the transmitter state (activationDate and lastTimeMessage in the TransmitterID object, which gets renewed on a new ID). If we write the setter like this

        set(newID) {
            stopScanning()
            id = TransmitterID(id: newID)
            resumeScanning()
        }

then we scan afresh when the user changes ID.

I'd be happy to replace the entire Transmitter object, but can't find a clean way for the old Transmitter object to release all bluetooth resources in time for the new object to use them (if that makes sense).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do need to reset the bluetooth peripheral if we're changing the transmitter id.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #70; I've incorporated some of the things you've been pointing out there. I think this PR should just focus on getting the example app building. I.e. Removing cocoapods, and incorporating the example app into the project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks!

id = TransmitterID(id: newID)
}
}

private var id: TransmitterID
Expand Down