ios mail app does not open vcard in my app - iphone

I would like to import vCards into my iOS app using the mail app. I have added public.vcard to my projects plist. If I try to open the vcard in another app using the UIDocumentInteractionController everything works as expected. However if I try to open the vCard in the mail app, the vCard is opened in the mail with no choice for my app. Is there a solution?
UPDATE:
The plist entry for the vcard looks like
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>vCard</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>LSItemContentTypes</key>
<array>
<string>public.vcard</string>
</array>
</dict>
</array>

This entry looks rather incomplete to me. Generally if yor application is able to open certain types you need to have either an import declaration (if the file format is owned by another application) or an export declaration (if the format is owned by your)
iOS and Mac are matching UTIs mostly by extension, so I guess you also need to have that in the declaration. Check with the UTI functions on iOS is there is indeed the public.vCard type assigned to your file's extension. If not, then it cannot be found.
I would add an UTImportedTypeDeclarations to your plist if there is such an association, if not add an UTExportedTypeDeclarations
I wrote this tutorial to explain all the things you need: http://www.cocoanetics.com/2012/09/fun-with-uti/

This seems to be impossible as of iOS 7.0.4.
iOS seems to handle some file types within the Mail app differently than others. Within the Mail app you won't get the option to open those file types in apps that are not from Apple.
You can verify this by using the UIDocumentInteractionController to open a file programmatically. This will prompt the user to open the file in a lot of apps (in all apps that registered this file type or a more general one. The Dropbox app e.g. almost opens everything).
When you mail yourself the exact same file and try to open it within the Mail app you'll not get those options (like Dropbox).
I verified this by registering VCard/.vcf, Jpegs and a custom type.

Related

Sandbox entitlement to script iTunes via NSAppleScript

I'm trying to script iTunes from NSAppleScript in my Cocoa app in order to add a file to the library.
In my entitlements file, I added the following:
<key>com.apple.security.scripting-targets</key>
<dict>
<key>com.apple.itunes</key>
<array>
<string>com.apple.itunes.library.read-write</string>
</array>
</dict>
I then call the AppleScript like this:
var error: NSDictionary? = nil
let appleScript = NSAppleScript(source: "tell application \"iTunes\" to add (POSIX file \"\(path)\") to library playlist 1")
let result = appleScript?.executeAndReturnError(&error)
but it fails with an error -10004: iTunes got an error: A privilege violation occurred.
I tried capitalizing iTunes both ways (itunes and iTunes) but nothing seems to work. I also tried adding, on top of the read-write entitlement, the read entitlement. Finally, I tried adding read and write access to the user's Music folder (where the iTunes library is stored) and this didn't help either.
Is there another required entitlement that I'm not aware of in order to script iTunes?
I found this link in my search for a solution (link) but it requires the user to select a specific folder in his Library folder to give the application user-selected file access and then it requires the script to be in a separate file which is 2 things too many for what I want to do. I don't trust the user regarding the management of the script files and I don't need a file for 1 line of AppleScript code. Another disadvantage, as I understand NSUserAppleScriptTask is that you can't persist a script's state across multiple calls, which is not a problem in my case but could be for someone else.
Thanks
After contacting the Developer Technical Support of Apple, I was able to solve this problem, which is actually 2 problems in one.
First, the entitlements need to have the bundle identifiers properly cased. For iTunes, the entitlements must be like this (note the capital T in iTunes):
<key>com.apple.security.scripting-targets</key>
<dict>
<key>com.apple.iTunes</key>
<array>
<string>com.apple.iTunes.library.read-write</string>
</array>
</dict>
Then, the privilege violation will occur unless the AppleScript code includes of source 1 at the end like this :
tell application "iTunes" to add (POSIX file "your/path/to/mp3.mp3") to library playlist 1 of source 1
There you go!

getting error in DropBox integration to the iphone app

I am trying to integrate the DropBox to my iPhone app. But I get error like
[ERROR] DropboxSDK: unable to link; app isn't registered for correct URL scheme (db-xpt9oxj57x9ftci)
Can anyone help me to solve this?
Most of the time that problem is caused by a misconfigured Info.plist file. Can you make sure you've followed the documentation/index.html about changing Info.plist file? In info plist set db-key in urltype (urlschema). That should do the trick.
I googled and the Dropbox sdk has the line specifically to add the the app key in your app plist file
Your app key is also needed in DBRoulette-Info.plist file so the app
can register for the correct url scheme. To do this, find the file
under the Resources group in the left pane, right-click it and select
Open As → Source Code. Replace the text APP_KEY with your app's key
https://www.dropbox.com/developers/start/setup#ios
I found this solution.
I am working with Xamarin in Windows Visual Studio 2015, and as presented in other queries online, there is no "URL scheme" option available. So the solution is to modify info.plist by hand. Your dropbox specific plist scheme should look like this:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>dbapi-2</string>
<string>dbapi-8-emm</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>db-APP_KEY</string>
</array>
</dict>
</array>
A great helper for me to get this information was the "info.plist" for this. This "info" modification should work for any xamarin project.
If you fix any typos or forget the "db" and are still having problems, clean & rebuild may help.
Your URL scheme should be db-<Your App key>. Example db-a7ghdtthegj6z1g
I had this issue just now and was done in by a space before the db- prefix. Hard to see in the plist editor, but very obvious when I looked at the XML.

How to associate iPhone application with _every_ file type?

