or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

availability.mdbase-plugin.mddecorators.mdindex.mdpromise-observable.md
tile.json

base-plugin.mddocs/

0

# Base Plugin Class

1

2

The `IonicNativePlugin` class serves as the foundation for all Ionic Native plugin wrappers, providing standardized plugin metadata management and availability checking functionality.

3

4

## Capabilities

5

6

### IonicNativePlugin Class

7

8

Base class that all Ionic Native plugin wrappers must extend to provide consistent plugin metadata and availability checking.

9

10

```typescript { .api }

11

/**

12

* Base class for all Ionic Native plugin wrappers

13

* Provides common functionality for plugin metadata and availability checking

14

*/

15

class IonicNativePlugin {

16

/** Display name of the plugin */

17

static pluginName: string;

18

/** Reference path to the plugin object on the global scope */

19

static pluginRef: string;

20

/** NPM package name for plugin installation */

21

static plugin: string;

22

/** GitHub repository URL */

23

static repo: string;

24

/** Array of supported platforms (e.g., ["Android", "iOS"]) */

25

static platforms: string[];

26

/** Installation command or instructions */

27

static install: string;

28

}

29

```

30

31

### Plugin Availability Checking

32

33

```typescript { .api }

34

/**

35

* Returns whether the plugin is installed and available

36

* @returns True if plugin is available, false otherwise

37

*/

38

static installed(): boolean;

39

```

40

41

**Usage Example:**

42

43

```typescript

44

import { ExamplePlugin } from "@ionic-native/example";

45

46

if (ExamplePlugin.installed()) {

47

// Plugin is available, safe to use

48

ExamplePlugin.someMethod();

49

} else {

50

// Plugin not installed or Cordova not available

51

console.log("Example plugin not available");

52

}

53

```

54

55

### Plugin Object Access

56

57

```typescript { .api }

58

/**

59

* Returns the original plugin object from the global scope

60

* @returns The original plugin object or null if not available

61

*/

62

static getPlugin(): any;

63

```

64

65

**Usage Example:**

66

67

```typescript

68

const nativePlugin = ExamplePlugin.getPlugin();

69

if (nativePlugin) {

70

// Access the native plugin directly

71

nativePlugin.nativeMethod();

72

}

73

```

74

75

### Plugin Metadata Access

76

77

```typescript { .api }

78

/**

79

* Returns the plugin's display name

80

* @returns The plugin display name

81

*/

82

static getPluginName(): string;

83

84

/**

85

* Returns the plugin's reference path

86

* @returns The plugin reference path (e.g., "cordova.plugins.Example")

87

*/

88

static getPluginRef(): string;

89

90

/**

91

* Returns the plugin's NPM package install name

92

* @returns The NPM package name

93

*/

94

static getPluginInstallName(): string;

95

96

/**

97

* Returns the plugin's supported platforms

98

* @returns Array of platform names

99

*/

100

static getSupportedPlatforms(): string[];

101

```

102

103

**Usage Examples:**

104

105

```typescript

106

console.log("Plugin name:", ExamplePlugin.getPluginName());

107

console.log("Plugin reference:", ExamplePlugin.getPluginRef());

108

console.log("Install with:", ExamplePlugin.getPluginInstallName());

109

console.log("Supported platforms:", ExamplePlugin.getSupportedPlatforms());

110

```

111

112

## Implementation Pattern

113

114

When creating a new plugin wrapper, extend `IonicNativePlugin` and define the static metadata:

115

116

```typescript

117

import { IonicNativePlugin, Plugin } from "@ionic-native/core";

118

119

@Plugin({

120

pluginName: "MyPlugin",

121

plugin: "cordova-plugin-myplugin",

122

pluginRef: "cordova.plugins.MyPlugin",

123

repo: "https://github.com/example/cordova-plugin-myplugin",

124

platforms: ["Android", "iOS"],

125

install: "ionic cordova plugin add cordova-plugin-myplugin"

126

})

127

export class MyPlugin extends IonicNativePlugin {

128

// Plugin methods go here

129

}

130

```

131

132

The `@Plugin` decorator will automatically set the static properties on the class based on the configuration provided.