Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HealthKit plugin #63

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ opts.Add(EnumVariable('arch', "Compilation Architecture", '', ['', 'arm64', 'arm
opts.Add(BoolVariable('simulator', "Compilation platform", 'no'))
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bin/'))
opts.Add(EnumVariable('plugin', 'Plugin to build', '', ['', 'apn', 'arkit', 'camera', 'icloud', 'gamecenter', 'inappstore', 'photo_picker']))
opts.Add(EnumVariable('plugin', 'Plugin to build', '', ['', 'apn', 'arkit', 'camera', 'icloud', 'gamecenter', 'inappstore', 'photo_picker', 'healthkit']))
opts.Add(EnumVariable('version', 'Godot version to target', '', ['', '3.x', '4.0']))

# Updates the environment with the option variables.
Expand Down
44 changes: 44 additions & 0 deletions plugins/healthkit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Godot iOS HealthKit plugin

## Enum

Type: `AuthorizationStatus`
Values: `AUTHORIZATION_STATUS_NOT_DETERMINED`, `AUTHORIZATION_STATUS_DENIED`, `AUTHORIZATION_STATUS_AUTHORIZED`

Type: `ObjectType`
Values: `OBJECT_TYPE_UNKNOWN`, `OBJECT_TYPE_QUANTITY_TYPE_STEP_COUNT`, `OBJECT_TYPE_QUANTITY_TYPE_ACTIVE_ENERY_BURNED`

Type: `QuantityType`
Values: `QUANTITY_TYPE_UNKNOWN`, `QUANTITY_TYPE_STEP_COUNT`, `QUANTITY_TYPE_ACTIVE_ENERY_BURNED`

## Methods

`bool is_health_data_available()`

- Check if HealthKit is available on device.

`Error request_authorization(Vector<int> to_share, Vector<int> to_read)`

- Requests authorization to share and read the given object types.

`SharingAuthorizationStatus authorization_status_for_type(ObjectType object_type)`

- Used to determine if the user is permitted to share the given object type. Should be called before actually sharing.

`Error execute_statistics_query(QuantityType quantity_type, int start_date, int end_date)`

- Starts a query to query health data of the given quantity type.

## Signals

`authorization_complete(int object_type, int status)`

- Called when the authorization has completed.

`statistics_query_completed(int quantity_type, float value)`

- Called when the statistics query has completed for the given quantity type.

`statistics_query_failed(int quantity_type, int error_code)`

- Called when the statistics query has failed for the given quantity type.
17 changes: 17 additions & 0 deletions plugins/healthkit/healthkit.gdip
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[config]
name="HealthKit"
binary="healthkit.xcframework"

initialization="register_healthkit_types"
deinitialization="unregister_healthkit_types"

[dependencies]
linked=[]
embedded=[]
system=[]

capabilities=[]

files=[]

[plist]
93 changes: 93 additions & 0 deletions plugins/healthkit/healthkit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*************************************************************************/
/* healthkit.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/

#ifndef HEALTHKIT_H
#define HEALTHKIT_H

#include "core/version.h"

#if VERSION_MAJOR == 4
#include "core/object/class_db.h"
#include "core/templates/vector.h"
#else
#include "core/object.h"
#include "core/vector.h"
#endif

class HealthKit : public Object {
GDCLASS(HealthKit, Object);

static HealthKit *_instance;

static void _bind_methods();

public:

enum AuthorizationStatus {
AUTHORIZATION_STATUS_NOT_DETERMINED,
AUTHORIZATION_STATUS_DENIED,
AUTHORIZATION_STATUS_AUTHORIZED,
};

enum SharingAuthorizationStatus {
SHARING_AUTHORIZATION_STATUS_NOT_DETERMINED,
SHARING_AUTHORIZATION_STATUS_DENIED,
SHARING_AUTHORIZATION_STATUS_AUTHORIZED,
};

enum ObjectType {
OBJECT_TYPE_UNKNOWN,
OBJECT_TYPE_QUANTITY_TYPE_STEP_COUNT,
OBJECT_TYPE_QUANTITY_TYPE_ACTIVE_ENERGY_BURNED,
};

enum QuantityType {
QUANTITY_TYPE_UNKNOWN,
QUANTITY_TYPE_STEP_COUNT,
QUANTITY_TYPE_ACTIVE_ENERGY_BURNED,
};

static HealthKit *get_singleton();

bool is_health_data_available() const;
Error request_authorization(Vector<int> to_share, Vector<int> to_read);
SharingAuthorizationStatus authorization_status_for_type(ObjectType object_type);
Error execute_statistics_query(QuantityType quantity_type, int start_date, int end_date);

HealthKit();
~HealthKit();
};

VARIANT_ENUM_CAST(HealthKit::AuthorizationStatus);
VARIANT_ENUM_CAST(HealthKit::SharingAuthorizationStatus);
VARIANT_ENUM_CAST(HealthKit::ObjectType);
VARIANT_ENUM_CAST(HealthKit::QuantityType);

#endif
Loading
Loading