承接 nativephp/mobile-network 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nativephp/mobile-network

Composer 安装命令:

composer require nativephp/mobile-network

包简介

Network connectivity status plugin for NativePHP Mobile

README 文档

README

Network connectivity status monitoring for NativePHP Mobile applications.

Overview

The Network API provides cross-platform network connectivity status detection, including connection type and metered status.

Installation

composer require nativephp/mobile-network

Usage

PHP (Livewire/Blade)

use Native\Mobile\Facades\Network;

// Get current network status
$status = Network::status();

if ($status->connected) {
    echo "Connected via: " . $status->type;

    if ($status->isExpensive) {
        echo " (metered connection)";
    }
} else {
    echo "No network connection";
}

JavaScript (Vue/React/Inertia)

import { Network } from '#nativephp';

// Get current network status
const status = await Network.status();

if (status.connected) {
    console.log(`Connected via: ${status.type}`);

    if (status.isExpensive) {
        console.log('Warning: metered connection');
    }
} else {
    console.log('No network connection');
}

Response Object

The status() method returns an object with the following properties:

Property Type Description
connected boolean Whether device has network connectivity
type string Connection type: wifi, cellular, ethernet, or unknown
isExpensive boolean Whether connection is metered (e.g., cellular data)
isConstrained boolean Whether Low Data Mode is enabled (iOS only)

Examples

Conditional Data Sync

use Native\Mobile\Facades\Network;

public function syncData()
{
    $status = Network::status();

    if (!$status->connected) {
        // Handle no connection
        return;
    }

    if ($status->isExpensive) {
        // On cellular - sync only essential data
        $this->syncEssentialData();
    } else {
        // On WiFi - full sync
        $this->syncAllData();
    }
}

JavaScript Connection Check

import { Network } from '#nativephp';

async function checkBeforeDownload() {
    const status = await Network.status();

    if (!status.connected) {
        console.log('No internet connection');
        return false;
    }

    if (status.isExpensive && status.type === 'cellular') {
        console.log('On cellular data - consider warning user');
        return false;
    }

    return true;
}

Platform Behavior

Android

  • Uses ConnectivityManager and NetworkCapabilities
  • isConstrained is always false (not applicable)
  • Requires ACCESS_NETWORK_STATE permission (added automatically)

iOS

  • Uses NWPathMonitor from Network framework
  • isConstrained reflects Low Data Mode setting
  • No special permissions required

统计信息

  • 总下载量: 6.26k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 0
  • Forks: 3
  • 开发语言: Kotlin

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固