Can i modify Root.plist in settings bundle dynamically? - iphone

I have a settings bundle in my app.. containing root.plist
now i have a screen which contains a checkbox..
on pressing the check box i want to change the BOOL value for DefaultValue key of PSToggleSwitchSpecifier in the plist.
Since its being done at runtime.. my question is that .. can the file be changed at runtime and if yes.. give an idea how to do it??
here is the plist:
<plist version="1.0">
<dict>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>DefaultValue</key>
<string></string>
<key>Key</key>
<string>Username</string>
<key>Title</key>
<string>Username</string>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
</dict>
<dict>
<key>DefaultValue</key>
<string></string>
<key>IsSecure</key>
<true/>
<key>Key</key>
<string>Password</string>
<key>Title</key>
<string>Password</string>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string> <-----toggleSwitch
<key>Title</key>
<string>Remember</string>
<key>Key</key>
<string>CheckBox</string>
<key>DefaultValue</key> <----- Default Value
<false/> <---- want to change this value
</dict>
</array>
<key>Title</key>
<string>Settings</string>
</dict>
</plist>
thank you in advance ;)

Because the settings bundle resides inside your app's bundle, you cannot change it at runtime, only at compile-time.
You can, however, use NSUserDefaults to set the value at runtime, and the settings application will automatically reflect this. It will be saved elsewhere, though. You can just read it back the same way as you would do with the settings bundle, also through NSUserDefaults.
Note that you shouldn't read from the settings bundle directly, as it makes no sense. You should always fetch and set user defaults using NSUserDefaults. When the user makes a change in the settings application, NSUserDefaults will reflect this automatically. They will always be kept in sync.

You can not modify files with the application bundle..

Related

My app is not showing up in Share Sheet

I integrated share extension in my application. This is my plist file for share extensions.
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<string>TRUEPREDICATE</string>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
I am receiving warning in Xcode that if I use Truepredicate then apple will reject my application. So I tried adding other activation rule as mentioned below
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
But if I remove Truepredicate and add above rules my share extension does not show any more. With truepredicate share extensions works perfectly fine.
Can anyone help me what should I do here?
I had integrated share extensions for music related apps.
There was mistake in My Plist file that's why was facing such issue.
Posting this answer just because may be in future if someone will do such mistake so my answer could help out!
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>1</integer>
</dict>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
This is working perfectly fine!
You have to wrap your new keys such as NSExtensionActivationSupportsWebURLWithMaxCount
inside a dictionary tag.
Put this back in your code:,
NSExtensionActivationRule, this key needs to reference the dictionary of new keys.
I don't write apps for ios, so I'm not sure why <string>TRUEPREDICATE</string> is the default. I just know it allows all data types to be passed implicitly. Data types must be explicitly as shown below.
Example:
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>0</integer>
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
<integer>0</integer>
<key>NSExtensionActivationSupportsText</key>
<false/>
</dict>
<key>NSExtensionPointName</key>
<string>com.apple.ui-services</string>
<key>NSExtensionPointVersion</key>
<string>1.0</string>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.ui-services</string>

Why can't I register my iOS application to handle the image file type?

