「Unity/画像共有/NatShare」の版間の差分
ナビゲーションに移動
検索に移動
| 82行目: | 82行目: | ||
[access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryAddUsageDescription key with a string value explaining to the user how the app uses this data. | [access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryAddUsageDescription key with a string value explaining to the user how the app uses this data. | ||
</pre> | </pre> | ||
NSPhotoLibraryAddUsageDescriptionの権限がないため。 | |||
NSPhotoLibraryAddUsageDescriptionを自動で権限を付ける方法 | |||
Assets/Editor/XcodePhotoLibraryPostProcess.cs | Assets/Editor/XcodePhotoLibraryPostProcess.cs | ||
2023年4月22日 (土) 15:55時点における版
NatShareとは
画像共有プラグイン
androidはversion7.0以上のみ対応
DL&Import
NatShare(github):https://github.com/natmlx/NatShare
githubのcodeからNatSuite-mainをDLし、Assets以下に設置。
x NatShare(UnityAssets):https://assetstore.unity.com/packages/tools/integration/natshare-mobile-sharing-api-117705
UnityAssetsでのインストールは、coreが競合する恐れがあるので、やめておく。詳しくは下の競合項目を。
テキストと画像共有
using UnityEngine;
using UnityEngine.UI;
using NatSuite.Sharing;
public class SampleScene : MonoBehaviour
{
void Start()
{
GameObject.Find("TextButton").GetComponent<Button>().onClick.AddListener(ShareText);
GameObject.Find("ImageButton").GetComponent<Button>().onClick.AddListener(ShareCaptureImage);
GameObject.Find("TextImageButton").GetComponent<Button>().onClick.AddListener(ShareTextCaptureImage);
}
// テキスト共有
void ShareText()
{
var payload = new SharePayload();
payload.AddText("ここに共有したいテキストを入力");
payload.Commit();
}
// キャプチャ画像共有
void ShareCaptureImage()
{
var screenshot = ScreenCapture.CaptureScreenshotAsTexture();
var payload = new SharePayload();
payload.AddImage(screenshot);
payload.Commit();
}
// テキスト&キャプチャ画像共有
void ShareTextCaptureImage()
{
var screenshot = ScreenCapture.CaptureScreenshotAsTexture();
var payload = new SharePayload();
payload.AddText("ここに共有したいテキストを入力");
payload.AddImage(screenshot);
payload.Commit();
}
// 通常画像共有
void ShareImage()
{
Texture2D texture = image.texture;
var payload = new SharePayload();
payload.AddImage(screetexturenshot);
payload.Commit();
}
void
CanvasImage.texture
}
Androidビルド時にcore-1.6.0とjetified-core-1.0.0-rc02が競合するとき
エラー詳細
java.lang.RuntimeException: Duplicate class android.support.v4.graphics.drawable.IconCompatParcelizer found in modules core-1.6.0-runtime.jar (androidx.core:core:1.6.0) and jetified-core-1.0.0-rc02-runtime.jar (:core-1.0.0-rc02:)
AdMobプラグインが、core-1.6.0を使ってるぽい。
対応方法
- NatShareプラグインをUnityAssetsからDLしてる場合は、githubからDLするように
- NatShare-main/Plugins/Android/core-1.0.0-rc02.aarを削除
参考:https://marumaro7.hatenablog.com/entry/natshareerror
iosでシェアの画像を保存ボタンを押すとクラッシュする問題
エラー詳細
[access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryAddUsageDescription key with a string value explaining to the user how the app uses this data.
NSPhotoLibraryAddUsageDescriptionの権限がないため。
NSPhotoLibraryAddUsageDescriptionを自動で権限を付ける方法
Assets/Editor/XcodePhotoLibraryPostProcess.cs
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
#if UNITY_IOS
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor.iOS.Xcode;
public class XcodePhotoLibraryPostProcess : IPostprocessBuildWithReport
{
public int callbackOrder { get { return 0; } }
public void OnPostprocessBuild(BuildReport report)
{
if (report.summary.platform == BuildTarget.iOS)
{
string path = Path.Combine(report.summary.outputPath, "Info.plist");
PlistDocument plist = new PlistDocument();
plist.ReadFromFile(path);
plist.root.SetString("NSPhotoLibraryUsageDescription", "シェアボタンで共有時に画像を選択します");
plist.root.SetString("NSPhotoLibraryAddUsageDescription", "シェアボタンで画像を保存します");
plist.WriteToFile(path);
}
}
}
#endif