搜尋套件、儲存庫與 APP 分類

套件詳情v1.4.0

device_region

此外掛程式使用平台特定的 API 回傳 SIM 國家代碼

AndroidiOSWindowsLinux
近 30 天下載
1.8萬
喜歡數
26
Pub 分數
150

安裝套件

flutter pub add device_region

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

device_region 套件使用 Android、iOS、Windows 與 Linux 上的平台特定 API 來取得 SIM 國家代碼。它提供了一種簡單且跨平台的方式,用於判斷與裝置 SIM 卡相關聯的國家,這對於地區化、基於區域的內容傳遞或合規性檢查非常有幫助。該外掛程式抽象了原生實作細節,為各平台提供一致的 Dart 界面。它不需要網路存取,直接從裝置層級資料運作。

適用情境

  • 根據SIM卡確定使用者所在國家
  • 按地區本地化應用內容
  • 強制執行區域特定限制
  • 在表單中自動設定預設國家
  • 支援多區域應用

主要特色

  • 跨平台支援(Android、iOS、Windows、Linux)
  • 使用原生SIM國家代碼API
  • 無需互聯網
  • 簡單、輕量級的 API
  • 返回 ISO 3166-1 alpha-2 國家代碼

適合對象

  • 不需要GPS即可實現區域檢測的應用
  • 需要國家上下文的旅行或支付應用
  • 在地化框架
  • 離線優先的應用程式
  • 針對多平台的開發者

使用建議

  • 依賴於SIM卡的存有;若無SIM卡,可能會回傳null
  • 在沒有SIM卡的裝置(例如平板電腦)上無法使用
  • 國家代碼可能無法反映使用者的目前位置
  • 僅限基於SIM卡的國家識別
  • 某些平台可能需要執行時權限

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

device_region

A Flutter plugin which uses platform-specific API to return a SIM country code. Supports iOS and Android.

Installation

In your Flutter project, in pubspec.yaml file add the dependency:

dependencies:
  device_region: ^1.4.0

Usage example

Import device_region.dart package.

import 'package:device_region/device_region.dart';
Get SIM country code

Call getSIMCountryCode method to receive SIM country code.

await DeviceRegion.getSIMCountryCode();
Android:

Using TelephonyManager class:

Returns simCountryIso if available. Otherwise, it should return networkCountryIso.

In case the value cannot be retrieved or an error occurs, null value will be returned

iOS:
iOS 16.0 and higher

Due to deprecated properties in CTTelephonyNetworkInfo class, plugin uses Locale class and returns Locale.current.region.identifier.

iOS up to 16.0

Using CTTelephonyNetworkInfo class:

Returns isoCountryCode if available.

In case the value cannot be retrieved or an error occurs, null value will be returned

Important notes

  • While call getSIMCountryCode on iOS (up to 16.0), it returns proper country code and can throw error log in debugger as below:
[Client] Updating selectors after delegate addition failed with: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service with pid 91 named com.apple.commcenter.coretelephony.xpc was invalidated from this process." UserInfo={NSDebugDescription=The connection to service with pid 91 named com.apple.commcenter.coretelephony.xpc was invalidated from this process.}

It's well known bug on iOS and it does not affect the operation of the application.

  • Method returns null in case if for some reason it was not possible to retrieve the information from the SIM slot. So it will return null i.e on iOS simulators and devices without SIM card inserted.

  • On iOS, it only works from 12.0 and above. For lower versions it will return null.

所屬分類

原始碼儲存庫

使用此套件的專案