您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

universal_links.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var exec = require('cordova/exec'),
  2. channel = require('cordova/channel'),
  3. // Reference name for the plugin
  4. PLUGIN_NAME = 'UniversalLinks',
  5. // Default event name that is used by the plugin
  6. DEFAULT_EVENT_NAME = 'didLaunchAppFromLink';
  7. // Plugin methods on the native side that can be called from JavaScript
  8. pluginNativeMethod = {
  9. SUBSCRIBE: 'jsSubscribeForEvent',
  10. UNSUBSCRIBE: 'jsUnsubscribeFromEvent'
  11. };
  12. var universalLinks = {
  13. /**
  14. * Subscribe to event.
  15. * If plugin already captured that event - callback will be called immidietly.
  16. *
  17. * @param {String} eventName - name of the event you are subscribing on; if null - default plugin event is used
  18. * @param {Function} callback - callback that is called when event is captured
  19. */
  20. subscribe: function(eventName, callback) {
  21. if (!callback) {
  22. console.warn('Universal Links: can\'t subscribe to event without a callback');
  23. return;
  24. }
  25. if (!eventName) {
  26. eventName = DEFAULT_EVENT_NAME;
  27. }
  28. var innerCallback = function(msg) {
  29. callback(msg.data);
  30. };
  31. exec(innerCallback, null, PLUGIN_NAME, pluginNativeMethod.SUBSCRIBE, [eventName]);
  32. },
  33. /**
  34. * Unsubscribe from the event.
  35. *
  36. * @param {String} eventName - from what event we are unsubscribing
  37. */
  38. unsubscribe: function(eventName) {
  39. if (!eventName) {
  40. eventName = DEFAULT_EVENT_NAME;
  41. }
  42. exec(null, null, PLUGIN_NAME, pluginNativeMethod.UNSUBSCRIBE, [eventName]);
  43. }
  44. };
  45. module.exports = universalLinks;