There is iPhone app "Another Mail Client" that should be able to open any file to send it as attachment. So, I want to associate this application with any file with any extension.
Following the documentation, we should declare support for files with the root UTI-type public.data – any file should belong to this type. It works, but not at all. In this case, our app will not be able to open any file, but only those which have already been registered in the system. For example, if in any application (e.g., dropbox) we'll try to "open in..." file with an unknown extension (file.unknowntype) using UIDocumentInteractionController, then the answer will be negative despite the fact that we have already registered our application and it supports the root UTI-type public.data. But, if you install another application, which supports files with extension (*.unknowntype), then our application will also be able to open these files and will appear in "open in..." application list.
UPD: #Gabriel This is CFBundleDocumentTypes part of my info.plist file:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>MyMail</string>
<key>LSItemContentTypes</key>
<array>
<string>public.data</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>CFBundleTypeIconFiles</key>
<array>
<string>Icon29.png</string>
...
<string>Icon114.png</string>
</array>
</dict>
</array>
I've made an app with the following setup
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>name</string>
<key>LSItemContentTypes</key>
<array>
<string>public.data</string>
</array>
</dict>
</array>
When I try to open a .pdf from Safari, this app shows up in "open in.." list. Can you make a sample app and try it?
UPD:
It seems like claim 'public.data' (tried also public.item, public.content) means file, which belongs to set "all known to system UTIs", not any file. So, you will be able to handle 99% of files, which users want to send by email , but not all. Another way would be to export UTI that you think are important, but which are not in system UTIs by default.
Friend, I read your question properly before posting the answer. I gave another thought that you will have a set of already known "any types" of files to register in a bulk. However, you want to dynamically accommodate your app to register any file type given to your app in future and make it attachable. For this as far as my knowledge is concerned, you cannot make you app to universally support any unknown file type. Let me explain what happens,
Suppose you make an application APP1 then it does not know about a file extension .XYZ and install it on iPhone.
But, later I develop another application APP2, which contains the above code and I register the .XYZ type from APP2 in whatever iPhone it installs.
So, lets say I install APP2 in your iPhone, having APP1. And when my app runs, then the .XYZ extension ( known to APP2 ahead of time) gets registered into the iPhone.
This is the reason now your app APP1 can use this .XYZ file surprisingly.
Concluding, you have to know a specific type of extensions ahead of time before making the app.
However, heres a possible solution for it.
Solution :
Decide the maximum number of characters you want to support in an extenstion. Lets say 4.
Now you can make a small Brute-Force routine to run in your app to make all the possible character combinations and register them all. This should make any file with extension upto 4 characters attachable to mail.
I hope that should do the trick.
Best of luck!
An idea for investigation...
If the installation of another app "fixes" the problem then try inspecting the other apps Info.plist file to see if it is registering or exporting any interesting UTIs or similar settings.
It sounds like your app might only be doing half the job and the other app is completing the missing setup.
You can inspect the contents of an apps ipa file from iTunes by copying it, renaming ipa to zip extracting the contents and then Show Package Contents on the app inside.

Add a file association with tiff files on iOS

I'd like to create a file associate with tiff files in my iOS app (i.e. so that my app appears as a target for opening tiff files from Mail or Safari). Adding the following to my Info.plist file doesn't seem to work:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>tiff</string>
<key>LSItemContentTypes</key>
<array>
<string>public.tiff</string>
</array>
<key>LSHandlerRank</key>
<string>Alternate</string>
</dict>
</array>
I have an app that I associate with PDFs in the same way and it works fine. I believe that it is not possible to associate an app with the tiff file type on iOS, but I can't find any documentation stating that.
Has anyone else had luck getting this to work or finding a definitive "no, you can't do that"?
I burned an Apple TSI on this (I never seem to end up using them anyway) and the official answer is: no, you can't do that.
I've logged an enhancement request on Apple's bug reporting site: http://developer.apple.com/bugreporter/ and I suggest you do too if this issue is a problem for you.
Acorn declares file associations for TIFFs, which seems to work fine.
The only differences I could see between Acorn's implementation and yours is that Gus omits CFBundleTypeName and adds LSIsAppleDefaultForType (set to true). You might want to give that a try.
LSIsAppleDefaultForType is undocumented. There's a reference to it here: http://lists.apple.com/archives/cocoa-dev/2006/Jun/msg00747.html
An general note - the Mail and Safari apps indeed does not allow you to "open with .." tiff files (still true in iOS8);
Nevertheless, a lot of other apps, such as Dropbox, GDrive, etc, does allow you to do that.

How to add mp3 support with CFBundleTypeName

In applications like PDF Reader Lite, it's possible to associate PDF type with the app in such a way, when a PDF file will be opened in an app like Safari or Email, it will show an option to open the file in PDF Reader Lite app too.
Is it possible to implement similar thing for mp3? I have tried to add below tags in Info.plist file in below way.
<array>
<dict>
<key>CFBundleTypeName</key>
<string>MPG3</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.mp3</string>
</array>
</dict>
</array>
But when I open an mp3 URL (a URL having an extension .mp3 at end like this - http://sound18.mp3pk.com/indian/7khoonmaaf/7khoonmaaf01(www.songs.pk).mp3 it doesn't display the option to open the file in my app.
Will anyone please help me out for this?
Thanks,
It actually works if you set this dict to the CFBundleDocumentTypes key.
You can test if it works by sending a mail with a mp3 file to your iPhone or iPad. Hold down on the attachment and the UIDocumentInteractionController-View will pop up. Other applications can also use the UIDocumentInteractionController (see SDK documentation) to allow opening files with another app.
However, Mobile Safari doesn't do that for all media types. So it won't work when you open the URL directly.
An alternative would be to register an URL scheme for your app (CFBundleURLTypes), then you could pass the URL-String to the app through that custom URL scheme (myapp://www.example.com/file.mp3).