Docs 菜单

故障排除 - Flutter SDK

如果您在 macOS 应用沙盒中使用 Realm Flutter SDK 进行开发,由于内置 macOS 安全设置,网络请求默认不起作用。 使用 Atlas App Services 和 Device Sync 需要网络访问权限。

要启用网络请求,请将以下代码添加文件macos/Runner/DebugProfile.entitlementsmacos/Runner/Release.entitlements中:

<!-- Other entitlements -->
<key>com.apple.security.network.client</key>
<true/>
<!-- Other entitlements -->

在不添加此网络访问权限的情况下,您仍然可以在本地使用 Realm。

有关适用于 macOS 的 Flutter 开发的更多信息,请参阅 使用 Flutter 构建 macOS 应用程序 在 Flutter 文档中。

在可用内存很少的 iOS 或 iPad 设备中,或者使用多个 Realm 或许多通知的内存密集型应用程序中,您可能会遇到以下错误:

libc++abi: terminating due to an uncaught exception of type std::bad_alloc: std::bad_alloc

该错误通常表示由于可用内存不足而无法分配资源。

如果您正在针对 iOS15 + 或 iPad15 + 进行构建,则可以添加 扩展虚拟寻址权利 以解决此问题。

将这些键添加到属性列表中,并将值设置为 true

<key>com.apple.developer.kernel.extended-virtual-addressing</key>
<true/>
<key>com.apple.developer.kernel.increased-memory-limit</key>
<true/>

要将 App Services 与 Realm 软件开发工具包(Realm SDK)在运行 Android 7 或更早版本的设备上结合使用,您必须将具有自定义 Let's Encrypt 传输层安全性 (TLS) 加密证书的 HTTP 客户端添加到App中。

这是由于在运行 Android 7 或更早版本的设备上使用 Flutter 连接到使用 Let's Encrypt TLS 证书的 Web 服务器时出现的一个已知问题。 由于 App Services 服务器使用 Let's Encrypt TLS 证书,因此您必须添加自定义证书。

您可以通过单击以下链接下载 Let's Encrypt 证书以添加到您的应用程序中: https://LetsEncrypt.org/certs/Lets-Encrypt-r3 .pem

要设置自定义 HTTP 客户端,请根据您的应用修改以下代码示例。

import 'package:realm_dart/realm.dart';
import "dart:io";
import "dart:convert";
IOClient createCustomHttpsClient(String cert) {
SecurityContext context = SecurityContext.defaultContext;
try {
final bytes = utf8.encode(cert);
context.setTrustedCertificatesBytes(bytes);
} on TlsException catch (e) {
final message = e.osError?.message ?? "";
if (!message.contains('CERT_ALREADY_IN_HASH_TABLE')) {
rethrow;
}
}
return IOClient(HttpClient(context: context));
}
App createAppWithCustomHttpsClient(
String letsEncryptCertificate, String appId) {
IOClient ioClient = createCustomHttpsClient(letsEncryptCertificate);
final appConfig = AppConfiguration(appId, httpClient: ioClient);
return App(appConfig);
}
final letsEncryptCertificate = "<LET'S ENCRYPT CERTIFICATE>";
final appId = "<YOUR APP ID>";
final app = createAppWithCustomHttpsClient(letsEncryptCertificate, appId);