0

I’ve got several iOS apps and I need them to be aware of each other. More precisely, I need to know whether there’s already one of my apps installed.

I thought about registering a custom URL scheme (something like my-app-present://), so that I could check whether the custom scheme is supported and if yes, I would know there’s already one of my apps on the device. But that doesn’t work, because the schemes are registered through Info.plist and the app registers the scheme before it has a chance to check for its existence. In other words, the check always succeeds.

Then I thought about creating a file in the temporary directory, but NSTemporaryDirectory() returns a folder inside the application sandbox, so that wouldn’t work either. I also thought about keychain, but again it looks like each application has strictly separate keychain on iOS.

I don’t want to go through the list of running apps and I don’t want to use networking. Do you know some other tricks?

zoul
  • 102,279
  • 44
  • 260
  • 354
  • 4
    Actually many your application may use same keychain, but only if they have sam **Bundle Seed ID** which you gave to them in **iOS Provisioning Portal** when create new **App ID**. This is just P.S., because you already have solution for your problem from @jtbandes. – Serhii Mamontov Aug 15 '11 at 07:49

2 Answers2

2

The custom URL scheme method sounds fine, as long as you have a different scheme for every app, for example my-app-1:// and my-app-2://. Then (I assume this is what you already knew) you can use canOpenURL: to check if the URL can be handled (i.e., your app is installed).

jtbandes
  • 115,675
  • 35
  • 233
  • 266
  • This is actually what most apps do, who require this interoperability. – Benjamin Mayo Aug 15 '11 at 07:24
  • Thank you (+1). I thought about this, but I’m already kind of embarrassed for misusing one URL scheme, let alone several of them. But what’s worse is that I would have to update the logic in all apps whenever I release a new one, right? – zoul Aug 15 '11 at 07:38
  • Yes, if all your apps need to know about *all* your other apps. If that's the case, perhaps you could store all your URL schemes on a server and load them dynamically? – jtbandes Aug 15 '11 at 07:39
  • Unfortunately yes, all my apps need to know if they’re first on the device. The app list stored on the server would work, but it’s already quite overkill for what I’m trying to do. – zoul Aug 15 '11 at 07:41
  • What are you trying to do? That's always useful information to include when asking a question. – jtbandes Aug 15 '11 at 07:44
  • I’ve never thought I’d say that, but I don’t think I’m supposed to talk about it :-) Sorry. The gist is what I have written in the previous comment: Our apps need to know if they’re the first on the device. – zoul Aug 15 '11 at 07:50
  • OK, fair enough — then I think this is the best solution (using a server). Apps can also [share a keychain](http://stackoverflow.com/questions/4115744/how-to-share-keychain-data-between-ios-applications) but that would be a bad solution here, please don't do it! :) – jtbandes Aug 15 '11 at 07:53
  • I’ll go with this, as I can’t find any better solution. I will use a number suffix for the URL scheme (`app-1`, `app-2`, …) so that I can check for my other apps without carrying a definitive list with each app. It’s a shameful hack, but what can I do. Thank you! – zoul Aug 15 '11 at 12:18
0

If by "talk to each other" you meant you just want to detect whether other app has been installed or not then iHasApp is an open source iOS framework could come in handy. I haven't used it yet. but from the description it appears to be a good choice.

http://www.ihasapp.com/documentation/Classes/iHasApp.html

Obj-Swift
  • 2,802
  • 3
  • 29
  • 50