3

In Xcode, can I set the "Application supports iTunes file sharing" / UIFileSharingEnabledsetting to YES/NO based on my app's configuration (debug vs release)?

I've seen discussions of using user defined build settings to set string values of string plist items (e.g. $(MY_DEFINED_SETTING), but can you do this with this boolean setting? This wouldn't be exactly the same thing, but as long as it gets removed automatically when building a release version of the app, that's fine. But if I try to enter anything beside YESor NOin the field, it defaults to NO.

I know one can have two different versions of a file based on the configuration, but would be simpler not to have two copies of largely the same file. But if that's the best solution, then any tips on implementing that would be appreciated.

Thanks

shim
  • 9,289
  • 12
  • 69
  • 108

1 Answers1

5

Although the default plist viewer in Xcode wouldn't let me enter a string into the key's value field for UIFileSharingEnabled because it was expecting a boolean, I did manage to get it to let me enter whatever value I wanted by viewing the plist as source code and entering it as follows:

<key>UIFileSharingEnabled</key>
<string>${FILE_SHARING_ENABLED}</string>

As opposed to <true/> or <false/> as the plist editor defaults the second line to.

(Where FILE_SHARING_ENABLED is the name of my user defined build setting with it set to YES for Debug and NO for Release)

screenshot of project settings

Note I also tried setting a user defined build setting where in the debug configuration it was equal to UIFileSharingEnabled, and some gibberish value in release. Then I tried using that as a key, but it didn't get replaced with the value, and was instead treated as a string.

Double check by printing out the contents of the infoDictionary

NSLog(@"%@",[[NSBundle mainBundle] infoDictionary]);

And also by opening iTunes and checking to see if the file sharing works/doesn't work on the phone's Apps page at the bottom. (Remember to test in both debug and release configurations)

shim
  • 9,289
  • 12
  • 69
  • 108
  • 1
    This doesn't seem to work for `NSAllowsArbitraryLoads` :( – Iulian Onofrei Feb 01 '16 at 14:44
  • You have that inside a `NSApptTansportSecurity` dictionary? – shim Feb 01 '16 at 14:52
  • Yes, as soon as I write `` it works, and if I change it to `${MY_USER_DEFINED_SETTING}` it gives me the ATS error. [This user](http://stackoverflow.com/questions/32752817/xcode-build-settings-remove-code-from-plist-on-production-build#comment53544921_32754036) has the same problem too. I find [this solution](http://stackoverflow.com/a/32755225/865175) more easy and safer though. – Iulian Onofrei Feb 01 '16 at 14:54
  • I got error from appstoreconnect while uploading with approach: `ERROR ITMS-90039: "Type Mismatch. The value for the Info.plist key UIFileSharingEnabled is not of the required type for that key...` Seems like you can't upload with custom flag now. – vpoltave Jan 28 '21 at 16:00