我正在使用Swift语言将我的Parse应用程序连接到我的Node.js Parse Server。在Parse的文档中,我可以看到这段代码:
[Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id<ParseMutableClientConfiguration> configuration) {
...
configuration.applicationId = @"YOUR_APP_ID";
configuration.clientKey = @"YOUR_APP_CLIENT_KEY";
configuration.server = @"http://localhost:1337/parse";
...
}]];
因为我使用的是Swift语言,所以这是我现在的配置:
// Initialize Parse.
Parse.setApplicationId("APP_ID", clientKey: "CLIENT_KEY")
但是如何在Objective-C代码中指定服务器?
谢谢!
答案 0 :(得分:28)
自己找到答案,这里是如何使用Swift设置配置(包括服务器URL):
let parseConfiguration = ParseClientConfiguration(block: { (ParseMutableClientConfiguration) -> Void in
ParseMutableClientConfiguration.applicationId = "APP_ID"
ParseMutableClientConfiguration.clientKey = "CLIENT_KEY"
ParseMutableClientConfiguration.server = "http://your_server.com:1337/parse"
})
Parse.initializeWithConfiguration(parseConfiguration)
希望它会帮助别人。
答案 1 :(得分:3)
Parse Server现在有一些很好的documentation,它基本上建议使用@ fraxool的解决方案,语法更简洁:
let configuration = ParseClientConfiguration {
$0.applicationId = "YOUR_APP_ID"
$0.clientKey = ""
$0.server = "http://localhost:1337/parse"
}
Parse.initializeWithConfiguration(configuration)
答案 2 :(得分:2)
只是用Swift 3添加答案:
let configuration = ParseClientConfiguration {
$0.applicationId = "YOUR_APP_ID"
$0.clientKey = ""
$0.server = "http://localhost:1337/parse"
}
Parse.initialize(with: configuration)
答案 3 :(得分:0)
//设置应用ID
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let configuration = ParseClientConfiguration {
$0.applicationId = PARSE_APP_KEY
$0.clientKey = PARSE_CLIENT_KEY
$0.server = "https://example.com"
}
}