Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch custom app with URL by domain

Even though the YouTube app is now not a built-in app by Apple, it looks like when tapping a youtube link (in mail, for example), which starts with http://www.youtube.com, opens the YouTube app right away.

Is there a way to this for custom apps in iOS 6? I only know of custom schemes as the way to launch an app via URL.

like image 447
Danra Avatar asked Sep 20 '12 19:09

Danra


2 Answers

I'm not sure I understand your question, but here is my attempt at an answer. You ask if there is a way to open third party apps from within another app. The answer is you can if the app has implemented a custom URL scheme (see here and navigate to the Communicating With Other Apps section).

But you also seem to say that you already know about this. In which case, I'm pretty sure there is no other way.

like image 55
Darren Avatar answered Oct 04 '22 16:10

Darren


To register a URL type for your app

Include the CFBundleURLTypes key in your app’s Info.plist file. The CFBundleURLTypes key contains an array of dictionaries, each of which defines a URL scheme the app supports.

Keys and values of the CFBundleURLTypes property

Call the URL (registered as above)

NSURL *myURL = [NSURL URLWithString:@"todolist://www.acme.com?Quarterly%20Report#200806231300"];
[[UIApplication sharedApplication] openURL:myURL];

Handle Calls to Custom URL Schemes

An app that has its own custom URL scheme must be able to handle URLs passed to it. All URLs are passed to your app delegate, either at launch time or while your app is running or in the background. To handle incoming URLs, your delegate should implement the following methods:

Use the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods to retrieve information about the URL and decide whether you want to open it. If either method returns NO, your app’s URL handling code is not called. In iOS 4.2 and later, use the application:openURL:sourceApplication:annotation: method to open the file. In iOS 4.1 and earlier, use the application:handleOpenURL: method to open the file. If your app is not running when a URL request arrives, it is launched and moved to the foreground so that it can open the URL. The implementation of your application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: method should retrieve the URL from its options dictionary and determine whether the app can open it. If it can, return YES and let your application:openURL:sourceApplication:annotation: (or application:handleOpenURL:) method handle the actual opening of the URL. (If you implement both methods, both must return YES before the URL can be opened.)

If your app is running but is in the background or suspended when a URL request arrives, it is moved to the foreground to open the URL. Shortly thereafter, the system calls the delegate’s application:openURL:sourceApplication:annotation: to check the URL and open it. If your delegate does not implement this method (or the current system version is iOS 4.1 or earlier), the system calls your delegate’s application:handleOpenURL: method instead.

Note

If two or more applications have registered the same Custom URL, there is no guarentee of which application the iOS will open if the Custom URL is called.

Further Reading

iOS App Programming Guide :: Advanced Tips and Trics

like image 31
SashaZd Avatar answered Oct 04 '22 16:10

SashaZd