You might think it's a duplicate question, but it's not, I'm totally aware of all the answers on SO about the canOpenURL and its caveats on iOS 9, but here is my problem:
I'm trying to check if an specific app is installed on my device (both developed by me).
I have declared the scheme on AppA as:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.my.company.id</string>
<key>CFBundleURLSchemes</key>
<array>
<string>XYZ</string>
</array>
</dict>
</array>
and on the other app, AppB I have added in info.plist:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>XYZ</string>
</array>
Now, in AppB I'm trying to find out if I have AppA installed like this:
internal static let appAScheme = "XYZ://"
static func AppAInstalled() -> Bool {
let appAURL = NSURL(string: appAScheme)
return UIApplication.sharedApplication().canOpenURL(appAURL!)
}
It always returns
-canOpenURL: failed for URL: "XYZ://" - error: "This app is not
allowed to query for scheme XYZ"
How ever, If I try to open AppA from AppB it'll work with no problem!
// Works alright
UIApplication.sharedApplication().openURL(appAURL!)
I can't figure it out why!
I have found the solution to my own question. I'm answering it here instead of just deleting my question because it might help somebody someday.
The problem here was that I'm trying to develop a framework for other developers, I have a test app that I'm using to check if everything is fine with my framework. I was setting LSApplicationQueriesSchemes values inside the framework target, not the actual test app. SO:
You need to set the whitelist values in your app target's info.plist
Related
Recently i updated my phone to iOS 14 and since then netServiceBrowser.searchForServices(ofType:"xyz._tcp", inDomain: "local.") not working at all. iPhone is not able to discover any services and not calling any NetServiceBrowserDelegate methods.
Your app requires access to the local network, and iOS14 has a new privacy option that requires authorization for this.
You have to add NSLocalNetworkUsageDescription to your Info.plist, see apple docs
If you use Bonjour, you need to déclare it in info.plist too...
<key>NSBonjourServices</key>
<array>
<string>_http._tcp</string>
</array>
here is my solutions that work for me well
<key>NSLocalNetworkUsageDescription</key>
<string>Allow Flutter tools on your computer to connect and debug app</string>
<key>NSBonjourServices</key>
<array>
<string>_dartobservatory._tcp</string>
</array>
For a Mac OSX application I am developing, I want to use an URL scheme, so I set up the scheme like this:
NSAppleEventManager.shared().setEventHandler(
self,
andSelector: #selector(handleUrlEvent(_:with:)),
forEventClass: AEEventClass(kInternetEventClass),
andEventID: AEEventID(kAEGetURL))
And I have a handler registered like this:
#objc
func handleUrlEvent(_ event: NSAppleEventDescriptor, with replyEvent: NSAppleEventDescriptor) {
log.verbose("handleUrlEvent")
}
My URL scheme is registered in my Info.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>Look for photo</string>
<key>CFBundleURLSchemes</key>
<array>
<string>gisync</string>
</array>
</dict>
</array>
The problem is, when I run my application using Xcode, the URL scheme is not registered and the application does not get the events I need.
When I archive and start my application from there, the scheme IS registered and the application gets the notifications. So then it works correctly, but I lose debugging capabilities.
EDIT: The release build does work somehow, so this seems to be different for release and debug.
Try explicitly registering the app with the Launch Services:
LSRegisterURL
This function adds the designated application and its document and URL claims (if any) to the Launch Services database, making the application a candidate for document and URL binding.
I’d do it in the applicationDidFinishLaunching and use conditional compilation to only do this in the DEBUG version.
Also version number of an app bundle has effect:
Preferred Application for a URL
If two or more versions of the same application have been found, give preference to the one with the latest version number.
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.
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.
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.