Skip to content
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to this project will be documented in this file.

## 2021-02-05

## Added

- `badge_number` property, `set_badge_number`, `get_badge_number` methods to `PushNotifications` plugin.
- `GodotUserNotificationDelegate` and `UserNotificationService` can be used by as a single interface to process incoming notifications (both remote and local).

## 2021-02-03

## Added

- `PushNotifications` plugin that enables Apple Remote Notifications support for Godot projects.

## 2021-01-31

## Fixes
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Godot iOS plugins

`master` branch is current development branch and can introduce breaking changes to plugin's public interface.
`3.2` branch aim is to provide same public interface as it was before switch to new iOS plugin system.

## Instructions

Expand Down Expand Up @@ -31,7 +33,7 @@

* Running
```
scons target=<debug|release|release_debug> arch=<arch> simulator=<no|yes> plugin=<plugin_name> version=<3.2|4.0>
scons target=<debug|release|release_debug> arch=<arch> simulator=<no|yes> plugin=<plugin_name> version=<3.3|4.0>
```
will generate `.a` static library for chosen target.
Do note, that Godot's default `debug` export template is compiled with `release_debug` target.
Expand All @@ -46,4 +48,4 @@

* Run `./scripts/generate_xcframework.sh <plugin_name> <debug|release|release_debug> <godot_version>` to generate `xcframework` with specific configuration. `xcframework` allows plugin to support both `arm64` device and `arm64` simulator.

* The result `.xcframework` will be stored in `bin` folder as well as intermidiate `.a` binaries.
* The result `.xcframework` will be stored in `bin` folder as well as intermidiate `.a` binaries.
6 changes: 3 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ 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', '', ['', 'arkit', 'camera', 'icloud', 'gamecenter', 'inappstore']))
opts.Add(EnumVariable('version', 'Godot version to target', '', ['', '3.2', '4.0']))
opts.Add(EnumVariable('plugin', 'Plugin to build', '', ['', 'apn', 'arkit', 'camera', 'icloud', 'gamecenter', 'inappstore']))
opts.Add(EnumVariable('version', 'Godot version to target', '', ['', '3.3', '4.0']))

