搜索插件、代码仓与 APP 分类

插件详情v4.0.0

carrier_info

运营商信息可从 Android 和 iOS 设备中获取 networkType、networkGeneration、mobileCountryCode、mobileCountryCode 等信息

AndroidiOS
近 30 天下载
4760
喜欢数
82
Pub 分数
150

安装插件

flutter pub add carrier_info

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Carrier Info 是一个 Flutter 插件,可从 Android 和 iOS 设备中检索基本的网络和设备信息,包括网络类型、网络生成、移动国家代码(MCC)和移动网络代码(MNC)。它在各平台上提供一致的载体详情访问,使开发者能够根据网络状况或用户位置构建自适应应用。该包轻量且可通过 pub.dev 无缝集成到 Flutter 项目中。它支持 Android 和 iOS,非常适合跨平台移动开发。

适合场景

  • 检测网络类型以实现自适应应用行为
  • 根据MCC识别用户所在国家
  • 根据网络代际优化数据使用
  • 通过运营商数据增强地理位置功能
  • 构建区域特定的内容分发

主要特点

  • 跨平台支持(Android 和 iOS)
  • 访问网络类型和生成
  • MCC 和 MNC 的检索
  • 简单的 API 集成
  • 轻量且可靠

适合对象

  • 需要网络感知功能的移动应用
  • 基于位置的服务
  • 数据节省功能
  • 按地区进行用户画像
  • 需要运营商元数据的应用

使用建议

  • Android 上需要适当的权限
  • 仅限设备级别的运营商信息
  • 与运营商数据相关的隐私考虑
  • Web 和桌面平台不可用
  • 依赖于底层操作系统运营商API

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

📱 Carrier Info

pub package

⚠️ IMPORTANT iOS 16.0+ NOTICE: Apple has deprecated CTCarrier starting with iOS 16.0. This means that most carrier-specific information (carrier name, country codes, network codes, etc.) will return nil or generic values on iOS 16.0 and later versions. This is an Apple platform limitation, not a plugin issue. See the iOS Limitations section for more details.

Carrier Info gets networkType, networkGeneration, mobileCountryCode, mobileCountryCode, e.t.c from both android and ios devices. It's a port from this js project and an improvement on the existing flt_telephony_info package.

📸 Screen Shots

Fetching android carrier info

Docs: https://developer.android.com/reference/android/telephony/TelephonyManager#getNetworkCountryIso(), https://developer.android.com/reference/android/telephony/SubscriptionManager

 AndroidCarrierData? carrierInfo = await CarrierInfo.getAndroidInfo();
 returns  {
   "isVoiceCapable": true,
   "isDataEnabled": true,
   "subscriptionsInfo": [
     {
       "mobileCountryCode": "310",
       "isOpportunistic": false,
       "mobileNetworkCode": "260",
       "displayName": "T-Mobile",
       "isNetworkRoaming": false,
       "simSlotIndex": 0,
       "phoneNumber": "+15551234567",
       "countryIso": "us",
       "subscriptionType": 0,
       "cardId": 0,
       "isEmbedded": false,
       "carrierId": 1,
       "subscriptionId": 1,
       "simSerialNo": "",
       "dataRoaming": 0
     }
   ],
   "isDataCapable": true,
   "isMultiSimSupported": "MULTISIM_NOT_SUPPORTED_BY_HARDWARE",
   "isSmsCapable": true,
   "telephonyInfo": [
     {
       "networkCountryIso": "us",
       "mobileCountryCode": "310",
       "mobileNetworkCode": "260",
       "displayName": "T-Mobile",
       "simState": "SIM_STATE_READY",
       "isoCountryCode": "us",
       "cellId": {
         "cid": 47108,
         "lac": 8514
       },
       "phoneNumber": "+15551234567",
       "carrierName": "T-Mobile",
       "subscriptionId": 1,
       "networkGeneration": "4G",
       "radioType": "LTE",
       "networkOperatorName": "T-Mobile"
     }
   ]
 };
Fetching iOS carrier info
 IosCarrierData? carrierInfo = await CarrierInfo.getIosInfo();

 // iOS 15.x and earlier - Full carrier information available
 returns  {
   "carrierData": [
     {
       "mobileNetworkCode": "20",
       "carrierAllowsVOIP": true,
       "mobileCountryCode": "621",
       "carrierName": "Airtel",
       "isoCountryCode": "ng"
     }
   ],
   "supportsEmbeddedSIM": false,
   "carrierRadioAccessTechnologyTypeList": ["LTE"],
   "isSIMInserted": true,
   "subscriberInfo": {
     "subscriberCount": 1,
     "subscriberIdentifiers": ["subscriber_id_here"],
     "carrierTokens": ["token_here"]
   },
   "cellularPlanInfo": {
     "supportsEmbeddedSIM": false
   },
   "networkStatus": {
     "hasCellularData": true,
     "activeServices": 1,
     "technologies": ["LTE"]
   },
   "_ios_version_info": {
     "ios_version": {...},
     "ctcarrier_deprecated": false,
     "deprecation_notice": "CTCarrier functionality is available on this iOS version."
   }
 }

 // iOS 16.0+ - Limited carrier information due to CTCarrier deprecation
 returns  {
   "carrierData": [
     {
       "mobileNetworkCode": null,
       "carrierAllowsVOIP": null,
       "mobileCountryCode": null,
       "carrierName": null,
       "isoCountryCode": null,
       "_deprecated_notice": "CTCarrier is deprecated in iOS 16.0+. Carrier information is no longer available."
     }
   ],
   "supportsEmbeddedSIM": false,
   "carrierRadioAccessTechnologyTypeList": ["LTE"],
   "isSIMInserted": true,
   "subscriberInfo": {
     "subscriberCount": 1,
     "subscriberIdentifiers": ["subscriber_id_here"],
     "carrierTokens": ["token_here"]
   },
   "cellularPlanInfo": {
     "supportsEmbeddedSIM": true
   },
   "networkStatus": {
     "hasCellularData": true,
     "activeServices": 1,
     "technologies": ["LTE"]
   },
   "_ios_version_info": {
     "ios_version": {...},
     "ctcarrier_deprecated": true,
     "deprecation_notice": "CTCarrier and CTSubscriber are deprecated in iOS 16.0+. Most carrier-specific information is no longer available for privacy and security reasons."
   }
 }