I have a problem registering image file types to my application. I tried adding the code below to my plist but nothing happens.
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Scary Bug Document</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>CFBundleTypeRole</key>
<string>None</string>
<key>LSItemContentTypes</key>
<array>
<string>public.image</string>
</array>
</dict>
</array>
I noticed that I can register for other file types, such as text (changing the public.image to public.text) but it just won't work with images (the "Open In .." menu is not showing my app).
What could be causing this, and how could I fix it?
It is now possible to open images from the mail app in iOS 7, it's just somewhat convoluted:
Tap and hold the image.
Tap on Quick Look so the image goes fullscreen.
Tap the image to show the top toolbar.
Tap the open in button at the top right.
Scroll the list to the left to find your app.
Be sure to set up your bundle document types for the image types you are interested in.
Dimitri Bouniol response that it works in iOS 7 via quick look is correct.
The following additions to my in info.plist below are how I got it to work for my app.
Still have not figured out how to get share in photos or camera roll to work.
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>myapp image</string>
</array>
<key>CFBundleTypeName</key>
<string>public.png</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.png</string>
<string>public.jpeg</string>
</array>
</dict>
</array>
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.image</string>
</array>
<key>UTTypeIdentifier</key>
<string>public.png</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>com.apple.ostype</key>
<string>PNG</string>
<key>public.filename-extension</key>
<array>
<string>png</string>
</array>
<key>public.mime-type</key>
<string>image/png</string>
</dict>
</dict>
<dict>
<key>UTTypeIdentifier</key>
<string>public.jpeg</string>
<key>UTTypeReferenceURL</key>
<string>http://www.w3.org/Graphics/JPEG/</string>
<key>UTTypeDescription</key>
<string>JPEG image</string>
<key>UTTypeIconFile</key>
<string>public.jpeg.icns</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.image</string>
<string>public.data</string>
</array>
<key>UTTypeTagSpecification</key>
<dict>
<key>com.apple.ostype</key>
<string>JPEG</string>
<key>public.filename-extension</key>
<array>
<string>jpeg</string>
<string>jpg</string>
</array>
<key>public.mime-type</key>
<string>image/jpeg</string>
</dict>
</dict>
</array>
Try:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Scary Bug Document</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>CFBundleTypeRole</key>
<string>None</string>
<key>LSItemContentTypes</key>
<array>
<string>public.png</string>
<string>public.jpg</string>
</array>
</dict>
</array>
Also, see this other answer on StackOverflow
After doing a bit of research it seems that is not possible to register the app for images.
Thanks for your answers.
public.image is an abstract type, try registering for public.png or public.jpeg etc
Per Apple's documentation, "to add the document type do the following:
Click on the disclosure button for Document Types to open the document types.
In the “Types” section fill in the UTI for the new type.
For the key value type: CFBundleTypeRole.
For the value type: Editor.
For the key value type: LSHandlerRank.
For the value type: Owner."
This works for me using public.image as the UTI.
OS will not allow you to open images in your app. I also tried myself a lot of permutation & combination, and confirmed from a few more posts in Apple Support.

Xcode 4 Document Types and Exported UTIs

I have an other problem with Xcode 4. I really like the new IDE but there are a few things I didn't get to work yet. One thing is to register Document Types with Xcode 4.
I tried it with the old way through the plist file, but it didn't work. (Means I couldn't open a file with my app) But I don't now how to set it up with the interface of Xcode 4.
My latest try looks like this: (Copied the entry made from Xcode in the info.plist)
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.plain-text</string>
</array>
<key>UTTypeDescription</key>
<string>Configuration File</string>
<key>UTTypeIdentifier</key>
<string>com.myname.projec.iws</string>
</dict>
</array>
and:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
<string>AnIcon-320</string>
</array>
<key>CFBundleTypeName</key>
<string>Config File</string>
<key>LSItemContentTypes</key>
<array>
<string>com.myname.projec.iws</string>
</array>
</dict>
</array>
This does not work. The file in Mail doesn't have the option to open with my app.
Does anyone have a working example with Xcode 4 or a tutorial how to do it. I don't have any further Idea how to get it work.
Sandro
I think the role and the file extension are missing.
If you want to specify a file extension, you need to add UTTypeTagSpecification:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.text</string>
</array>
<key>UTTypeDescription</key>
<string>my document type</string>
<key>UTTypeIdentifier</key>
<string>com.mycompany.myfiletypename</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>iws</string>
</array>
</dict>
</dict>
For the role, you need to add CFBundleTypeRole:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>My file</string>
<key>CFBundleTypeIconFiles</key>
<array>
<string>document-320.png</string>
<string>document-64.png</string>
</array>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSItemContentTypes</key>
<array>
<string>com.mycompany.myfiletypename</string>
</array>
</dict>
</array>
You can edit the equivalent of your 'com.mycompany.myfiletypename' by setting "Document Types" => "Item 0" => "Document OS Types" => "Item 0".
The default value is "????" which you can change to "com.mycompany.myfiletypename".
I think the other properties speak for themselves.
I just looked at my old .plist file and cut and pasted the keys and values into the new one in Xcode 4 project that had been imported from an Xcode3 version. It apparently "loses" some of the info in the .plist for UTI's when it comes over. However, when I pasted the missing keys/values back in from .plist made with Xcode3, the new values worked AND they appear in the GUI so you can now "browse" the GUI and see what goes where. Kind of reverse engineering the GUI but it works.

