quave:universal-links

v1.0.0Published 4 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

quave:universal-links

quave:universal-links is a Meteor package that allows you to expose your native iOS settings to enable Universal Links.

Why

It is very useful to lunch your app from a link and this package make this configuration a breeze.

Remember that you need to enable Associated Domains in your app and also configure Universal Links in your mobile-config.js.

We believe we are not reinventing the wheel in this package but what we are doing is like putting together the wheels in the vehicle :).

Installation

meteor add quave:universal-links

Usage

In your settings

1  "packages": {
2    "quave:universal-links": {
3      "appleTeamId": "VR7QCJTCL2",
4      "appleBundleId": "com.yoursite.app"
5    }
6  }

In your server

1import { registerUniversalLinksHandler } from 'meteor/quave:universal-links';
2
3Meteor.startup(() => {
4  registerUniversalLinksHandler();
5});

That is it, now you can access http://localhost:3000/apple-app-site-association and you will get back Apple required configuration for Universal Links.

Advanced

If you want to provide appleTeamId and appleBundleId in runtime (in case you serve multiple apps from the same backend) you can use createResponderAppleAppSiteAssociation function. See a full example from a market place that each store can have a native app.

1import { createResponderAppleAppSiteAssociation } from 'meteor/quave:universal-links';
2
3import { StoresCollection } from '../../app/stores/data/StoresCollection';
4import { getNativeStoresInfo } from './native';
5import { getBaseUrlFromHeaders } from '../mode/modeCommon';
6
7export const appleAppSiteAssociation = (req, res) => {
8  const baseUrl = getBaseUrlFromHeaders(req.headers);
9  const store = StoresCollection.findByFullUrl(baseUrl);
10  const nativeStoresInfo = getNativeStoresInfo(store);
11
12  if (!nativeStoresInfo.nativeAppEnabled) {
13    res.setHeader('Content-Type', 'text/html');
14    res.writeHead(405);
15    res.end(`<h1>Native App not enabled for ${store.name}</h1>`);
16    return;
17  }
18  if (!nativeStoresInfo.appleTeamId || !nativeStoresInfo.appleBundleId) {
19    res.setHeader('Content-Type', 'text/html');
20    res.writeHead(405);
21    res.end(
22      `<h1>Bundle ID and Team ID are not configured for ${store.name}</h1>`
23    );
24    return;
25  }
26
27  createResponderAppleAppSiteAssociation(nativeStoresInfo)(req, res);
28};

License

MIT