如何让iOS应用与我的Parse Web服务器通信?

时间:2017-04-21 10:36:44

标签: ios swift xcode parse-platform parse-server

我有一个web服务器,其中一个parse-server-example正在运行,如下所示:

var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/nimbus',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'nimbus',
masterKey: process.env.MASTER_KEY || 'emory',
serverURL: process.env.SERVER_URL || 'http://locahost:5010/parse',
liveQuery: {
classNames: ["Users"]
}

现在,我还通过以下方式配置了我的iOS应用程序(didFinishLaunching):

Parse.setApplicationId("nimbus", clientKey: "X")
let player = PFObject(className: "User")
player.setObject("Richard", forKey: "Name")
player.setObject("O", forKey: "Password")
player.saveInBackground { (succeeded, error) -> Void in
if succeeded {
            print("Object Uploaded")
        } else {
            print("Error: \(error)")
        }
    }

然而,没有任何反应。如何将应用程序和服务器连接在一起?此外,由于Parse已经开源并放弃了托管,我可以使用任何 API密钥,对吗?

1 个答案:

答案 0 :(得分:2)

  

如何将应用程序和服务器连接在一起?

要将您的应用的Parse iOS SDKParse Server相关联, 使用ParseClientConfiguration

初始化您的Parse SDK

例如:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    // Configuration of you parse application
    let configuration = ParseClientConfiguration {
        $0.applicationId = "MY_APP_ID" // Your App Id
        $0.server = "https://example.com/api" // The URL of your server
    }
    Parse.initialize(with: configuration)

    return true
}
  

我可以使用任何API密钥吗?

您不需要客户端密钥即可与Parse Server

连接

我希望我的回答很有帮助