# Updates the environment with the option variables.
opts.Update(env)
Expand Down Expand Up @@ -93,7 +93,7 @@ env.Append(LINKFLAGS=["-arch", env['arch'], '-isysroot', sdk_path, '-F' + sdk_pa
if env['arch'] == 'armv7':
env.Prepend(CXXFLAGS=['-fno-aligned-allocation'])

if env['version'] == '3.2':
if env['version'] == '3.3':
env.Prepend(CFLAGS=['-std=gnu11'])
env.Prepend(CXXFLAGS=['-DGLES_ENABLED', '-std=gnu++14'])

Expand Down
40 changes: 40 additions & 0 deletions plugins/apn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Godot iOS Apple Push Notifications plugin

Requires `-ObjC` value added to the `Other Linker Flags` in Xcode project.

Example:

```
var _apn = null

func _apn_device(value):
print("device string: " + value);

...

func _ready():
if Engine.has_singleton("APN"):
var _apn = Engine.get_singleton("APN");
_apn.connect("device_address_changed", self, "_apn_device");

_apn.register_push_notifications(_apn.PUSH_SOUND | _apn.PUSH_BADGE | _apn.PUSH_ALERT);
```

## Enum

Type: `PushOptions`
Values: `PUSH_ALERT`, `PUSH_BADGE`, `PUSH_SOUND`, `PUSH_SETTINGS`

## Methods

`register_push_notifications(PushOptions options)` - Registers device to receive remote notifications through Apple Push Notification service.
`set_badge_number(int value)` - Sets the badge value of the app icon on the Home screen.
`get_badge_number()` - Returns the badge value of the app icon on the Home screen.

## Properties

`badge_number: int` - The number represents the badge of the app icon on the Home screen.

## Signals

`device_address_changed(String token)` - Called whenever iOS device updates remote notification token value.
19 changes: 19 additions & 0 deletions plugins/apn/apn.gdip
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[config]
name="PushNotifications"
binary="apn.xcframework"

initialization="godot_apn_init"
deinitialization="godot_apn_deinit"

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

capabilities=[]

files=[]

linker_flags=["-ObjC"]

[plist]
63 changes: 63 additions & 0 deletions plugins/apn/apn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*************************************************************************/
/* apn.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 godot_apn_implementation_h
#define godot_apn_implementation_h

#include "core/object.h"

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

static void _bind_methods();

public:
enum PushOptions {
PUSH_ALERT = 1 << 0,
PUSH_BADGE = 1 << 1,
PUSH_SOUND = 1 << 2,
PUSH_SETTINGS = 1 << 3,
};

static APNPlugin *get_singleton();

void register_push_notifications(PushOptions options);
void update_device_token(String token);

void set_badge_number(int value);
int get_badge_number();

APNPlugin();
~APNPlugin();
};

VARIANT_ENUM_CAST(APNPlugin::PushOptions)

#endif /* godot_apn_implementation_h */
97 changes: 97 additions & 0 deletions plugins/apn/apn.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*************************************************************************/
/* apn.mm */
/*************************************************************************/
/* 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. */
/*************************************************************************/

#include "apn.h"

#import <Foundation/Foundation.h>

#include "core/class_db.h"
#include "core/project_settings.h"

#import "godot_apn_delegate.h"

static APNPlugin *singleton;

APNPlugin *APNPlugin::get_singleton() {
return singleton;
}

void APNPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("register_push_notifications", "options"), &APNPlugin::register_push_notifications);

ClassDB::bind_method(D_METHOD("set_badge_number", "value"), &APNPlugin::set_badge_number);
ClassDB::bind_method(D_METHOD("get_badge_number"), &APNPlugin::get_badge_number);
ADD_PROPERTY(PropertyInfo(Variant::INT, "badge_number"), "set_badge_number", "get_badge_number");

ADD_SIGNAL(MethodInfo("device_address_changed", PropertyInfo(Variant::STRING, "id")));

BIND_ENUM_CONSTANT(PUSH_ALERT);
BIND_ENUM_CONSTANT(PUSH_BADGE);
BIND_ENUM_CONSTANT(PUSH_SOUND);
BIND_ENUM_CONSTANT(PUSH_SETTINGS);
}

void APNPlugin::register_push_notifications(PushOptions options) {
UNAuthorizationOptions notificationsOptions = UNAuthorizationOptionNone;

if (options & PUSH_ALERT) {
notificationsOptions |= UNAuthorizationOptionAlert;
}

if (options & PUSH_BADGE) {
notificationsOptions |= UNAuthorizationOptionBadge;
}

if (options & PUSH_SOUND) {
notificationsOptions |= UNAuthorizationOptionSound;
}

[[GodotAPNAppDelegate shared] registerPushNotificationsWithOptions:options];
}

void APNPlugin::update_device_token(String token) {
emit_signal("device_address_changed", token);
}

void APNPlugin::set_badge_number(int value) {
UIApplication.sharedApplication.applicationIconBadgeNumber = (long)value;
}

int APNPlugin::get_badge_number() {
return (int)UIApplication.sharedApplication.applicationIconBadgeNumber;
}

APNPlugin::APNPlugin() {
singleton = this;
}

APNPlugin::~APNPlugin() {
singleton = NULL;
}
47 changes: 47 additions & 0 deletions plugins/apn/apn_plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*************************************************************************/
/* apn_plugin.cpp */
/*************************************************************************/
/* 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. */
/*************************************************************************/

#import "apn_plugin.h"
#import "apn.h"

#import "core/engine.h"

APNPlugin *plugin;

void godot_apn_init() {
plugin = memnew(APNPlugin);
Engine::get_singleton()->add_singleton(Engine::Singleton("APN", plugin));
}

void godot_apn_deinit() {
if (plugin) {
memdelete(plugin);
}
}
32 changes: 32 additions & 0 deletions plugins/apn/apn_plugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*************************************************************************/
/* apn_plugin.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. */
/*************************************************************************/

void godot_apn_init();
void godot_apn_deinit();
Loading