From 469929d9313cd0e39f3cb7249960e0b5620766bc Mon Sep 17 00:00:00 2001 From: Nandesora Tjihero Date: Sun, 19 Jun 2022 12:03:06 +0200 Subject: [PATCH] Removed broken/inconsistent links (API reference sections ) from http.md and connectivity.md and instead made them complete,no need to point other pages --- .vitepress/config.js | 30 ++++----- nativescript-core/Application.md | 104 ++++++++++++++++++++++++++++++ nativescript-core/connectivity.md | 7 -- nativescript-core/http.md | 6 -- 4 files changed, 116 insertions(+), 31 deletions(-) create mode 100644 nativescript-core/Application.md diff --git a/.vitepress/config.js b/.vitepress/config.js index deedbb5d..12530b5a 100644 --- a/.vitepress/config.js +++ b/.vitepress/config.js @@ -534,27 +534,21 @@ function getSidebar() { { text: '@nativescript/core', children: [ + { text: 'Application', link: '/nativescript-core/application' }, + //{text: 'ApplicationSettings',link: '/nativescript-core/application-settings'}, { text: 'Color', link: '/nativescript-core/color' }, { text: 'Connectivity', link: '/nativescript-core/connectivity' }, - { text: 'Application', link: '/nativescript-core/application' }, - { - text: 'ApplicationSettings', - link: '/nativescript-core/application-settings', - }, - { text: 'Observable', link: '/nativescript-core/observable' }, - { - text: 'Observable Array', - link: '/nativescript-core/observable-array', - }, - { text: 'Virtual Array', link: '/nativescript-core/virtual-array' }, - { text: 'File System', link: '/nativescript-core/file-system' }, - { text: 'Fps Meter', link: '/nativescript-core/fps-meter' }, + //{ text: 'Observable', link: '/nativescript-core/observable' }, + //{text: 'Observable Array',link: '/nativescript-core/observable-array'}, + //{ text: 'Virtual Array', link: '/nativescript-core/virtual-array' }, + //{ text: 'File System', link: '/nativescript-core/file-system' }, + //{ text: 'Fps Meter', link: '/nativescript-core/fps-meter' }, { text: 'Http', link: '/nativescript-core/http' }, - { text: 'Image Source', link: '/nativescript-core/image-source' }, - { text: 'Platform', link: '/nativescript-core/platform' }, - { text: 'Timer', link: '/nativescript-core/timer' }, - { text: 'Trace', link: '/nativescript-core/trace' }, - { text: 'Xml Parser', link: '/nativescript-core/xml-parser' }, + //{ text: 'Image Source', link: '/nativescript-core/image-source' }, + //{ text: 'Platform', link: '/nativescript-core/platform' }, + //{ text: 'Timer', link: '/nativescript-core/timer' }, + //{ text: 'Trace', link: '/nativescript-core/trace' }, + //{ text: 'Xml Parser', link: '/nativescript-core/xml-parser' }, ], }, // { diff --git a/nativescript-core/Application.md b/nativescript-core/Application.md new file mode 100644 index 00000000..14d3aa84 --- /dev/null +++ b/nativescript-core/Application.md @@ -0,0 +1,104 @@ +--- +title: Application +--- + +## Application + +The Application module provides abstraction over the platform-specific Application implementations. The module lets you manage the lifecycle of your NativeScript applications from starting the application to handling application events and creating platform-specific logic, such as, sending Broadcasts on Android or adding a Notification observer on IOS. + +#### Usage + +/// flavor javascript + +```javascript +const applicationModule = require('@nativescript/core/application') +``` + +/// + +/// flavor typescript + +```typescript +import { Application } from '@nativescript/core' +``` + +/// + +## Android + +The application module provides a number of Android specific properties to access the Android app, context and activities. + +/// flavor javascript + +```javascript +const androidApp = applicationModule.android +const isPaused = androidApp.paused // e.g. false +const packageName = androidApp.packageName // The package ID e.g. org.nativescript.nativescriptsdkexamplesng +const nativeApp = androidApp.nativeApp // The native APplication reference +const foregroundActivity = androidApp.foregroundActivity // The current Activity reference +const context = androidApp.context // The current Android context +``` + +/// + +/// flavor typescript + +```typescript + +``` + +/// + +#### Registering a Broadcast Receiver + +/// flavor javascript + +```javascript +if (applicationModule.isAndroid) { + // use tns-platform-declarations to acces native APIs (e.g. android.content.Intent) + const receiverCallback = (androidContext, intent) => { + const level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1) + const scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1) + const percent = (level / scale) * 100.0 + vm.set('batteryLife', percent.toString()) + } + + applicationModule.android.registerBroadcastReceiver( + android.content.Intent.ACTION_BATTERY_CHANGED, + receiverCallback + ) +} +``` + +/// + +/// flavor typescript + +```typescript + +``` + +/// + +#### Methods + +| Name | Type | Description | +| ---------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `getConnectionType` | `number` | Gets the type of connection. Returns a value from the `connectivityModule.connectionType` enumeration. To use this method on Android you need to have the **android.permission.ACCESS_NETWORK_STATE** permission added to the **AndroidManifest.xml** file. | +| `startMonitoring(connectionTypeChangedCallback: function)` | `void` | Starts monitoring the connection type. | +| `stopMonitoring` | `void` | Stops monitoring the connection type. | + +#### Connection Types + +- `none = 0`, +- `wifi = 1`, +- `mobile = 2`, +- `ethernet = 3`, +- `bluetooth = 4`, +- `vpn = 5` + +#### Native Component + +| Android | iOS | +| :---------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------- | +| [CONNECTIVITY_SERVICE (android.content.Context)](https://developer.android.com/reference/android/content/Context) | [SCNetworkReachability](https://developer.apple.com/documentation/systemconfiguration/scnetworkreachability-g7d) | diff --git a/nativescript-core/connectivity.md b/nativescript-core/connectivity.md index 174145c8..ac54ce4c 100644 --- a/nativescript-core/connectivity.md +++ b/nativescript-core/connectivity.md @@ -88,13 +88,6 @@ export function onNavigatedTo(args) { - `bluetooth = 4`, - `vpn = 5` -#### API References - -| Name | Type | -| --------------------------------------------------------------------------- | -------- | -| [@nativescript/core/connectivity](/api-reference/modules.html#connectivity) | `Module` | -| [connectionType](/api-reference/modules.html#connectivity) | `Enum` | - #### Native Component | Android | iOS | diff --git a/nativescript-core/http.md b/nativescript-core/http.md index 4739948c..0248ef51 100644 --- a/nativescript-core/http.md +++ b/nativescript-core/http.md @@ -172,9 +172,3 @@ Http.request({ | `getJSON(url: string): Promise` | `Promise` | Downloads the content from the specified URL as a string and returns its JSON.parse representation. | | `getString(url: string): Promise` | `Promise` | Downloads the content from the specified URL as a string. | | `request(options: HttpRequestOptions): Promise` | `Promise` | Makes a generic http request using the provided options and returns a HttpResponse Object. | - -#### API References - -| Name | Type | -| ---------------------------------------------------------------------------------------- | -------- | -| [@nativescript/core/http](https://docs.nativescript.org/api-reference/modules.html#http) | `Module` |