Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by Hotshot10101 · Jan 17, 2013 at 05:22 PM · arraystrings

Add Array of Strings to info.plist

I need some help. I need to add a completely new entry to info.plist. This new entry is an array and I need to set the first element to a value.

I have seen this post, but it only shows modifying an existing string in info.plist:

http://www.unifycommunity.com/wiki/index.php?title=IPhone_Build_Utility_Script

Specifically I am connecting to an external accessory and need to add the info.plist entry for:

Supported external accessory protocols

which is an array type.

then I need to set the first element to a protocol string similar to:

com.AmpedRFTech.Demo

I don't need to copy splash screens or icons or any of that. All I need to do is add the above.

Can someone help me out?

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
2
Best Answer

Answer by Hotshot10101 · Jan 18, 2013 at 06:27 PM

I figured this out. Turns out it was easier than I thought. I assumed that since it was an Array type that it would be harder than just adding a string, but it isn't. I also realized as I studied the existing code in the above link that the info.plist file is just XML. XML I know well.

There are a couple of things to note. When looking at the values in Xcode they are spelled out at strings like Support external accessory protocols. In the XML the key is actually UISupportedExternalAccessoryProtocols. I found this out by putting in what I thought it should be and it didn't work. I then opened the info.plist file in MonoDevelop and it shows the real key string.

You will probably also notice that I needed to add the UIBackgroundModes array as well.

Hope this saves someone else some time.

Here is my script:

 #!/usr/bin/perl
 use File::Copy; 
 
 print ("\n*** Starting PostprocessBuildPlayer ***\n");
 
 my $installPath = $ARGV[0]; 
    
 #go through the info.plist file line by line until you find this one: 
 my $endOfPlist = "</dict>"; 
    
 # The type of player built: 
 # "dashboard", "standaloneWin32", "standaloneOSXIntel", "standaloneOSXPPC", "standaloneOSXUniversal", "webplayer", "iPhone" 
 my $target = $ARGV[1]; 
    
 print ("\n*** PostprocessBuildPlayer - Building at '$installPath' with target: $target ***\n"); 
   
 ################################################################ 
 # This modifies info.plist to add the external accessory       # 
 # entries                                                      # 
 ################################################################ 
    
 #open this file 
    
 $oplistPath = $installPath."/Info.plist"; 
 $nplistPath = $installPath."/Info.plist.tmp"; 
    
 open OLDPLIST, "<", $oplistPath or die("Cannot open Info.plist"); 
 open NEWPLIST, ">", $nplistPath or die("Cannot create new Info.plist"); 
    
 my $nextLine = 0;    
        
 while(<OLDPLIST>) 
 {     
    ################################################################ 
    # Add any key/value pairs you want at the end of Info.plist    # 
    ################################################################ 
    
    if ($_ =~ m/$endOfPlist/) 
    { 
       my $keys = "";
           
       $keys .= "   <key>UISupportedExternalAccessoryProtocols</key>\n";
       $keys .= "   <array>\n"; 
       $keys .= "      <string>com.AmpedRFTech.Demo</string>\n";
       $keys .= "   </array>\n";
           
       $keys .= "   <key>UIBackgroundModes</key>\n"; 
       $keys .= "   <array>\n"; 
       $keys .= "      <string>App communicates with an accessory</string>\n";
       $keys .= "   </array>\n";
           
       $_ = $keys . $_; 
    } 
        
    print NEWPLIST $_; 
 } 
    
 close OLDPLIST; 
 close NEWPLIST; 
    
 `mv \'$nplistPath\' \'$oplistPath\'`; 
 
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
Wiki

Answer by sopepos · May 07, 2015 at 09:15 AM

Thanks to Hotshot10101 for the script. I modified it a bit. (for detecting the end of Info.plist correctly.)

 #!/usr/bin/perl
 
 use File::Copy;
 
 print ("\n*** Starting PostprocessBuildPlayer ***\n");
 
 my $installPath = $ARGV[0];
 
 #go through the info.plist file line by line until you find this one:
 my $endOfDict = "</dict>";
 my $endOfPlist = "</plist>";
 
 # The type of player built:
 # "dashboard", "standaloneWin32", "standaloneOSXIntel", "standaloneOSXPPC", "standaloneOSXUniversal", "webplayer", "iPhone"
 my $target = $ARGV[1];
 
 print ("\n*** PostprocessBuildPlayer - Building at '$installPath' with target: $target ***\n");
 
 ################################################################
 # This modifies info.plist to add the external accessory       #
 # entries                                                      #
 ################################################################
 
 #open this file
 
 $oplistPath = $installPath."/Info.plist";
 $nplistPath = $installPath."/Info.plist.tmp";
 
 open OLDPLIST, "<", $oplistPath or die("Cannot open Info.plist");
 open NEWPLIST, ">", $nplistPath or die("Cannot create new Info.plist");
 
 while(<OLDPLIST>)
 {
     ################################################################
     # Add any key/value pairs you want at the end of Info.plist    #
     ################################################################
 
     if ($_ =~ m/$endOfDict/)
     {
         my $pos = tell OLDPLIST;
         my $nextLine = <OLDPLIST>;
         if ($nextLine =~ m/$endOfPlist/)
         {
             my $keys = "";
             
             $keys .= "   <key>UISupportedExternalAccessoryProtocols</key>\n";
             $keys .= "   <array>\n"; 
             $keys .= "      <string>com.AmpedRFTech.Demo</string>\n";
             $keys .= "   </array>\n";
                
             $keys .= "   <key>UIBackgroundModes</key>\n"; 
             $keys .= "   <array>\n"; 
             $keys .= "      <string>App communicates with an accessory</string>\n";
             $keys .= "   </array>\n";       
 
             print NEWPLIST $keys;
         }
         seek OLDPLIST, $pos, 0;
     } 
     print NEWPLIST $_;
 }
 
 close OLDPLIST;
 close NEWPLIST;
 
 `mv \'$nplistPath\' \'$oplistPath\'`;
 
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.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

Inventory system using an array... 3 Answers

Increasing And Decreasing An Array Through A Variable 2 Answers

A node in a childnode? 1 Answer

how do I Instantiate a game object on a trigger 2 Answers

Creating an array of gui styles and using them 1 Answer


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