【问题标题】:How to connect my Swift app to my Parse Server?如何将我的 Swift 应用程序连接到我的 Parse 服务器?
【发布时间】:2016-05-07 10:01:39
【问题描述】:

我正在使用 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 代码中指定服务器呢?

谢谢!

【问题讨论】:

  • 仅供参考 - Parse.com 正在关闭。在完成您的应用之前,您应该找到另一个解决方案。
  • @rmaddy 这正是我尝试迁移到 Parse“自托管”服务器的原因 ;-)
  • 啊。也许需要为此添加一个新标签。
  • @rmaddy 确实如此,我也是这么认为的。顺便说一句,我自己找到了这个问题的答案,现在将发布解决方案。

标签: objective-c swift parse-platform parse-server


【解决方案1】:

自己找到了答案,这里是如何使用 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)

希望对其他人有所帮助。

【讨论】:

    【解决方案2】:

    Parse Server 现在有一些不错的documentation,它基本上推荐@fraxool 的解决方案,语法更简洁:

    let configuration = ParseClientConfiguration {
        $0.applicationId = "YOUR_APP_ID"
        $0.clientKey = ""
        $0.server = "http://localhost:1337/parse"
    }
    Parse.initializeWithConfiguration(configuration)
    

    【讨论】:

      【解决方案3】:

      只是用 Swift 3 添加答案:

         let configuration = ParseClientConfiguration {
              $0.applicationId = "YOUR_APP_ID"
              $0.clientKey = ""
              $0.server = "http://localhost:1337/parse"
          }
          Parse.initialize(with: configuration)
      

      【讨论】:

        【解决方案4】:

        //设置应用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"
                }
                  Parse.initialize(with: configuration)
        
           return true
        }
        

        【讨论】:

        • Parse.initialize(with: configuration) 缺失
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-10
        • 1970-01-01
        相关资源
        最近更新 更多