What plist settings should I use to share documents in iOS8 - cocoa-touch

I'm trying to share a document using SLComposeServiceViewController in iOS, the document I'm testing this out with is a pdf (though I need the ability to share any file).
I send my PDF to Mail on the iPhone, press and hold on the attachment, but my icon never shows.
I have image, URL and Text share working fine, I just can't seem to get any type of document to work.
I'm assuming NSExtensionActivationSupportsAttachmentsWithMaxCount and/or NSExtensionActivationSupportsFileWithMaxCount need to be set, but I have no idea what the difference is between them.
This is my plist at the moment...
Can anyone help?
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>10</integer>
<key>NSExtensionActivationSupportsAttachmentsWithMinCount</key>
<integer>0</integer>
<key>NSExtensionActivationSupportsAttachmentsWithMaxCount</key>
<integer>20</integer>
<key>NSExtensionActivationSupportsMovieWithMaxCount</key>
<integer>0</integer>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsVideoWithMaxCount</key>
<integer>0</integer>
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
<integer>0</integer>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>1</integer>
</dict>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>

These are predicates and all of them have to be satisfied for your extension to be shown. You probably only need NSExtensionActivationSupportsAttachmentsWithMinCount like this:
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsAttachmentsWithMinCount</key>
<integer>1</integer>
</dict>
<key>NSExtensionPointName</key>
<string>com.apple.share-services</string>
<key>NSExtensionPointVersion</key>
<string>1.0</string>
</dict>
Test using just TRUEPREDICATE to make sure the predicates are really the cause of the problem.
One more thing: share extensions are not enabled by default, so make sure you check the More [...] button at the end of the list of share targets.

You can get files from Mail (or similar) and Dropbox (Box, iCloud or similar) with this code in your extension info.plist
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>

Related

NSUserDefaults objectIsForcedForKey with a nested dictionary

Currently I am using [[NSUserDefaults standardDefaults] objectIsForcedForKey: #"TestKey"]; to verify whether the key is managed or not.
This works great for a plist that would have each key on the list
<plist version="1.0">
<dict>
<key>Test</key>
<integer>1</integer>
</dict>
</plist>
but when I use nested dictionaries - the function can't seem to see that the object is being managed
<plist version="1.0">
<dict>
<key>TestKey1</key>
<integer>1</integer>
<dict>
<key>Dictionary2</key>
<dict>
<key>TestKey3</key>
<string>testkey3_value</string>
</dict>
</dict>
</dict>
</plist>
When I attempt to do something like [[NSUserDefaults standardDefaults] objectIsForcedForKey: #"TestKey3"]; It doesn't seem to realize that it is being managed
Your defaults domain does not include a key named "TestKey3". The dictionary containing that key is one of your own, and is not managed by NSUserDefaults. Therefore, NSUserDefaults's APIs will not be able to see '"TestKey3"`.

NSPerformService "Tweet" with an Image (Twitter.app)

Is there anyway to NSPerformService(#"Tweet", [NSPasteboard generalPasteboard]); with an image? I know that simply text is possible, but i don't know about the image.If yes, example code would be nice.
Thank you.
PS: for those who don't know, this is only possible if the user has the Twitter.app installed.
The types that you can send to a service depends upon the types that the registered application has declared in its Info.plist. For Twitter.app, this looks like:
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Tweet</string>
</dict>
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
</array>
Unfortunately, this means that you will have to transform the image into a string before it will be accepted by the service.

Multi Value Setting (Settings.bundle) issue

I just can't get Multi Value settings to work in my Ipad app.
This is my plist code for the multi value:
<dict>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>DefaultValue</key>
<string>0</string>
<key>Values</key>
<array>
<string>0</string>
<string>1</string>
<string>2</string>
</array>
<key>Title</key>
<string>Project</string>
<key>Key</key>
<string>project</string>
</dict>
I already tried everything, reset the iPad simulator, added other settings... and multi values keep on not showing in the settings. Am i missing something?
Solved this by defining the array of "Titles". It won't show the setting without it.

How to define a Uniform Type Identifier in a plist file?

My application uses the following NSApplicationDelegate function.
- (void)application:(NSApplication*)sender openFiles:(NSArray*)filenames;
I want to use this function to enable the user to drag and drop image files onto the application icon in the dock.
How do I have to define certain file types in my plist file to restrict them to be images? I found out the structure has to look something like this.
// plist file contents taken from Preview.app
[...]
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFile</key>
<string>jpeg.icns</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSIsAppleDefaultForType</key>
<true/>
<key>LSItemContentTypes</key>
<array>
<string>public.jpeg</string>
</array>
<key>NSDocumentClass</key>
<string>PVDocument</string>
</dict>
</array>
I added it to the plist file but it does not work. A popup window shows the following error message.
The document "test.jpg" could not be opened. MyApp cannot open files
in the "JPEG image" format.
Further, I read in the documentation that there is public.image which would be what I want to define.
Meanwhile, I found out that the plist file only contains the key CFBundleDocumentTypes if I create a Cocoa Application with the option "Create document-based application.". Can you please clarify what dependencies exist for the option?
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>png</string>
<string>jpg</string>
... add as many types as you need
</array>
... other keys
</dict>
</array>
Update: The CFBundleDocumentTypes key is deprecated in Mac OS X v10.5. The new key LSItemContentTypes should be used instead. The items are UTI strings:
<key>LSItemContentTypes</key>
<array>
<string>public.png</string>
</array>
If your document types are common types, you could use UTI's
About UTI's

How do I make a file that identifies as a custom UTI type?

Right now I have an application that generates an XML file. We'll call it someFile.myapp
When my app saves the file and look at it using mdls it has a kMDItemContentType of "dyn.234kdfsjk23jk24234kjfd"
How can I get the UTI type of the file to be a custom value like com.mycompany.myapp?
UTIs are linked to extensions via a declaration in your application's Info.plist file. Add a section like so:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.xml</string>
</array>
<key>UTTypeDescription</key>
<string>My Special File Type</string>
<key>UTTypeIdentifier</key>
<string>org.myapp.someutiidentifier</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>myapp</string>
</array>
</dict>
</dict>
</array>
Dream up a unique extension for your file, and use an exported UTI declaration to associate the extension with your UTI.
Files are mapped to UTIs by Launch Services, which is theoretically able to use many different kinds of information about the file to identify its type, but in practice will disregard everything other than the file extension. Consequently, if you want your file's type to be identifiable, you need to come up with a unique extension and map it to the relevant type in your app's Info.plist. If your files need to share an extension that has already been claimed by another app, then you're SOL.
As far as I can see -- and I say this as a longtime Mac fan -- this is the one aspect of Mac OS X where it is really apt to say: "Welcome to 1985!"