• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by multimediamarkers · Oct 29, 2017 at 05:53 PM · iosplist

Can not change " NSPhotoLibraryUsageDescription / NSPhotoLibraryAddUsageDescription" in postbuildprocess

Hi,

I have a very strange t$$anonymous$$ng going on. In a post build process i will change the NSCameraUsageDescription/NSMicrophoneUsageDescription in what ever i want from script. But when i want to change the NSPhotoLibraryAddUsageDescription (t$$anonymous$$s one is not in Player Settings) setting in the info.plist file from script it is not changed when i build/run the app in Xcode.

The NSPhotoLibraryAddUsageDescription can not be set in Unity Player Settings so i need to do it from code. Offcourse when i change the NSPhotoLibraryAddUsageDescription in Xcode by hand it works but i like to do it from a post build process.

I hope someone can help me with t$$anonymous$$s one ...

Greetings,

Mark

My code looks like:

using UnityEditor; using UnityEditor.Callbacks; using UnityEngine; using System.IO; using UnityEditor.iOS.Xcode;

public static class MyBuildPostprocessor { [PostProcessBuild(0)] public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) { Debug.Log("OnPostProcessBuild started ...");

     if (target == BuildTarget.iOS)
     {

         // Get plist
         string plistPath = pathToBuiltProject + "/Info.plist";
         PlistDocument plist = new PlistDocument();
         plist.ReadFromString(File.ReadAllText(plistPath));

         // Get root
         PlistElementDict rootDict = plist.root;

         // Change value of NSCameraUsageDescription in Xcode plist
         var buildKey = "NSCameraUsageDescription";
         rootDict.SetString(buildKey, "T$$anonymous$$s description is created from code");
         Debug.Log("NSCameraUsageDescription changed.");

         //Change value of NSPhotoLibraryAddUsageDescription in Xcode plist
         buildKey = "NSPhotoLibraryAddUsageDescription";
         rootDict.SetString(buildKey, "Photo library ADD usage description changed from code.");
         Debug.Log("NSPhotoLibraryAddUsageDescription changed.");
        
         // Change value of NSPhotoLibraryUsageDescription in Xcode plist
         var buildKey = "NSMicrophoneUsageDescription";
         rootDict.SetString(buildKey, "T$$anonymous$$s description is created from code");
         Debug.Log("NSMicrophoneUsageDescription changed.");

         // Write to file
         File.WriteAllText(plistPath, plist.WriteToString());
     }
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by developersice · Oct 30, 2017 at 11:02 AM

Same issue here with a sharing function, right pain having to do it manually everytime we build the app

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by IMD · May 02, 2019 at 04:56 PM

It's working for me... perhaps ensure t$$anonymous$$s is executed last, after plugin post-processors by updating the order of execution using the attribute parameter : [PostProcessBuild(99)].

For example:

  [PostProcessBuild(99)]
     public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {
         if (target == BuildTarget.iOS) {
             OnPostprocessBuildIOS(pathToBuiltProject);
         }
     }

Best, Isaac

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

147 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why does Apple think my Unity project is trying to access the camera? 6 Answers

Unity xCode-proj all Capabilities are disabled by default after updating to Version 8.3 (8E162) 1 Answer

iOS build 10x larger than Android (over 1GB!) 1 Answer

Resources.Load works in Editor but fails when building to iPhone 0 Answers

UNET: Network [Command] from non-player object 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges