Sacred Music – Deep Linking API
The sacredmusic:// URI scheme allows you to link into the Sacred Music app, in a similar way that a link with https:// opens into your default web browser. Linking to a specific location in an app (instead of to a web page) is called deep linking. Properly-formed sacredmusic:// links can be sent by email or posted on web pages. Here are some examples of URI schemes:
- https:// – links to a web page in your default browser. Example: https://www.singpraises.net/
- mailto: – creates a new message in your default email program. Example: mailto:samuel@singpraises.net
- fb:// – opens the Facebook app. Example: fb://notifications
- gospellibrary:// – opens the Gospel Library app. Example: gospellibrary://content/scriptures/bofm/1-ne/3?id=p7&lang=eng#p7
- sacredmusic:// – opens the Sacred Music app. Example: sacredmusic://content/manual/hymns/the-morning-breaks?lang=eng
In order for sacredmusic:// links to work, the Sacred Music app has to be installed on the target device (Android or iOS), and whatever app you're linking from has to recognize it as a link so it's clickable. Also, deep links might not work as expected if there is more than one version of the Sacred Music app installed at the same time (for example the released version and a beta version), because the device won't know which version of the app to open.
Historical note: Sacred Music was previously called “LDS Music.” LDS Music 1.0.1 for iOS introduced the ldsmusic:// scheme (basic linking to songs, for linking from Gospel Library). In 1.4.0 (iOS), linking for collections and playlists was added, and 1.8.0 (iOS) introduced linking using Gospel Library content URIs. The ldsmusic:// scheme was added to LDS Music for Android in version 1.1.0. In April/May 2019, when the app was renamed to Sacred Music, the sacredmusic:// URI scheme was introduced. The sacredmusic:// URI scheme is preferred, though ldsmusic:// is still supported.
Opening the app
Here are some basic links that allow you to open the app without going to specific content:
- sacredmusic:// – Open the app without going anywhere.
- sacredmusic://content – Open the app and go to the home screen.
- sacredmusic://content?lang=por – Open the app and go to the home screen, with Portuguese content. More information about the language parameter can be found further down, under “Optional parameters.”
Going to a specific collection or song
The best way to link to a collection or song in Sacred Music is using the collection and song URI. Since November 2016, this method works on both iOS and Android, and it follows the same pattern as Gospel Library.
The formula for a collection link is as follows:
sacredmusic://content + [collection URI] + ? + [optional parameters]
The formula for a song link is as follows:
sacredmusic://content + [collection URI] + / + [song URI] + ? + [optional parameters]
Here are some examples of links to specific collections or songs:
- sacredmusic://content/manual/hymns – Goes to the hymnbook.
- sacredmusic://content/manual/childrens-songbook – Goes to the Children’s Songbook.
- sacredmusic://content/manual/hymns/the-morning-breaks – Goes to “The Morning Breaks” in the hymnbook.
- sacredmusic://content/manual/childrens-songbook/i-am-a-child-of-god – Goes to “I Am a Child of God” in the Children’s Songbook.
While not required, it's a good idea to include a language parameter at the end if you want to link to a specific song in a specific language. If you don't specify a language, it will use the default language, which is the language of the device – which may cause an error if the song you want to link to doesn't exist in that language. Here are a few examples (more information about the language parameter can be found further down, under “Optional parameters”):
- sacredmusic://content/manual/hymns?lang=eng – Goes to the English hymnbook.
- sacredmusic://content/manual/hymns/called-to-serve?lang=fra – Goes to “Called to Serve” in the French hymnbook.
- sacredmusic://content/manual/childrens-songbook/i-am-a-child-of-god?lang=spa – Goes to “I Am a Child of God” in the Spanish Children’s Songbook.
Older versions of Sacred Music for iOS used "external IDs" to link to a collection or song, instead of collection and song URIs. While this method still works on iOS, it has been deprecated in favor of the URI system. A few examples are here for historical reference:
- (deprecated) sacredmusic://collection/Hymns-EN – Goes to the English hymnbook (we used a two-letter language code for the first four languages that were in the app: English, Spanish, French, and Portuguese; for later languages, we standardized with a three-letter code).
- (deprecated) sacredmusic://collection/Hymns-DEU – Goes to the German hymnbook.
- (deprecated) sacredmusic://item/Hymns-KOR-167 – Goes to “Hark, All Ye Nations!” (number 167) in the Korean hymnbook.
- (deprecated) sacredmusic://item/Childrens-FR-18a – Goes to “For Health and Strength” (page 18, song A) in the French Children’s Songbook.
Optional parameters
The language parameter, lang, allows you to specify the language of the content you want to link to. In general, three-letter ISO 639-3 language codes are used. An exception is Chinese: "zho" is used for Traditional Chinese, and "zhs" is used for Simplified Chinese. Here are some examples using the language parameter:
- sacredmusic://content?lang=ita – Goes to the home screen, with Italian content.
- sacredmusic://content/manual/hymns?lang=zho – Goes to the Traditional Chinese hymnbook.
- sacredmusic://content/manual/childrens-songbook/book-of-mormon-stories?lang=jpn – Goes to “Book of Mormon Stories” in the Japanese Children’s Songbook.
In Sacred Music for iOS, the parameters return_url and return_name were previously used to provide a return link to where you were before clicking the sacredmusic:// link. However, this feature was removed because iOS 9 and newer provide a built-in back link when you link from one app to another. In Android, the regular back button provides the same functionality. For historical reference, here are a few examples:
- (iOS only) sacredmusic://content/manual/hymns?return_url=http://www.singpraises.net/&return_name=SingPraises.net – Goes to the hymnbook in Sacred Music, and provides a link to return to SingPraises.net.
- (iOS only) sacredmusic://content/manual/hymns?return_url=gospellibrary://content/manual/hymns/the-morning-breaks&return_name=Gospel%20Library – Goes to “The Morning Breaks” in Sacred Music, and provides a link to return to the Gospel Library app.
Creating a playlist (iOS only)
You can use the sacredmusic:// URI scheme to share or back up a playlist from Sacred Music for iOS. The easiest way to generate a playlist link is to create the playlist in Sacred Music, then use the Share options to share the link with yourself. Because playlists don't sync, it's a good idea to share important playlists with yourself before updating or reinstalling the app, in case you need to recreate them. Playlist links use song external IDs. Here are a few examples:
- (iOS only) sacredmusic://playlists/add?playlist_name=test%20playlist – Creates a new, blank playlist called "test playlist".
- (iOS only) sacredmusic://playlists/add?playlist_name=another%20playlist&item1=Hymns-EN-1&item2=Childrens-PT-4&item3=Hymns-FR-45&item4=Childrens-FR-4 – Creates a new playlist called "another playlist" and adds four specific songs to the playlist.
JavaScript for linking from a web page
While deep links are useful in a mobile context, they become much less useful on devices where Sacred Music isn't installed or supported. While it's difficult to detect if an app is installed on a user's device, it is relatively simple to detect if a user is using iOS or Android, and adapt accordingly.
If your app or web page has deep links into Sacred Music, be sure to invite your users to download the Sacred Music app, and provide an alternative experience for users who aren't using Android or iOS. Here are some examples of HTML links that work on Android or iOS, with varying experiences on a desktop computer:
- Example 1: Standard link that doesn't work on a desktop computer: sacredmusic://content/manual/hymns/the-morning-breaks?lang=eng
- Example 2: Link that uses JavaScript to provide a popup on a desktop computer: sacredmusic://content/manual/hymns/the-morning-breaks?lang=eng
- Example 3: Link that uses JavaScript to redirect to the Church website on a desktop computer: sacredmusic://content/manual/hymns/the-morning-breaks?lang=eng
Unfortunately, not all websites and apps recognize custom URI schemes like sacredmusic://. For example, if you try to share a sacredmusic:// link on Facebook, it won't recognize it as a tappable link. Similarly, if you try to embed a sacredmusic:// link in a PDF, only some PDF readers will open the link as expected. To work around this, you can use a link that starts with https:// and redirects you to the app. Here are some examples: