パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細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.

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト