$ show yasirkula/UnityNativeShare
UnityNativeShare is a Unity plugin library that enables native file and text sharing on Android and iOS platforms. The codebase consists of a C# Unity plugin (NativeShare.cs) that provides a fluent API for sharing content, with native implementations in Java for Android and Objective-C++ for iOS. The Android implementation uses a ContentProvider for secure file sharing and includes custom share dialog support for callback reliability across different Android versions. The iOS implementation uses UIActivityViewController with proper memory management for share result callbacks. The architecture follows a standard Unity plugin pattern with platform-specific native code wrapped by C# interfaces. Key entry points are the NativeShare class methods (AddFile, SetText, Share) and the native callback receivers (NSShareResultCallbackAndroid, NSShareResultCallbackiOS). The plugin handles platform-specific edge cases including Xiaomi/MIUI device quirks, Android 11+ package visibility requirements, and iOS photo library permissions. However, the README explicitly states this asset is no longer maintained, which is a critical finding. While the code demonstrates solid craftsmanship for its time, the lack of active maintenance means compatibility with newer OS versions (Android 13+, iOS 16+) is uncertain. The technical debt includes potential issues with newer Android package visibility changes and iOS share sheet behavior modifications.
The LLM identified 4 files worth highlighting for reuse:
Core C# Unity plugin class implementing a fluent API for native sharing. Demonstrates clean separation of concerns with platform-specific code isolated via conditional compilation. The Share() method properly handles Android Java interop and iOS native calls. Texture sharing includes fallback logic for non-readable textures using RenderTexture blitting. Well-structured with proper error handling and memory management patterns.
Android ContentProvider implementation for secure file sharing. Follows Android FileProvider patterns with proper security checks (non-exported, grantUriPermissions). Implements PathStrategy for file-to-URI mapping with canonical path resolution. Handles MIME type detection and file metadata queries. The implementation is self-contained and demonstrates proper Android security practices for file sharing.
Unity Editor post-process build script that automatically configures iOS Info.plist with photo library usage descriptions. Uses Unity's PlistDocument API for safe XML manipulation. Implements settings persistence with JSON serialization and editor preferences GUI. This component is reusable for any Unity plugin requiring iOS permission configuration.
Custom share dialog implementation that provides consistent callback behavior across all Android versions. Uses DialogFragment for proper lifecycle management and displays share targets in a GridView with app icons. Handles edge cases like unexported activities and empty share targets. The adapter pattern for displaying apps demonstrates clean separation of UI and data logic.