Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

Commit

Permalink
Moved iOS build post-processor settings to 'Project Settings/yasirkul…
Browse files Browse the repository at this point in the history
…a/Native Share'
  • Loading branch information
yasirkula committed Jul 5, 2021
1 parent 0a1f502 commit 9b1575d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ For reference, the legacy documentation is available at: https://github.com/yasi

There are two ways to set up the plugin on iOS:

- **a. Automated Setup:** *(optional)* change the value of **PHOTO_LIBRARY_USAGE_DESCRIPTION** in *Plugins/NativeShare/Editor/NSPostProcessBuild.cs*
- **a. Automated Setup:** *(optional)* change the value of **Photo Library Usage Description** at *Project Settings/yasirkula/Native Share*
- **b. Manual Setup:** see: https://github.com/yasirkula/UnityNativeShare/wiki/Manual-Setup-for-iOS

## HOW TO
Expand Down
83 changes: 73 additions & 10 deletions Plugins/NativeShare/Editor/NSPostProcessBuild.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,88 @@
#if UNITY_IOS
using System.IO;
using System.IO;
using UnityEditor;
using UnityEngine;
#if UNITY_IOS
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
#endif

namespace NativeShareNamespace
{
public class NSPostProcessBuild
[System.Serializable]
public class Settings
{
private const bool ENABLED = true;
private const string PHOTO_LIBRARY_USAGE_DESCRIPTION = "The app requires access to Photos to save media to it.";
private const string SAVE_PATH = "ProjectSettings/NativeShare.json";

public bool AutomatedSetup = true;
public string PhotoLibraryUsageDescription = "The app requires access to Photos to save media to it.";

private static Settings m_instance = null;
public static Settings Instance
{
get
{
if( m_instance == null )
{
try
{
if( File.Exists( SAVE_PATH ) )
m_instance = JsonUtility.FromJson<Settings>( File.ReadAllText( SAVE_PATH ) );
else
m_instance = new Settings();
}
catch( System.Exception e )
{
Debug.LogException( e );
m_instance = new Settings();
}
}

return m_instance;
}
}

public void Save()
{
File.WriteAllText( SAVE_PATH, JsonUtility.ToJson( this, true ) );
}

#if UNITY_2018_3_OR_NEWER
[SettingsProvider]
public static SettingsProvider CreatePreferencesGUI()
{
return new SettingsProvider( "Project/yasirkula/Native Share", SettingsScope.Project )
{
guiHandler = ( searchContext ) => PreferencesGUI(),
keywords = new System.Collections.Generic.HashSet<string>() { "Native", "Share", "Android", "iOS" }
};
}
#endif

#if !UNITY_2018_3_OR_NEWER
[PreferenceItem( "Native Share" )]
#endif
public static void PreferencesGUI()
{
EditorGUI.BeginChangeCheck();

Instance.AutomatedSetup = EditorGUILayout.Toggle( "Automated Setup", Instance.AutomatedSetup );

EditorGUI.BeginDisabledGroup( !Instance.AutomatedSetup );
Instance.PhotoLibraryUsageDescription = EditorGUILayout.DelayedTextField( new GUIContent( "Photo Library Usage Description", "Shown to user when they select the 'Save to Photos' option in share sheet" ), Instance.PhotoLibraryUsageDescription );
EditorGUI.EndDisabledGroup();

if( EditorGUI.EndChangeCheck() )
Instance.Save();
}
}

public class NSPostProcessBuild
{
#if UNITY_IOS
#pragma warning disable 0162
[PostProcessBuild]
public static void OnPostprocessBuild( BuildTarget target, string buildPath )
{
if( !ENABLED )
if( !Settings.Instance.AutomatedSetup )
return;

if( target == BuildTarget.iOS )
Expand All @@ -29,13 +93,12 @@ public static void OnPostprocessBuild( BuildTarget target, string buildPath )
plist.ReadFromString( File.ReadAllText( plistPath ) );

PlistElementDict rootDict = plist.root;
rootDict.SetString( "NSPhotoLibraryUsageDescription", PHOTO_LIBRARY_USAGE_DESCRIPTION );
rootDict.SetString( "NSPhotoLibraryAddUsageDescription", PHOTO_LIBRARY_USAGE_DESCRIPTION );
rootDict.SetString( "NSPhotoLibraryUsageDescription", Settings.Instance.PhotoLibraryUsageDescription );
rootDict.SetString( "NSPhotoLibraryAddUsageDescription", Settings.Instance.PhotoLibraryUsageDescription );

File.WriteAllText( plistPath, plist.WriteToString() );
}
}
#pragma warning restore 0162
#endif
}
}
5 changes: 3 additions & 2 deletions Plugins/NativeShare/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Online documentation & example code available at: https://github.com/yasirkula/UnityNativeShare
E-mail: [email protected]


1. ABOUT
This plugin helps you natively share files (images, videos, documents, etc.) and/or plain text on Android & iOS. A ContentProvider is used to share the media on Android.

Expand All @@ -17,10 +18,10 @@ For reference, the legacy documentation is available at: https://github.com/yasi
There are two ways to set up the plugin on iOS:

a. Automated Setup for iOS
- change the value of PHOTO_LIBRARY_USAGE_DESCRIPTION in Plugins/NativeShare/Editor/NSPostProcessBuild.cs (optional)
- (optional) change the value of 'Photo Library Usage Description' at 'Project Settings/yasirkula/Native Share'

b. Manual Setup for iOS
- set the value of ENABLED to false in NSPostProcessBuild.cs
- set the value of 'Automated Setup' to false at 'Project Settings/yasirkula/Native Share'
- build your project
- enter a Photo Library Usage Description to Info.plist in Xcode (in case user decides to save the shared media to Photos)
- also enter a Photo Library Additions Usage Description to Info.plist in Xcode, if exists
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.yasirkula.nativeshare",
"displayName": "Native Share",
"version": "1.4.1",
"version": "1.4.2",
"documentationUrl": "https://github.com/yasirkula/UnityNativeShare",
"changelogUrl": "https://github.com/yasirkula/UnityNativeShare/releases",
"licensesUrl": "https://github.com/yasirkula/UnityNativeShare/blob/master/LICENSE.txt",
Expand Down

0 comments on commit 9b1575d

Please sign in to comment.