Flutter嵌入式SIM管理工具插件esim_toolkit的使用
Flutter嵌入式SIM管理工具插件esim_toolkit的使用
Flutter eSIM 插件
一个用于检查设备是否支持eSIM并直接在应用程序中安装eSIM配置文件的Flutter插件。
目录
开始使用
要使用此插件,请在 pubspec.yaml
文件中添加 esim_toolkit
作为依赖项:
dependencies:
esim_toolkit: ^latest_version
然后运行以下命令以获取依赖项:
flutter pub get
安装
确保根据您的项目平台进行必要的设置:
- Android: 不需要额外设置。
- iOS: 不需要额外设置。
使用
在Dart文件中导入库:
import 'package:esim_toolkit/esim_toolkit.dart';
现在您可以使用 EsimToolkit
类来检查设备是否支持eSIM并安装eSIM配置文件。
// 检查设备是否支持eSIM
// 不需要请求Apple的权限批准(手动检查)
bool isEsimSupported = await EsimToolkit.isEsimSupported();
// 检查设备是否支持eSIM
// 不需要请求Apple的权限批准(手动检查)
// 您可以添加一些尚未上市的新设备进行检查
List<String> newer = ['iPhone18,4', 'iPhone19,4'];
bool isEsimSupported = await EsimToolkit.isEsimSupported(newer);
// 安装eSIM配置文件
// 需要请求Apple的权限批准
bool installedSuccessfully = await EsimToolkit.installEsimProfile(profileData);
// 获取eSIM设置步骤的文本说明
bool textInstructions = await EsimToolkit.instructions();
iOS 的 eSIM 集成指南
兼容性检查
您可以通过以下步骤将eSIM功能集成到您的iOS应用中。请注意,此过程涉及从Apple请求权限批准。
步骤
第一步:请求eSIM权限
使用您的开发者帐户,通过Apple开发者门户提交eSIM权限请求。
第二步:审批流程
Apple将审核并批准权限请求。您可以在应用的配置设置中查看审批状态。
第三步:下载配置文件
下载开发和分发配置文件。确保在配置文件设置中选择了eSIM权限。
第四步:更新Info.plist
在您的 Info.plist
文件中添加以下键值对:
<key>CarrierDescriptors</key>
<array>
<dict>
<key>GID1</key>
<string>***</string>
<key>GID2</key>
<string>***</string>
<key>MCC</key> <!-- 国家代码 -->
<string>***</string>
<key>MNC</key> <!-- 网络代码 -->
<string>***</string>
</dict>
</array>
注意:可以从以下来源获取GID1、GID2、MCC和MNC信息以实现eSIM兼容性:
- 移动网络运营商:联系您的移动网络运营商以获取特定的eSIM卡详细信息。
- 在线eSIM提供商:许多提供商如Truphone、Twilio和Unlocator在其网站上发布此类信息。
- 设备制造商:一些制造商如Apple和Samsung在其网站或用户手册中提供详细信息。
- eSIM数据库:像esimdb.com这样的网站提供了有关eSIM卡及其关联代码的信息。
重要的是要注意,eSIM兼容性可能因移动网络运营商和设备而异。因此,请始终参考具体的提供商或制造商以获取准确和最新的信息。
有关更多详细信息,请参阅API参考部分。
示例
查看 example 目录下的简单Flutter应用程序,演示了如何使用该插件。
贡献
欢迎为本项目做出贡献!
许可证
该项目基于 MIT 许可证 授权。
示例代码
以下是完整的示例代码,展示如何使用 esim_toolkit
插件:
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:esim_toolkit/esim_toolkit.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
[@override](/user/override)
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _isSupportESim = false;
final esimToolkitPlugin = EsimToolkit();
[@override](/user/override)
void initState() {
super.initState();
initPlatformState();
esimToolkitPlugin.onEvent.listen((event) {
debugPrint(event);
});
}
// 平台消息是异步的,因此我们初始化在一个异步方法中。
Future<void> initPlatformState() async {
bool isSupportESim;
// 平台消息可能会失败,所以我们使用try/catch捕获PlatformException。
// 我们还处理消息可能返回null的情况。
try {
List<String> newer = ["iPhone17,4"];
isSupportESim = await esimToolkitPlugin.isSupportESim(newer);
} on PlatformException {
isSupportESim = false;
}
// 如果小部件在异步平台消息完成之前从树中移除,则我们希望丢弃回复而不是调用setState来更新我们的不存在的外观。
if (!mounted) return;
setState(() {
_isSupportESim = isSupportESim;
});
}
Future<void> installEsim() async {
await esimToolkitPlugin.installEsimProfile("LPA:1\$lpa.airalo.com\$TEST");
}
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
Text('isSupportESim: $_isSupportESim\n'),
ElevatedButton(
onPressed: () {
installEsim();
},
child: const Text('Install eSim'),
)
],
),
),
),
);
}
}
更多关于Flutter嵌入式SIM管理工具插件esim_toolkit的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter嵌入式SIM管理工具插件esim_toolkit的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
esim_toolkit
是一个用于 Flutter 的插件,旨在帮助开发者管理嵌入式 SIM (eSIM) 卡。它提供了一组 API,允许开发者与设备的 eSIM 功能进行交互,例如激活、下载和管理 eSIM 配置文件。
1. 安装插件
首先,你需要在 pubspec.yaml
文件中添加 esim_toolkit
插件的依赖:
dependencies:
flutter:
sdk: flutter
esim_toolkit: ^latest_version
然后运行 flutter pub get
以安装插件。
2. 导入插件
在你的 Dart 文件中导入 esim_toolkit
插件:
import 'package:esim_toolkit/esim_toolkit.dart';
3. 检查设备是否支持 eSIM
在尝试使用 eSIM 功能之前,你应该先检查设备是否支持 eSIM:
bool isESimSupported = await EsimToolkit.isESimSupported();
if (isESimSupported) {
print("Device supports eSIM.");
} else {
print("Device does not support eSIM.");
}
4. 下载 eSIM 配置文件
要下载 eSIM 配置文件,你需要提供一个激活码(通常是 QR 码或字符串):
String activationCode = "your_activation_code_here";
try {
await EsimToolkit.downloadESimProfile(activationCode);
print("eSIM profile downloaded successfully.");
} catch (e) {
print("Failed to download eSIM profile: $e");
}
5. 激活 eSIM 配置文件
下载 eSIM 配置文件后,你可能需要手动激活它:
try {
await EsimToolkit.activateESimProfile();
print("eSIM profile activated successfully.");
} catch (e) {
print("Failed to activate eSIM profile: $e");
}
6. 获取 eSIM 配置文件信息
你可以获取已下载的 eSIM 配置文件的信息:
List<ESimProfile> profiles = await EsimToolkit.getESimProfiles();
for (var profile in profiles) {
print("Profile ID: ${profile.profileId}");
print("Profile Name: ${profile.profileName}");
print("State: ${profile.state}");
}
7. 删除 eSIM 配置文件
如果你不再需要某个 eSIM 配置文件,可以将其删除:
String profileId = "your_profile_id_here";
try {
await EsimToolkit.deleteESimProfile(profileId);
print("eSIM profile deleted successfully.");
} catch (e) {
print("Failed to delete eSIM profile: $e");
}