0% found this document useful (0 votes)
2 views

Allowing Apps and Websites to Link to Your Content Apple Developer Documentation

The document explains how to use universal links to connect directly to content within an app, allowing users to open the app without routing through a browser. It outlines the steps to support universal links, including creating a two-way association between the app and website and updating the app delegate. Additionally, it describes how apps can communicate through universal links, enabling data transfer without third-party servers.

Uploaded by

j7yzksvtnn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Allowing Apps and Websites to Link to Your Content Apple Developer Documentation

The document explains how to use universal links to connect directly to content within an app, allowing users to open the app without routing through a browser. It outlines the steps to support universal links, including creating a two-way association between the app and website and updating the app delegate. Additionally, it describes how apps can communicate through universal links, enabling data transfer without third-party servers.

Uploaded by

j7yzksvtnn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Documentation

Xcode /

Allowing apps and


websites to link to your
content
Use universal links to link directly to
content within your app and share
data securely.

Overview
You can connect to content deep inside your
app with universal links. Users open your app
in a specified context, allowing them to
accomplish their goals efficiently.

When users tap or click a universal link, the


system redirects the link directly to your app
without routing through Safari or your
website. In addition, because universal links
are standard HTTP or HTTPS links, one URL
works for both your website and your app. If
the user has not installed your app, the
system opens the URL in Safari, allowing your
website to handle it.

When users install your app, the system


checks a file stored on your web server to
verify that your website allows your app to
open URLs on its behalf. Only you can store
this file on your server, securing the
association of your website and your app.

Support universal links


Take the following steps to support universal
links:

P. Create a two-way association between


your app and your website and specify the
URLs that your app handles, as described
in Supporting associated domains.

R. Update your app delegate to respond to


the user activity object the system
provides when a universal link routes to
your app, as described in Supporting
universal links in your app.

With universal links, users open your app


when they click links to your website within
Safari and WKWebView, and when they click
links that result in a call to:

open(_:options:completion
Handler:) in iOS and tvOS

openSystemURL(_:) in watchOS

open(_:withApplicationAt:
configuration:completion
Handler:) in macOS

openURL in SwiftUI

Note
If your app uses one of the above
methods to open a universal link to your
website, the link wonʼt open in your app.

When a user browses your website in Safari


and taps a universal link in the same domain,
the system opens that link in Safari,
respecting the userʼs most likely intent to
continue within the browser. If the user taps a
universal link in a different domain, the
system opens the link in your app.

Communicate with other apps


Apps can communicate through universal
links. Supporting universal links allows other
apps to send small amounts of data directly
to your app without using a third-party
server.

Define the parameters that your app handles


within the URL query string. The following
example code for a photo library app
specifies parameters that include the name of
an album and the index of a photo to display.

https://myphotoapp.example.com/albums?alb
https://myphotoapp.example.com/albums?alb

Other apps craft URLs based on your domain,


path, and parameters and ask your app to
open them by calling:

The open(_:options:completion
Handler:) method of UIApplication
in iOS and tvOS

The openSystemURL(_:) method of


WKExtension in watchOS

The open(_:withApplicationAt:
configuration:completion
Handler:) method of NSWorkspace in
macOS

The openURL environment value in SwiftUI

The calling app can ask the system to inform


it when your app opens the URL.

In this example code, an app calls your


universal link in iOS and tvOS:

if let appURL = URL(string: "https://myph


UIApplication.shared.open(appURL) { s
if success {
print("The URL was delivered
} else {
print("The URL failed to open
}
}
} else {
print("Invalid URL specified.")
}

In this example code, an app calls your


universal link in watchOS:

if let appURL = URL(string: "https://myph


WKExtension.shared().openSystemURL(ap
} else {
print("Invalid URL specified.")
}

In this example code, an app calls your


universal link in macOS:

if let appURL = URL(string: "https://myph


let configuration = NSWorkspace.OpenC
NSWorkspace.shared.open(appURL, confi
guard error == nil else {
print("The URL failed to open
return
}
print("The URL was delivered succ
}
} else {
print("Invalid URL specified.")
}

For more information on handling links within


your app, see Supporting universal links in
your app.

Topics

Universal links

Supporting universal links in your app


Prepare your app to respond to an
incoming universal link.

Associated domains

Supporting associated domains


Connect your app and a website to
provide both a native app and a browser
experience.

Custom URLs

Defining a custom URL scheme for your


app
Use specially formatted URLs to link to
content within your app.

Default apps

Preparing your app to be the default web


browser
Configure your browser app so users
can set it as the default on their device
instead of Safari.

Developer Documentation

Platforms +

Tools +

Topics & Technologies +

Resources +

Support +

Account +

Programs +

Events +

To submit feedback on documentation,


visit Feedback Assistant. Light Dark Auto

Copyright © 2024 Apple Inc. All rights reserved.

Terms of Use Privacy Policy Agreements and Guidelines

You might also like