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.
Related
I'm using custom scheme and am testing
on my iPhone6, iOS Simulator
which is running iOS 15
the app works fine when I launch it from https (Universal Link)
but when I try to launch it using Custom URL scheme it crashes instantly, dosent reach the main function ether.
Am sure you'll need to register your schemes here if I answered your question;
I have some examples below.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
<string>http</string>
<string>mailto</string>
<string>tel</string>
<string>facetime</string>
<string>sms</string>
</array>
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>
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
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.
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.