Skip to content

Commit d1f3876

Browse files
liutingduclaude
andauthored
Add deep link support to Example app and update README (#350)
- Register `intercom-sample://secondscreen` URL scheme for Android (intent-filter) and iOS (CFBundleURLTypes) in config.xml - Add deep link handling JS with second screen navigation in the Example app - Add deep linking documentation link to README Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d1a2ddb commit d1f3876

5 files changed

Lines changed: 58 additions & 2 deletions

File tree

Example/config.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
<activity android:exported="true" />
2626
</edit-config>
2727
<preference name="AndroidXEnabled" value="true" />
28+
<config-file target="AndroidManifest.xml" parent="/manifest/application/activity[@android:name='MainActivity']">
29+
<intent-filter>
30+
<action android:name="android.intent.action.VIEW" />
31+
<category android:name="android.intent.category.DEFAULT" />
32+
<category android:name="android.intent.category.BROWSABLE" />
33+
<data android:scheme="intercom-sample" android:host="secondscreen" />
34+
</intent-filter>
35+
</config-file>
2836
<icon density="hdpi" src="www/img/android/hdpi.png" />
2937
<icon density="mdpi" src="www/img/android/mdpi.png" />
3038
<icon density="xhdpi" src="www/img/android/xhdpi.png" />
@@ -34,6 +42,18 @@
3442
<platform name="ios">
3543
<allow-intent href="itms:*" />
3644
<allow-intent href="itms-apps:*" />
45+
<config-file target="*-Info.plist" parent="CFBundleURLTypes">
46+
<array>
47+
<dict>
48+
<key>CFBundleURLSchemes</key>
49+
<array>
50+
<string>intercom-sample</string>
51+
</array>
52+
<key>CFBundleURLName</key>
53+
<string>io.intercom.cordova.sample</string>
54+
</dict>
55+
</array>
56+
</config-file>
3757
<preference name="deployment-target" value="15.0" />
3858
<preference name="BackupWebStorage" value="local" />
3959
<icon height="29" src="www/img/icon-29.png" width="29" />

Example/www/css/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ body {
3030
height:100%;
3131
margin:0px;
3232
padding:0px;
33-
text-transform:uppercase;
33+
text-transform:none;
3434
width:100%;
3535
overflow: scroll;
3636
}

Example/www/index.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
</head>
99

1010
<body>
11-
<div class="app">
11+
<div id="second-screen" style="display:none; text-align:center; padding:40px;">
12+
<h1>Second Screen</h1>
13+
<p id="deep-link-url"></p>
14+
<p><button id="back-btn">Back</button></p>
15+
</div>
16+
<div id="home-screen" class="app">
1217
<img class="logo" src="img/Intercom-logo.png" width="112" height="99"/>
1318

1419
<p><button id="login-btn">Login</button></p>
@@ -27,6 +32,7 @@
2732
<p><button id="is-user-logged-in-btn">Check if user is logged in</button></p>
2833
<p><button id="fetch-logged-in-attributes-btn">Fetch logged in user attribtues</button></p>
2934
</div>
35+
</div>
3036
<script type="text/javascript" src="cordova.js"></script>
3137
<script type="text/javascript" src="js/index.js"></script>
3238
</body>

Example/www/js/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19+
// Deep link handler for Cordova (called by the system when a URL opens the app)
20+
function handleOpenURL(url) {
21+
app.handleDeepLink(url);
22+
}
23+
1924
var app = {
2025
// Application Constructor
2126
initialize: function() {
@@ -145,6 +150,30 @@ var app = {
145150
}
146151
intercom.fetchLoggedInUserAttributes(onSuccess, onError);
147152
}, false);
153+
154+
document.getElementById("back-btn").addEventListener("click", function(){
155+
app.showHomeScreen();
156+
}, false);
157+
},
158+
159+
handleDeepLink: function(url) {
160+
console.log('Deep link received: ' + url);
161+
if (url && url.indexOf('intercom-sample://secondscreen') === 0) {
162+
app.showSecondScreen(url);
163+
} else {
164+
alert('Deep link received: ' + url);
165+
}
166+
},
167+
168+
showSecondScreen: function(url) {
169+
document.getElementById('home-screen').style.display = 'none';
170+
document.getElementById('second-screen').style.display = 'block';
171+
document.getElementById('deep-link-url').textContent = 'opened via: ' + url;
172+
},
173+
174+
showHomeScreen: function() {
175+
document.getElementById('second-screen').style.display = 'none';
176+
document.getElementById('home-screen').style.display = 'block';
148177
},
149178
// Update DOM on a Received Event
150179
receivedEvent: function(id) {

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ An example app is provided [here](https://github.com/intercom/intercom-cordova/t
6666
* Our [installation guide]((https://developers.intercom.com/installing-intercom/cordova-phonegap/installation/)) contains full setup and initialisation instructions.
6767
* The [configuration guide](https://developers.intercom.com/installing-intercom/cordova-phonegap/configuration/) provides info on how to configure Intercom for Cordova/Phonegap.
6868
* Read our guide on [Push Notifications](https://developers.intercom.com/installing-intercom/cordova-phonegap/push-notifications/) support.
69+
* Learn how to handle [Deep Linking](https://developers.intercom.com/installing-intercom/cordova-phonegap/deep-linking) in your Cordova app.
6970
* Please contact us on [Intercom](https://www.intercom.com/) with any questions you may have, we're only a message away!
7071

7172

0 commit comments

Comments
 (0)