Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation on removing plugin event listeners #871

Merged
merged 1 commit into from Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions site/docs-md/plugins/android.md
Expand Up @@ -197,14 +197,24 @@ Plugins.MyPlugin.addListener("myPluginEvent", (info: any) => {
});
```

To emit the event from the Swift plugin class you can do it like this:
To emit the event from the Java plugin class you can do it like this:

```java
JSObject ret = new JSObject();
ret.put("value", "some value");
notifyListeners("myPluginEvent", ret);
```

To remove a listener from the plugin object:

```javascript
const myPluginEventListener = Plugins.MyPlugin.addListener("myPluginEvent", (info: any) => {
console.log("myPluginEvent was fired");
});

myPluginEventListener.remove();
```

### Permissions

Some Plugins will require you to request permissions.
Expand Down Expand Up @@ -284,4 +294,4 @@ public class MainActivity extends BridgeActivity {
}});
}
}
```
```
15 changes: 12 additions & 3 deletions site/docs-md/plugins/ios.md
Expand Up @@ -20,7 +20,7 @@ Once your plugin is generated, you can start editing it by opening `Plugin.swift
### Simple Example

In the generated example, there is a simple echo plugin with an `echo` function that simply returns a value that it was given.

This example demonstrates a few core components of Capacitor plugins: receiving data from a Plugin Call, and returning
data back to the caller:

Expand Down Expand Up @@ -66,7 +66,7 @@ For example, here is how you'd get data passed to your method:
}
```

Notice the various ways data can be accessed on the `CAPPluginCall` instance, including how to require
Notice the various ways data can be accessed on the `CAPPluginCall` instance, including how to require
options using `guard`.

### Returning Data Back
Expand Down Expand Up @@ -164,6 +164,16 @@ To emit the event from the Swift plugin class you can do it like this:

`self.notifyListeners("myPluginEvent", data: [:])`

To remove a listener from the plugin object:

```javascript
const myPluginEventListener = Plugins.MyPlugin.addListener("myPluginEvent", (info: any) => {
console.log("myPluginEvent was fired");
});

myPluginEventListener.remove();
```


### Export to Capacitor

Expand All @@ -185,4 +195,3 @@ CAP_PLUGIN(MyPlugin, "MyPlugin",
```

This makes `MyPlugin`, and the `echo` method available to the Capacitor web runtime, indicating to Capacitor that the echo method will return a Promise.