GitBook: [master] 217 pages modified

This commit is contained in:
Daniel Sogl 2021-10-01 21:57:54 +00:00 committed by gitbook-bot
parent 4127bcf6e5
commit 529ec51bda
No known key found for this signature in database
GPG Key ID: 07D2180C7B12D0FF
3 changed files with 233 additions and 0 deletions

View File

@ -214,4 +214,6 @@
* [Android Notch](plugins/android-notch.md)
* [Network Interface](plugins/network-interface.md)
* [Printer](plugins/printer.md)
* [Installation](installation.md)
* [FAQ](faq.md)

87
docs/faq.md Normal file
View File

@ -0,0 +1,87 @@
# FAQ
### [Cordova Management Tips](https://ionicframework.com/docs/native/community#cordova-management-tips) <a id="cordova-management-tips"></a>
**1\) Use the** [**Ionic CLI**](https://ionicframework.com/docs/cli) **to add/update/delete plugins.**
Instead of directly editing `config.xml` and `package.json`. Use `ionic` in front of Cordova commands for a better experience and additional functionality \(`ionic cordova build ios` instead of `cordova build ios`\).
**2\) Upgrade plugins by removing, then re-adding them.**
```text
$ ionic cordova plugin remove cordova-plugin-camera
$ ionic cordova plugin add cordova-plugin-camera
```
**3\) Install explicit versions.**
To ensure that the same version of a plugin is always installed via `npm install`, specify the version number:
```text
$ ionic cordova plugin add cordova-plugin-camera@4.3.2
```
**4\) Restore Cordova in an existing Ionic project**
Useful when adding new developers to a project. `ionic cordova prepare` restores platforms and plugins from `package.json` and `config.xml`. The version to be installed is taken from `package.json` or `config.xml`, if found in those files. In case of conflicts, `package.json` is given precedence over `config.xml`.
**5\) Troubleshoot Cordova issues with Ionic CLI commands**
* `ionic doctor list`: Detects [common issues](https://ionicframework.com/docs/cli/commands/doctor-list) and suggests steps to fix them
* `ionic repair`: Remove, then [regenerate](https://ionicframework.com/docs/cli/commands/repair) all dependencies
### [Understanding Version Numbers](https://ionicframework.com/docs/native/community#understanding-version-numbers) <a id="understanding-version-numbers"></a>
For any given Ionic Native plugin, the Ionic Native \(TypeScript code\) and Cordova \(native code\) version numbers will not match. The Ionic Native version number is found in `package.json`:
```text
"@ionic-native/camera": "^5.3.0",
```
CopyCopied
The Cordova plugin version number is found in both `package.json` and `config.xml`:
```text
"cordova-plugin-camera": "4.0.3",
```
CopyCopied
```text
<plugin name="cordova-plugin-camera" spec="4.0.3" />
```
CopyCopied
When checking for new native functionality or bug fixes, look for new versions on the Cordova plugin GitHub page itself \(here's the [Camera one](https://github.com/apache/cordova-plugin-camera), for example\).
To check for new Ionic Native releases \(may include exposing methods recently added by the Cordova plugin, etc.\), see [here](https://github.com/ionic-team/ionic-native/releases).
### [Troubleshooting Failed Builds](https://ionicframework.com/docs/native/community#troubleshooting-failed-builds) <a id="troubleshooting-failed-builds"></a>
Research the build error\(s\) by checking out these resources:
* Google & [StackOverflow](https://stackoverflow.com/): Many issues are documented online
* Ask the [Ionic Community Ionic Forum](https://forum.ionicframework.com/) \(see the Ionic Native category\)
* See the Ionic Customer Success [Knowledge Base](https://ionic.zendesk.com/)
#### [Cordova Plugin Conflicts](https://ionicframework.com/docs/native/community#cordova-plugin-conflicts) <a id="cordova-plugin-conflicts"></a>
Plugins can conflict with each other when they share the same underlying native dependencies or when more than one plugin tries to access the same native code at once. For example, common libraries like the Google Play Services version \(Google Maps is using GPS v24.2 but Firebase wants GPS v27.1\). Keeping these plugins updated regularly can help with this.
Another tip is to ensure that your app uses only one plugin per specific feature/functionality \(example: Push Notifications\).
### [Recommended Upgrade Strategy](https://ionicframework.com/docs/native/community#recommended-upgrade-strategy) <a id="recommended-upgrade-strategy"></a>
The most Ionic stable apps are routinely updated, especially at the native layer. Keeping native plugins up to date ensures your project has the latest security fixes, new features, and improved performance.
Update your project's plugins one at a time, ideally in separate code branches. This reduces the surface area that issues can arise from - if you update everything in your project at once, it's sometimes hard to tell where the problem stems from.
#### [When should I update?](https://ionicframework.com/docs/native/community#when-should-i-update-) <a id="when-should-i-update-"></a>
* When a new feature/bug is released: Run `npm outdated` to see a list of available updates.
* When new major versions are released: Official blogs, such as the [Cordova blog](https://cordova.apache.org/blog/)and [Ionic blog](https://ionicframework.com/blog/), will publish announcements and news.
* Evaluate the nature of the update: is it a shiny new feature or critical security fix?
* Timing: Where does it fit in against your team's project goals?

144
docs/installation.md Normal file
View File

@ -0,0 +1,144 @@
# Installation
[Apache Cordova](https://cordova.apache.org/) is an open source native runtime that allows developers to build native mobile apps with HTML, CSS, and JavaScript. Similar to [Capacitor](https://capacitorjs.com/), Ionics own native runtime, Cordova allows developers to access native device features, such as camera, keyboard, and geolocation, using a system of plugins. A plugin is a small amount of add-on code that provides JavaScript interface to native components. They allow your app to use native device capabilities beyond what is available to pure web apps.
For developers using Ionic with Cordova, our team has developed a collection of TypeScript wrappers for open source Cordova plugins that make it easy to add native functionality to any Ionic app. See [Ionic Native](https://github.com/ionic-team/ionic-native).
These plugins are submitted and maintained by the Ionic community. While community members are generally quick to find and fix issues, certain plugins may not function properly.
For professional developers and teams that require dedicated native plugin support & SLAs, ongoing maintenance, and security patches, please explore our [premium options](https://ionicframework.com/native), including plugin support and pre-built solutions for common native use cases.
> These docs are for apps built with Ionic Framework 4.0.0 and greater. For older Ionic v3 projects, please [see here](https://ionicframework.com/docs/v3/native).
### [Capacitor Support](https://ionicframework.com/docs/native/community#capacitor-support) <a id="capacitor-support"></a>
In addition to Cordova, Ionic Native also works with [Capacitor](https://capacitor.ionicframework.com/), Ionic's official native runtime. Basic usage below. For complete details, [see the Capacitor documentation](https://capacitor.ionicframework.com/docs/cordova/using-cordova-plugins).
### [Usage](https://ionicframework.com/docs/native/community#usage) <a id="usage"></a>
All plugins have two components - the native code \(Cordova\) and the TypeScript code \(Ionic Native\). Cordova plugins are also wrapped in a `Promise` or `Observable` in order to provide a common plugin interface and modernized development approach.
Using the [Camera plugin](https://ionicframework.com/docs/native/camera) as an example, first install it:CORDOVACAPACITOR
```text
// Install Cordova plugin
$ ionic cordova plugin add cordova-plugin-camera
// Install Ionic Native TypeScript wrapper
$ npm install @ionic-native/camera
// Install Ionic Native core library (once per project)
$ npm install @ionic-native/core
```
Next, begin using the plugin, following the various framework usage options below. For FAQ, see [here](https://ionicframework.com/docs/native/faq).
### [Angular](https://ionicframework.com/docs/native/community#angular) <a id="angular"></a>
Angular apps can use either Cordova or Capacitor to build native mobile apps. Import the plugin in a `@NgModule` and add it to the list of Providers. For Angular, the import path should end with `/ngx`. Angular's change detection is automatically handled.
```text
// app.module.ts
import { Camera } from '@ionic-native/camera/ngx';
...
@NgModule({
...
providers: [
...
Camera
...
]
...
})
export class AppModule { }
```
CopyCopied
After the plugin has been declared, it can be imported and injected like any other service:
```text
// camera.service.ts
import { Injectable } from "@angular/core";
import { Camera, CameraOptions } from "@ionic-native/camera/ngx";
@Injectable({
providedIn: "root",
})
export class PhotoService {
constructor(private camera: Camera) {}
takePicture() {
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
};
this.camera.getPicture(options).then(
(imageData) => {
// Do something with the new photo
},
(err) => {
// Handle error
console.log("Camera issue: " + err);
}
);
}
}
```
CopyCopied
### [React](https://ionicframework.com/docs/native/community#react) <a id="react"></a>
React apps must use Capacitor to build native mobile apps. However, Ionic Native \(and therefore, Cordova plugins\) can still be used.// Install Core library \(once per project\)npm install @ionic-native/core
// Install Ionic Native TypeScript wrappernpm install @ionic-native/barcode-scanner
// Install Cordova pluginnpm install phonegap-plugin-barcodescanner
// Update native platform project\(s\) to include newly added pluginionic cap sync
Import the plugin object then use its static methods:
```text
import { BarcodeScanner } from "@ionic-native/barcode-scanner";
const Tab1: React.FC = () => {
const openScanner = async () => {
const data = await BarcodeScanner.scan();
console.log(`Barcode data: ${data.text}`);
};
return (
<IonPage>
<IonHeader>
<IonToolbar>
<IonTitle>Tab 1</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<IonButton onClick={openScanner}>Scan barcode</IonButton>
</IonContent>
</IonPage>
);
};
```
CopyCopied
### [Vanilla JavaScript](https://ionicframework.com/docs/native/community#vanilla-javascript) <a id="vanilla-javascript"></a>
Vanilla JavaScript apps, targeting ES2015+ and/or TypeScript, can use either Cordova or Capacitor to build native mobile apps. To use any plugin, import the class from the appropriate package and use its static methods:
```text
import { Camera } from "@ionic-native/camera";
document.addEventListener("deviceready", () => {
Camera.getPicture()
.then((data) => console.log("Took a picture!", data))
.catch((e) => console.log("Error occurred while taking a picture", e));
});
```