From 0914376c1eca60ba0a4416ae59efead12cecf862 Mon Sep 17 00:00:00 2001 From: lucas <452252+catabriga@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:22:07 +0200 Subject: [PATCH 1/6] add AlbumIOS skeleton --- plugins/album/README.md | 1 + plugins/album/album_ios.gdip | 17 +++++++++ plugins/album/album_ios.h | 59 ++++++++++++++++++++++++++++++ plugins/album/album_ios.mm | 56 ++++++++++++++++++++++++++++ plugins/album/album_ios_module.cpp | 54 +++++++++++++++++++++++++++ plugins/album/album_ios_module.h | 32 ++++++++++++++++ 6 files changed, 219 insertions(+) create mode 100644 plugins/album/README.md create mode 100644 plugins/album/album_ios.gdip create mode 100644 plugins/album/album_ios.h create mode 100644 plugins/album/album_ios.mm create mode 100644 plugins/album/album_ios_module.cpp create mode 100644 plugins/album/album_ios_module.h diff --git a/plugins/album/README.md b/plugins/album/README.md new file mode 100644 index 0000000..831c1f4 --- /dev/null +++ b/plugins/album/README.md @@ -0,0 +1 @@ +# Godot iOS Album plugin diff --git a/plugins/album/album_ios.gdip b/plugins/album/album_ios.gdip new file mode 100644 index 0000000..ed53f7f --- /dev/null +++ b/plugins/album/album_ios.gdip @@ -0,0 +1,17 @@ +[config] +name="AlbumIOS" +binary="albumios.xcframework" + +initialization="register_album_ios_types" +deinitialization="unregister_album_ios_types" + +[dependencies] +linked=[] +embedded=[] +system=[] + +capabilities=[] + +files=[] + +[plist] diff --git a/plugins/album/album_ios.h b/plugins/album/album_ios.h new file mode 100644 index 0000000..c34778d --- /dev/null +++ b/plugins/album/album_ios.h @@ -0,0 +1,59 @@ +/*************************************************************************/ +/* album_ios.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 ALBUM_IOS_H +#define ALBUM_IOS_H + +#include "core/version.h" + +#if VERSION_MAJOR == 4 +#include "core/object/class_db.h" +#else +#include "core/object.h" +#endif + + +class AlbumIOS : public Object { + + GDCLASS(AlbumIOS, Object); + + static AlbumIOS *instance; + static void _bind_methods(); + +public: + void publish_image_to_album(String path_to_image); + + static AlbumIOS *get_singleton(); + + AlbumIOS(); + ~AlbumIOS(); +}; + +#endif diff --git a/plugins/album/album_ios.mm b/plugins/album/album_ios.mm new file mode 100644 index 0000000..4550398 --- /dev/null +++ b/plugins/album/album_ios.mm @@ -0,0 +1,56 @@ +/*************************************************************************/ +/* album_ios.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 "album_ios.h" + + +AlbumIOSIOS *AlbumIOSIOS::instance = NULL; + +void AlbumIOS::_bind_methods() { + ClassDB::bind_method(D_METHOD("publish_image_to_album"), &AlbumIOS::publish_image_to_album); +} + +AlbumIOS *AlbumIOS::get_singleton() { + return instance; +} + +AlbumIOS::AlbumIOS() { + ERR_FAIL_COND(instance != NULL); + instance = this; +} + +void AlbumIOS::publish_image_to_album(String path_to_image) { + NSString *path_to_image_ns = [NSString stringWithCString:path_to_image.utf8().get_data() encoding:NSUTF8StringEncoding]; + + +} + +AlbumIOS::~AlbumIOS() { +} diff --git a/plugins/album/album_ios_module.cpp b/plugins/album/album_ios_module.cpp new file mode 100644 index 0000000..cc95042 --- /dev/null +++ b/plugins/album/album_ios_module.cpp @@ -0,0 +1,54 @@ +/*************************************************************************/ +/* album_ios_module.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. */ +/*************************************************************************/ + +#include "album_ios_module.h" + +#include "core/version.h" + +#if VERSION_MAJOR == 4 +#include "core/config/engine.h" +#else +#include "core/engine.h" +#endif + +#include "album_ios.h" + +AlbumIOS *album_ios; + +void register_album_ios_types() { + album_ios = memnew(AlbumIOS); + Engine::get_singleton()->add_singleton(Engine::Singleton("AlbumIOS", album_ios)); +} + +void unregister_album_ios_types() { + if (album_ios) { + memdelete(album_ios); + } +} diff --git a/plugins/album/album_ios_module.h b/plugins/album/album_ios_module.h new file mode 100644 index 0000000..c1a1991 --- /dev/null +++ b/plugins/album/album_ios_module.h @@ -0,0 +1,32 @@ +/*************************************************************************/ +/* album_ios_module.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 register_album_ios_types(); +void unregister_album_ios_types(); From b1c2929dfc178bc0c9e8745034380bbcfdfbfc40 Mon Sep 17 00:00:00 2001 From: lucas <452252+catabriga@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:27:00 +0200 Subject: [PATCH 2/6] add AlbumIOS skeleton --- SConstruct | 2 +- plugins/album/album_ios.mm | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/SConstruct b/SConstruct index c943b12..51ffd68 100644 --- a/SConstruct +++ b/SConstruct @@ -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', '', ['', 'album', 'apn', 'arkit', 'camera', 'icloud', 'gamecenter', 'inappstore', 'photo_picker'])) opts.Add(EnumVariable('version', 'Godot version to target', '', ['', '3.x', '4.0'])) # Updates the environment with the option variables. diff --git a/plugins/album/album_ios.mm b/plugins/album/album_ios.mm index 4550398..b1c700a 100644 --- a/plugins/album/album_ios.mm +++ b/plugins/album/album_ios.mm @@ -30,8 +30,10 @@ #include "album_ios.h" +#import -AlbumIOSIOS *AlbumIOSIOS::instance = NULL; + +AlbumIOS *AlbumIOS::instance = NULL; void AlbumIOS::_bind_methods() { ClassDB::bind_method(D_METHOD("publish_image_to_album"), &AlbumIOS::publish_image_to_album); From ec887d9dab0699076bfaaf2e226cb0e5aa0a88d2 Mon Sep 17 00:00:00 2001 From: lucas <452252+catabriga@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:35:21 +0200 Subject: [PATCH 3/6] add UIKit calls --- plugins/album/album_ios.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/album/album_ios.mm b/plugins/album/album_ios.mm index b1c700a..79f926d 100644 --- a/plugins/album/album_ios.mm +++ b/plugins/album/album_ios.mm @@ -31,6 +31,7 @@ #include "album_ios.h" #import +#import AlbumIOS *AlbumIOS::instance = NULL; @@ -50,8 +51,8 @@ void AlbumIOS::publish_image_to_album(String path_to_image) { NSString *path_to_image_ns = [NSString stringWithCString:path_to_image.utf8().get_data() encoding:NSUTF8StringEncoding]; - - + UIImage *image = [UIImage imageWithContentsOfFile:path_to_image_ns]; + UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); } AlbumIOS::~AlbumIOS() { From 71034781d5e44d8eca8645850d498a97910cfd48 Mon Sep 17 00:00:00 2001 From: lucas <452252+catabriga@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:07:32 +0200 Subject: [PATCH 4/6] rename gdip --- plugins/album/album_ios.gdip | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 plugins/album/album_ios.gdip diff --git a/plugins/album/album_ios.gdip b/plugins/album/album_ios.gdip deleted file mode 100644 index ed53f7f..0000000 --- a/plugins/album/album_ios.gdip +++ /dev/null @@ -1,17 +0,0 @@ -[config] -name="AlbumIOS" -binary="albumios.xcframework" - -initialization="register_album_ios_types" -deinitialization="unregister_album_ios_types" - -[dependencies] -linked=[] -embedded=[] -system=[] - -capabilities=[] - -files=[] - -[plist] From b40256aafd03471a9deffcdedf3afefc8b10733a Mon Sep 17 00:00:00 2001 From: lucas <452252+catabriga@users.noreply.github.com> Date: Tue, 9 Jul 2024 23:32:14 +0200 Subject: [PATCH 5/6] add video publishing --- plugins/album/album_ios.h | 1 + plugins/album/album_ios.mm | 8 +++++++- plugins/album/albumios.gdip | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 plugins/album/albumios.gdip diff --git a/plugins/album/album_ios.h b/plugins/album/album_ios.h index c34778d..a74b4ba 100644 --- a/plugins/album/album_ios.h +++ b/plugins/album/album_ios.h @@ -49,6 +49,7 @@ class AlbumIOS : public Object { public: void publish_image_to_album(String path_to_image); + void publish_video_to_album(String path_to_video); static AlbumIOS *get_singleton(); diff --git a/plugins/album/album_ios.mm b/plugins/album/album_ios.mm index 79f926d..00acb8f 100644 --- a/plugins/album/album_ios.mm +++ b/plugins/album/album_ios.mm @@ -37,7 +37,8 @@ AlbumIOS *AlbumIOS::instance = NULL; void AlbumIOS::_bind_methods() { - ClassDB::bind_method(D_METHOD("publish_image_to_album"), &AlbumIOS::publish_image_to_album); + ClassDB::bind_method(D_METHOD("publish_image_to_album"), &AlbumIOS::publish_image_to_album); + ClassDB::bind_method(D_METHOD("publish_video_to_album"), &AlbumIOS::publish_video_to_album); } AlbumIOS *AlbumIOS::get_singleton() { @@ -55,5 +56,10 @@ UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); } +void AlbumIOS::publish_video_to_album(String path_to_video) { + NSString *path_to_video_ns = [NSString stringWithCString:path_to_video.utf8().get_data() encoding:NSUTF8StringEncoding]; + UISaveVideoAtPathToSavedPhotosAlbum(path_to_video_ns, nil, nil, nil); +} + AlbumIOS::~AlbumIOS() { } diff --git a/plugins/album/albumios.gdip b/plugins/album/albumios.gdip new file mode 100644 index 0000000..ed53f7f --- /dev/null +++ b/plugins/album/albumios.gdip @@ -0,0 +1,17 @@ +[config] +name="AlbumIOS" +binary="albumios.xcframework" + +initialization="register_album_ios_types" +deinitialization="unregister_album_ios_types" + +[dependencies] +linked=[] +embedded=[] +system=[] + +capabilities=[] + +files=[] + +[plist] From da5ec4edf69686ea3e5c26904cb1c5e39536b52e Mon Sep 17 00:00:00 2001 From: lucas <452252+catabriga@users.noreply.github.com> Date: Wed, 10 Jul 2024 19:35:01 +0200 Subject: [PATCH 6/6] Update readme --- plugins/album/README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/plugins/album/README.md b/plugins/album/README.md index 831c1f4..f3a0bbe 100644 --- a/plugins/album/README.md +++ b/plugins/album/README.md @@ -1 +1,24 @@ # Godot iOS Album plugin + +This plugin enables you to publish images and videos that have been saved in the //user: storage space. + +## Example + +``` +extends Control + +var album_ios = null + +func _ready(): + if Engine.has_singleton("AlbumIOS"): + album_ios = Engine.get_singleton('AlbumIOS') + +func publish_image_to_album(image_path: String): + if album_ios != null: + album_ios.publish_image_to_album(image_path) + +func publish_video_to_album(video_path: String): + if album_ios != null: + album_ios.publish_video_to_album(video_path) + +``` \ No newline at end of file