iOS Features

Available on All iOS Versions
SIM Detection
  • isSIMInserted: Boolean indicating if a SIM card is inserted and active
  • networkStatus: Real-time network connectivity information
  • carrierRadioAccessTechnologyTypeList: Current radio technology (2G, 3G, 4G, 5G)
Network Status
"networkStatus": {
  "hasCellularData": true,        // Cellular data available
  "activeServices": 1,            // Number of active cellular services
  "technologies": ["LTE"]         // Current radio access technologies
}
Subscriber Information (iOS 16.0+)
"subscriberInfo": {
  "subscriberCount": 1,                           // Number of subscribers (dual SIM)
  "subscriberIdentifiers": ["subscriber_id"],     // Subscriber identifiers
  "carrierTokens": ["token"]                      // Carrier authentication tokens
}
Cellular Plan Information
"cellularPlanInfo": {
  "supportsEmbeddedSIM": true     // eSIM support detection
}
iOS Version Detection

Use the _ios_version_info field to detect capabilities:

final iosInfo = await CarrierInfo.getIosInfo();
final versionInfo = iosInfo?.toMap()['_ios_version_info'] as Map<String, dynamic>?;
final isDeprecated = versionInfo?['ctcarrier_deprecated'] as bool? ?? false;

if (isDeprecated) {
  // Handle iOS 16.0+ limitations
  print('SIM Inserted: ${iosInfo?.isSIMInserted}');
  print('Network Status: ${iosInfo?.networkStatus?.hasCellularData}');
  print('Radio Tech: ${iosInfo?.carrierRadioAccessTechnologyTypeList}');
} else {
  // Full carrier information available
  print('Carrier: ${iosInfo?.carrierData?.first.carrierName}');
  print('MCC: ${iosInfo?.carrierData?.first.mobileCountryCode}');
}

iOS Limitations

CTCarrier Deprecation (iOS 16.0+)

Starting with iOS 16.0, Apple has deprecated the CTCarrier class and related APIs for privacy and security reasons. This affects the following information:

❌ No longer available on iOS 16.0+:

  • Carrier name (carrierName)
  • Mobile country code (mobileCountryCode)
  • Mobile network code (mobileNetworkCode)
  • ISO country code (isoCountryCode)
  • VOIP allowance (carrierAllowsVOIP)

✅ Still available on iOS 16.0+:

  • SIM insertion detection (isSIMInserted)
  • Radio access technology types (carrierRadioAccessTechnologyTypeList)
  • Network status (networkStatus)
  • Subscriber information (subscriberInfo)
  • Cellular plan information (cellularPlanInfo)
Recommendations
  1. Check iOS version: Use the _ios_version_info field to determine if you're running on iOS 16.0+ and handle the limitations accordingly.

  2. Use available features: Focus on features that work across all iOS versions:

    // These work on all iOS versions
    final simInserted = iosInfo?.isSIMInserted ?? false;
    final hasData = iosInfo?.networkStatus?.hasCellularData ?? false;
    final radioTech = iosInfo?.carrierRadioAccessTechnologyTypeList ?? [];
    
  3. Graceful degradation: Design your app to work without carrier-specific information on newer iOS versions.

  4. Alternative approaches: Consider using network-based detection or user input for carrier information when needed.

  5. Android alternative: For apps that require detailed carrier information, consider using the Android implementation which still provides full functionality.

New iOS Models

The plugin now includes enhanced models for iOS data:

  • IosCarrierData: Main container with all carrier information
  • CarrierData: Individual carrier information (nullable fields for iOS 16.0+)
  • SubscriberInfo: Subscriber and carrier token information
  • CellularPlanInfo: Cellular plan provisioning information
  • NetworkStatus: Real-time network connectivity status
Technical References
Permissions

You should add permissions that are required to your android manifest:

  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.READ_BASIC_PHONE_STATE" />
  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  <uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />

✨ Contribution

Lots of PR's would be needed to make this plugin standard, as for iOS there's a permanent limitation for getting the exact data usage, there's only one way around it and it's super complex.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目