How do I register a custom filetype in iOS

I am currently creating a app in which i want to let the user backup their files (plist + m4a). I zip the files and change the extension to a custom one (specifically for my app, say "*.MyBackup"). The user can then either export via email or with iTunes file sharing.
I have already read about CFBundleDocumentTypes but didn't really get what I had to do with them.
The part where i am currently stuck at is how to associate my extension with my app. If the user sends himself an email with the "custom"-zip file he's supposed to be able to open it with my app.
How do I do this and what are "UTExportedTypeDeclarations"?
I hope it's okay if I dump in that part of my projects info.plist without much further explanation. I think it's pretty much self-explanatory.
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
<string>Icon-iPad-doc320.png</string>
<string>Icon-iPad-doc.png</string>
</array>
<key>CFBundleTypeName</key>
<string>MyAppName File</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<!-- my app supports files with my custom extension (see UTExportedTypeDeclarations) -->
<string>com.myurl.myapp.myextension</string>
<!-- and csv files. -->
<string>public.comma-separated-values-text</string>
</array>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>MyAppName File</string>
<key>UTTypeIdentifier</key>
<string>com.myurl.myapp.myextension</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>myextension</string>
<key>public.mime-type</key>
<string>application/octet-stream</string>
</dict>
</dict>
</array>
Check out /var/mobile/Library/Preferences/com.apple.LaunchServices.plist.

root.plist changes not visible on iphone

when i add new entries to my settings bundle root.plist file, build and run the app, the new settings are not visible within the app. I've of course used a unique key for the new entries.
In my root.plist file in the xcode project the file shows the changes, but when i get the current file from the iphone via the organizer, the changes are not there.
I am using iOs 4.0.1.
BR,
Martin
Delete and reinstall the app. There's a bug where updated resources may not be installed when the app already exists on the device.
Root.pList
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>StringsTable</key>
<string>Root</string>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Type</key>
<string>PSGroupSpecifier</string>
<key>Title</key>
<string>iParkschein Einstellungen</string>
</dict>
<dict>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
<key>Title</key>
<string>Kennzeichen</string>
<key>Key</key>
<string>kennzeichen_preference</string>
<key>DefaultValue</key>
<string></string>
<key>IsSecure</key>
<false/>
<key>KeyboardType</key>
<string>Alphabet</string>
<key>AutocapitalizationType</key>
<string>None</string>
<key>AutocorrectionType</key>
<string>No</string>
</dict>
<dict>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
<key>Title</key>
<string>Stadt</string>
<key>Key</key>
<string>stadt_preference</string>
<key>DefaultValue</key>
<string>Wien</string>
<key>IsSecure</key>
<false/>
<key>KeyboardType</key>
<string>Alphabet</string>
<key>AutocapitalizationType</key>
<string>None</string>
<key>AutocorrectionType</key>
<string>No</string>
</dict>
<dict>
<key>Type</key>
<string>PSToggleSwitchSpecifier</string>
<key>Title</key>
<string>Firmenrechnung</string>
<key>Key</key>
<string>firmenrechnung_preference</string>
<key>DefaultValue</key>
<true/>
</dict>
<dict>
<key>Type</key>
<string>PSTextFieldSpecifier</string>
<key>Title</key>
<string>Kennzeichen</string>
<key>Key</key>
<string>servicenummer_preference</string>
<key>DefaultValue</key>
<string></string>
<key>IsSecure</key>
<false/>
<key>KeyboardType</key>
<string>Alphabet</string>
<key>AutocapitalizationType</key>
<string>None</string>
<key>AutocorrectionType</key>
<string>No</string>
</dict>
</array>
</dict>
</plist>
if i read the keys from the userdefaults and write them to the console, i get ever key except the servicenummer_preference
BR,
Martin