Skip to content

Commit

Permalink
Merge pull request #70 from harshabonthu/master
Browse files Browse the repository at this point in the history
Refactor prefix based hooks and branch test env support
  • Loading branch information
aaustin committed Mar 12, 2016
2 parents 6169c2b + b339b38 commit 4868ccf
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 437 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,11 @@ In iOS 9.2, Apple dropped support for URI scheme redirects. You must enable Univ
Add the following entry to your application's `config.xml`:

```xml
<universal-links>
<branch-config>
<ios-team-id value="your_ios_team_id" />
<host name="bnc.lt" scheme="https">
<path prefix="/your_encoded_id" />
<!--optional test ENV encoded id-->
<path prefix="/your_encoded_id" />
</host>
</universal-links>
<android-prefix value="/X9Ug" />
<host name="bnc.lt" scheme="https" />
</branch-config>
```

You can get your iOS Team ID from the Apple Developer Portal. Once done, you have successfully enabled universal links for iOS.
Expand Down
11 changes: 3 additions & 8 deletions hooks/afterPrepareHook.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/**
Hook is executed at the end of the 'prepare' stage. Usually, when you call 'cordova build'.
It will inject required preferences in the platform-specific projects, based on <universal-links>
It will inject required preferences in the platform-specific projects, based on <branch-config>
data you have specified in the projects config.xml file.
*/

var configParser = require('./lib/configXmlParser.js'),
androidManifestWriter = require('./lib/android/manifestWriter.js'),
// androidWebHook = require('./lib/android/webSiteHook.js'),
iosProjectEntitlements = require('./lib/ios/projectEntitlements.js'),
// iosAppSiteAssociationFile = require('./lib/ios/appleAppSiteAssociationFile.js'),
iosProjectPreferences = require('./lib/ios/xcodePreferences.js'),
ANDROID = 'android',
IOS = 'ios';
Expand Down Expand Up @@ -58,21 +57,19 @@ function run(cordovaContext) {
* Activate Deep Links for Android application.
*
* @param {Object} cordovaContext - cordova context object
* @param {Object} pluginPreferences - plugin preferences from the config.xml file. Basically, content from <universal-links> tag.
* @param {Object} pluginPreferences - plugin preferences from the config.xml file. Basically, content from <branch-config> tag.
*/
function activateUniversalLinksInAndroid(cordovaContext, pluginPreferences) {
// inject preferenes into AndroidManifest.xml
androidManifestWriter.writePreferences(cordovaContext, pluginPreferences);

// generate html file with the <link> tags that you should inject on the website.
// androidWebHook.generate(cordovaContext, pluginPreferences);
}

/**
* Activate Universal Links for iOS application.
*
* @param {Object} cordovaContext - cordova context object
* @param {Object} pluginPreferences - plugin preferences from the config.xml file. Basically, content from <universal-links> tag.
* @param {Object} pluginPreferences - plugin preferences from the config.xml file. Basically, content from <branch-config> tag.
*/
function activateUniversalLinksInIos(cordovaContext, pluginPreferences) {
// modify xcode project preferences
Expand All @@ -81,6 +78,4 @@ function activateUniversalLinksInIos(cordovaContext, pluginPreferences) {
// generate entitlements file
iosProjectEntitlements.generateAssociatedDomainsEntitlements(cordovaContext, pluginPreferences);

// generate apple-site-association-file
// iosAppSiteAssociationFile.generate(cordovaContext, pluginPreferences);
}
37 changes: 13 additions & 24 deletions hooks/lib/android/manifestWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ Class injects plugin preferences into AndroidManifest.xml file.
* @return {Boolean} true - if data tag for Universal Links; otherwise - false
*/
function isDataTagForUniversalLinks(data) {
if (data == null) {
// can have only 1 data tag in the intent-filter
if (data == null || data.length != 1) {
return false;
}

Expand Down Expand Up @@ -184,25 +185,7 @@ Class injects plugin preferences into AndroidManifest.xml file.

// generate intent-filters
pluginPreferences.hosts.forEach(function(host) {
var dataElements = [];
host.paths.forEach(function(path) {
var dataElement = {
'$': {
'android:host': host.name,
'android:scheme': host.scheme,
}
}
if (path.prefix) {
dataElement['$']['android:pathPrefix'] = path.prefix
}
if (path.url) {
dataElement['$']['android:path'] = path.url
}
dataElements.push(dataElement);
});
ulIntentFilters.push(createIntentFilter(host.name, host.scheme, dataElements));


ulIntentFilters.push(createIntentFilter(host.name, host.scheme, pluginPreferences.androidPrefix));
});

// add Universal Links intent-filters to the launch activity
Expand Down Expand Up @@ -270,9 +253,9 @@ Class injects plugin preferences into AndroidManifest.xml file.
* @param {String} pathName - host path
* @return {Object} intent-filter as a JSON object
*/
function createIntentFilter(host, scheme, data) {
function createIntentFilter(host, scheme, pathPrefix) {
var intentFilter = {
'$': {
'$' : {
'android:autoVerify': 'true'
},
'action': [{
Expand All @@ -289,12 +272,18 @@ Class injects plugin preferences into AndroidManifest.xml file.
'android:name': 'android.intent.category.BROWSABLE'
}
}],
'data': data
'data': [{
'$': {
'android:host': host,
'android:scheme': scheme,
'android:pathPrefix': pathPrefix
}
}]
};

return intentFilter;
}

// endregion

})();
})();
165 changes: 0 additions & 165 deletions hooks/lib/android/webSiteHook.js

This file was deleted.

Loading

0 comments on commit 4868ccf

Please sign in to comment.