我正在关注 realm swift getting started guide here它工作正常。我有以下对象:
class Dog: Object {
dynamic var name = ""
dynamic var age = 0
}
在我的 View Controller 中有
override func viewDidLoad() {
super.viewDidLoad()
print(Realm.Configuration.defaultConfiguration.fileURL!)
let myDog = Dog()
myDog.name = "Rex"
myDog.age = 1
let realm = try! Realm()
try! realm.write {
realm.add(myDog)
}
}
小告密者报告说 realm 试图连接到 static.realm.io
和 api.mixpanel.com
。如果我只想在本地使用它,如何阻止 realm 尝试连接到各种服务器?
最佳答案
这是预期的行为。
Realm collects anonymous analytics when your app is run with a debugger attached, or when it runs in a simulator.
有关详细信息,请参阅我们的文档。
https://realm.io/docs/swift/latest/#i-see-a-network-call-to-mixpanel-when-i-run-my-app-what-is-that
它不会发生在发布版本中。为了在调试构建中防止这种情况,请设置名为 REALM_DISABLE_ANALYTICS
的环境变量。
另见 https://github.com/realm/realm-cocoa/blob/master/Realm/RLMAnalytics.mm#L37-L44
关于ios - Realm Swift 仅在本地使用,但它仍会尝试在线连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45784877/